Skip to content

Commit

Permalink
try fixing storyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
konekowo committed Sep 30, 2024
1 parent 02ad272 commit e96f9e3
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 169 deletions.
40 changes: 32 additions & 8 deletions src/Elements/RandomBackground/StoryBoard.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import * as PIXI from "pixi.js";
import {DestroyOptions} from "pixi.js";
import {BackgroundContainer} from "./Background";
import {Main} from "../../main";
import {BeatmapData} from "../../Util/Beatmap/Data/BeatmapData";
import {DestroyOptions} from "pixi.js";
import {EventSprite} from "../../Util/Beatmap/Data/Sections/Events/Storyboard/EventSprite";
import {StoryboardCommand} from "../../Util/Beatmap/Data/Sections/Events/Storyboard/Commands/StoryboardCommand";
import * as timers from "node:timers";
import {CommandType} from "../../Util/Beatmap/Data/Sections/Events/Storyboard/Commands/CommandType";
import {FadeCommand} from "../../Util/Beatmap/Data/Sections/Events/Storyboard/Commands/impl/FadeCommand";
import {ScaleCommand} from "../../Util/Beatmap/Data/Sections/Events/Storyboard/Commands/impl/ScaleCommand";
Expand All @@ -15,9 +14,13 @@ import {MoveXCommand} from "../../Util/Beatmap/Data/Sections/Events/Storyboard/C
import {MoveYCommand} from "../../Util/Beatmap/Data/Sections/Events/Storyboard/Commands/impl/MoveYCommand";
import {RotateCommand} from "../../Util/Beatmap/Data/Sections/Events/Storyboard/Commands/impl/RotateCommand";
import {ColorCommand} from "../../Util/Beatmap/Data/Sections/Events/Storyboard/Commands/impl/ColorCommand";
import {ParameterCommand} from "../../Util/Beatmap/Data/Sections/Events/Storyboard/Commands/impl/ParameterCommand";
import {LoopCommand} from "../../Util/Beatmap/Data/Sections/Events/Storyboard/Commands/impl/LoopCommand";
import {StoryBoardUtil} from "../../Util/StoryBoardUtil";
import {Layer} from "../../Util/Beatmap/Data/Sections/Events/Storyboard/Layer";
import {
ParameterCommand,
ParameterCommandType
} from "../../Util/Beatmap/Data/Sections/Events/Storyboard/Commands/impl/ParameterCommand";

export class StoryBoard extends BackgroundContainer {
private beatmap: BeatmapData;
Expand All @@ -35,6 +38,22 @@ export class StoryBoard extends BackgroundContainer {
let sprite = PIXI.Sprite.from(event.texture);
sprite.visible = false;
sprite.cullable = true;
switch (event.layer) {
case Layer.Background:
sprite.zIndex = 0;
break;
case Layer.Fail:
sprite.zIndex = 1;
break;
case Layer.Pass:
sprite.zIndex = 1;
break;
case Layer.Foreground:
sprite.zIndex = 2;
break;
}
sprite.anchor = StoryBoardUtil.ConvertOriginToAnchor(event.origin);
sprite.position.set(event.x,event.y);
event.sprite = sprite;
this.addChild(sprite);
}
Expand All @@ -49,6 +68,7 @@ export class StoryBoard extends BackgroundContainer {
if (event instanceof StoryboardCommand) {
if (currentTime > event.startTime && !(event instanceof LoopCommand) ? (currentTime <= event.endTime) : true) {
if (event.parentStoryboardObject instanceof EventSprite && event.parentStoryboardObject.sprite) {
event.parentStoryboardObject.sprite.blendMode = "normal";
this.applyCommand(currentTime, event.parentStoryboardObject.sprite, event);
if (event.parentStoryboardObject.sprite.alpha > 0) {
event.parentStoryboardObject.sprite.visible = true;
Expand Down Expand Up @@ -82,19 +102,19 @@ export class StoryBoard extends BackgroundContainer {
pixiObject.position = StoryBoardUtil.ConvertOsuPixels(new PIXI.Point(
((moveCommand.endPos.x - moveCommand.startPos.x) * command.easing(animProgress)) + moveCommand.startPos.x,
((moveCommand.endPos.y - moveCommand.startPos.y) * command.easing(animProgress)) + moveCommand.startPos.y),
moveCommand.parentStoryboardObject.origin, this.beatmap.General.WidescreenStoryboard);
this.beatmap.General.WidescreenStoryboard);
break;
case CommandType.MoveX:
let moveXCommand = command as MoveXCommand;
pixiObject.position.x = StoryBoardUtil.ConvertOsuPixels(new PIXI.Point(
((moveXCommand.endX - moveXCommand.startX) * command.easing(animProgress)) + moveXCommand.startX, 0),
moveXCommand.parentStoryboardObject.origin, this.beatmap.General.WidescreenStoryboard).x;
this.beatmap.General.WidescreenStoryboard).x;
break;
case CommandType.MoveY:
let moveYCommand = command as MoveYCommand;
pixiObject.position.y = StoryBoardUtil.ConvertOsuPixels(new PIXI.Point(
((moveYCommand.endY - moveYCommand.startY) * command.easing(animProgress)) + moveYCommand.startY, 0),
moveYCommand.parentStoryboardObject.origin, this.beatmap.General.WidescreenStoryboard).y;
this.beatmap.General.WidescreenStoryboard).y;
break;
case CommandType.Rotate:
let rotateCommand = command as RotateCommand;
Expand All @@ -108,12 +128,16 @@ export class StoryBoard extends BackgroundContainer {
pixiObject.tint = new Float32Array([r, g, b]);
break;
case CommandType.Parameter:
break; //skip for now
let parameterCommand = command as ParameterCommand;
if (parameterCommand.parameter == ParameterCommandType.UseAdditiveBlending) {
pixiObject.blendMode = "add";
}
break;
case CommandType.Loop:
let loopCommand = command as LoopCommand; // not sure if this works
loopCommand.childCommands.forEach((command) => {
let relativeTime = (time - ((command.endTime - command.startTime)*command.timesLooped)) - loopCommand.startTime;
if (relativeTime > command.startTime && relativeTime <= command.endTime) {
if (relativeTime > command.startTime && relativeTime <= command.endTime && command.timesLooped <= loopCommand.loopCount) {
this.applyCommand(relativeTime, pixiObject, command);
} else if (relativeTime > command.endTime) {
command.timesLooped++;
Expand Down
4 changes: 2 additions & 2 deletions src/Screens/Screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export abstract class Screen extends PIXI.Container {

public abstract onResize(): void;

public static getScreenWidth(): number {
protected getScreenWidth(): number {
return window.innerWidth;
}

public static getScreenHeight(): number {
protected getScreenHeight(): number {
return window.innerHeight;
}
}
Loading

0 comments on commit e96f9e3

Please sign in to comment.