Skip to content

Commit

Permalink
it somewhat works now??
Browse files Browse the repository at this point in the history
  • Loading branch information
konekowo committed Sep 30, 2024
1 parent e96f9e3 commit 5808024
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/Elements/RandomBackground/RandomBackground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class RandomBackground extends Screen {
}
}
}
bgContainer.addChild(new StoryBoard(audio.beatmap))
bgContainer.addChild(new StoryBoard(audio.beatmap, audio))
if (background || backgroundVideo) {
this.setBGContainer(bgContainer);
}
Expand Down
50 changes: 30 additions & 20 deletions src/Elements/RandomBackground/StoryBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,25 @@ import {ColorCommand} from "../../Util/Beatmap/Data/Sections/Events/Storyboard/C
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";
import {Audio} from "../../Audio/Audio";
import {MathUtil} from "../../Util/MathUtil";
import {EventStoryboard} from "../../Util/Beatmap/Data/Sections/Events/Storyboard/EventStoryboard";

export class StoryBoard extends BackgroundContainer {
private beatmap: BeatmapData;
private startTime = Date.now();
private audio: Audio;

public constructor(beatmap: BeatmapData) {
public constructor(beatmap: BeatmapData, audio: Audio) {
super();
this.interactiveChildren = false;
this.interactive = false;
this.beatmap = beatmap;
this.audio = audio;
Main.app.ticker.add(this.Update, this);
for (let i = 0; i < beatmap.Events.Events.length; i++) {
let event = beatmap.Events.Events[i];
Expand All @@ -46,14 +51,15 @@ export class StoryBoard extends BackgroundContainer {
sprite.zIndex = 1;
break;
case Layer.Pass:
sprite.zIndex = 1;
sprite.zIndex = 2;
break;
case Layer.Foreground:
sprite.zIndex = 2;
sprite.zIndex = 3;
break;
}
sprite.anchor = StoryBoardUtil.ConvertOriginToAnchor(event.origin);
sprite.position.set(event.x,event.y);
sprite.position = StoryBoardUtil.ConvertOsuPixels(new PIXI.Point(event.x,event.y), beatmap.General.WidescreenStoryboard);
sprite.label = event.filepath;
event.sprite = sprite;
this.addChild(sprite);
}
Expand All @@ -62,27 +68,30 @@ export class StoryBoard extends BackgroundContainer {


public Update() {
let currentTime = Date.now() - this.startTime;
let currentTime = this.audio.GetCurrentTime();
for (let i = 0; i < this.beatmap.Events.Events.length; i++) {
let event = this.beatmap.Events.Events[i];
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;
} else {
event.parentStoryboardObject.sprite.visible = false;
if (event instanceof EventSprite && event.sprite) {
if (currentTime >= event.StartTime && currentTime <= event.EndTime) {
event.sprite.visible = true;
if (event.filepath.startsWith("sb/q.png")){
console.log(event);
}
for (let j = 0; j < event.Commands.length; j++) {
let command = event.Commands[j];
if (currentTime >= command.startTime) {
this.applyCommand(currentTime, event.sprite, command, event);
}
}
} else if (currentTime > event.EndTime) {
event.sprite.destroy();
}
}
}
}

private applyCommand(time: number, pixiObject: PIXI.Container, command: StoryboardCommand) {
let animProgress = (command.endTime - time)/(command.endTime - command.startTime);
private applyCommand(time: number, pixiObject: PIXI.Container, command: StoryboardCommand, event: EventStoryboard) {
let animProgress = MathUtil.clamp01((command.endTime - time)/(command.endTime - command.startTime));
switch (command.commandType) {
case CommandType.Fade:
let fadeCommand = command as FadeCommand;
Expand Down Expand Up @@ -113,7 +122,7 @@ export class StoryBoard extends BackgroundContainer {
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),
0, ((moveYCommand.endY - moveYCommand.startY) * command.easing(animProgress)) + moveYCommand.startY),
this.beatmap.General.WidescreenStoryboard).y;
break;
case CommandType.Rotate:
Expand All @@ -125,7 +134,7 @@ export class StoryBoard extends BackgroundContainer {
let r = ((colorCommand.endColor.red - colorCommand.startColor.red) * command.easing(animProgress)) + colorCommand.startColor.red;
let g = ((colorCommand.endColor.green - colorCommand.startColor.green) * command.easing(animProgress)) + colorCommand.startColor.green;
let b = ((colorCommand.endColor.blue - colorCommand.startColor.blue) * command.easing(animProgress)) + colorCommand.startColor.blue;
pixiObject.tint = new Float32Array([r, g, b]);
pixiObject.tint = [r, g, b];
break;
case CommandType.Parameter:
let parameterCommand = command as ParameterCommand;
Expand All @@ -138,7 +147,7 @@ export class StoryBoard extends BackgroundContainer {
loopCommand.childCommands.forEach((command) => {
let relativeTime = (time - ((command.endTime - command.startTime)*command.timesLooped)) - loopCommand.startTime;
if (relativeTime > command.startTime && relativeTime <= command.endTime && command.timesLooped <= loopCommand.loopCount) {
this.applyCommand(relativeTime, pixiObject, command);
this.applyCommand(relativeTime, pixiObject, command, event);
} else if (relativeTime > command.endTime) {
command.timesLooped++;
}
Expand All @@ -147,6 +156,7 @@ export class StoryBoard extends BackgroundContainer {
case CommandType.Trigger:
break; //skip for now
}
command.executedOnce = true;
}

public destroy(options?: DestroyOptions) {
Expand Down
2 changes: 2 additions & 0 deletions src/Screens/MainMenu/MainMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export class MainMenu extends Screen {
this.osuCircle.scale = Screen.getScaleBasedOffScreenSize();
this.addChild(this.menu);
this.menu.onResize();
this.osuCircle.visible = false;
this.menu.visible = false;
this.addChild(this.osuCircle);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import {CommandType} from "./CommandType";
import {EasingFunction} from "../../../../../../TweenWrapper/EasingFunction";
import {EventStoryboard} from "../EventStoryboard";
import {Event} from "../../Event";

export abstract class StoryboardCommand extends Event{
public abstract commandType: CommandType;

public parentStoryboardObject!: EventStoryboard;

/**
* indicates if the command should "accelerate". See <a href="http://easings.net/">Easing Functions Cheat Sheet</a>.
*/
Expand All @@ -16,4 +13,6 @@ export abstract class StoryboardCommand extends Event{
public endTime: number = 0;

public timesLooped: number = 0;

public executedOnce: boolean = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import * as PIXI from "pixi.js";

export class EventSprite extends EventStoryboard {
public eventType = EventTypes.SPRITE;
public sprite!: PIXI.Sprite;
public sprite?: PIXI.Sprite;
public texture?: PIXI.Texture;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,39 @@ import {Event} from "../Event";
import {Layer} from "./Layer";
import {Origin} from "./Origin";
import * as PIXI from "pixi.js";
import {LoopCommand} from "./Commands/impl/LoopCommand";

export abstract class EventStoryboard extends Event {
public startTime = -1;
private _startTime?: number;
private _endTime?: number;

public get StartTime() {
if (!this._startTime) {
this._startTime = this.Commands.sort((a, b) => a.startTime - b.startTime)[0].startTime;
}
return this._startTime
}

public get EndTime() {
if (!this._endTime) {
let endTime = this.Commands.sort((a, b) => a.endTime - b.endTime)[this.Commands.length - 1].endTime;
for (let i = 0; i < this.Commands.length; i++) {
let command = this.Commands[i];
if (command instanceof LoopCommand) {
let latestEndTime = command.childCommands.
sort((a, b) => a.endTime - b.endTime)[command.childCommands.length - 1].endTime;
latestEndTime *= command.loopCount;
latestEndTime += command.startTime;
if (latestEndTime > endTime) {
endTime = latestEndTime;
}
}
}
this._endTime = endTime;
}
return this._endTime;
}

/**
* Each <a href="https://osu.ppy.sh/wiki/en/Storyboard/Scripting/Objects">object declaration</a>
* is followed by one or more commands. These tell the object to do something, called an event,
Expand Down
16 changes: 3 additions & 13 deletions src/Util/Beatmap/Parser/EventsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ export class EventsParser {
case CommandType.Loop:
if (depth == 2) break;
event = new LoopCommand();
event.parentStoryboardObject = object;
event.startTime = parseFloat(values[1]);
event.loopCount = Math.max(0, parseInt(values[2]) - 1);
parentCommand = event;
Expand All @@ -188,7 +187,6 @@ export class EventsParser {
command.easing = easing;
command.startOpacity = MathUtil.clamp01(parseFloat(values[4]));
command.endOpacity = values.length > 5 ? MathUtil.clamp01(parseFloat(values[5])) : command.startOpacity;
command.parentStoryboardObject = object;
break;
case CommandType.Scale:
command = new ScaleCommand();
Expand All @@ -197,7 +195,6 @@ export class EventsParser {
command.easing = easing;
command.startScale = parseFloat(values[4]);
command.endScale = values.length > 5 ? parseFloat(values[5]) : command.startScale;
command.parentStoryboardObject = object;
break;
case CommandType.VectorScale:
command = new VectorScaleCommand();
Expand All @@ -208,7 +205,6 @@ export class EventsParser {
let endX = values.length > 6 ? parseFloat(values[6]) : command.startScale.x;
let endY = values.length > 7 ? parseFloat(values[7]) : command.startScale.y;
command.endScale = new PIXI.Point(endX, endY);
command.parentStoryboardObject = object;
break;
case CommandType.Rotate:
command = new RotateCommand();
Expand All @@ -217,7 +213,6 @@ export class EventsParser {
command.easing = easing;
command.startRotation = parseFloat(values[4]);
command.endRotation = values.length > 5 ? parseFloat(values[5]) : command.startRotation;
command.parentStoryboardObject = object;
break;
case CommandType.Move:
command = new MoveCommand();
Expand All @@ -228,7 +223,6 @@ export class EventsParser {
let endX_ = values.length > 6 ? parseFloat(values[6]) : command.startPos.x;
let endY_ = values.length > 7 ? parseFloat(values[7]) : command.startPos.y;
command.endPos = new PIXI.Point(endX_, endY_);
command.parentStoryboardObject = object;
break;
case CommandType.MoveX:
command = new MoveXCommand();
Expand All @@ -237,7 +231,6 @@ export class EventsParser {
command.easing = easing;
command.startX = parseFloat(values[4]);
command.endX = values.length > 5 ? parseFloat(values[5]) : command.startX;
command.parentStoryboardObject = object;
break;
case CommandType.MoveY:
command = new MoveYCommand();
Expand All @@ -246,7 +239,6 @@ export class EventsParser {
command.easing = easing;
command.startY = parseFloat(values[4]);
command.endY = values.length > 5 ? parseFloat(values[5]) : command.startY;
command.parentStoryboardObject = object;
break;
case CommandType.Color:
command = new ColorCommand();
Expand Down Expand Up @@ -274,17 +266,15 @@ export class EventsParser {
endR = MathUtil.clamp01(endR);
endG = MathUtil.clamp01(endG);
endB = MathUtil.clamp01(endB);
command.startColor = new PIXI.Color(new Float32Array([startR, startG, startB]));
command.endColor = new PIXI.Color(new Float32Array([endR, endG, endB]));
command.parentStoryboardObject = object;
command.startColor = new PIXI.Color([startR, startG, startB]);
command.endColor = new PIXI.Color([endR, endG, endB]);
break;
case CommandType.Parameter:
command = new ParameterCommand();
command.startTime = startTime;
command.endTime = endTime;
command.easing = easing;
command.parameter = values[4] as ParameterCommandType;
command.parentStoryboardObject = object;
break;
}
if (command) {
Expand All @@ -296,7 +286,7 @@ export class EventsParser {
}
}
} else {
event = command;
object.Commands.push(command);
}
}
break;
Expand Down

0 comments on commit 5808024

Please sign in to comment.