Skip to content

Commit

Permalink
convert from osupixels to screen pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
konekowo committed Sep 30, 2024
1 parent 55cca93 commit 02ad272
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/Elements/RandomBackground/StoryBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {RotateCommand} from "../../Util/Beatmap/Data/Sections/Events/Storyboard/
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";

export class StoryBoard extends BackgroundContainer {
private beatmap: BeatmapData;
Expand Down Expand Up @@ -78,16 +79,22 @@ export class StoryBoard extends BackgroundContainer {
break;
case CommandType.Move:
let moveCommand = command as MoveCommand;
pixiObject.position.x = ((moveCommand.endPos.x - moveCommand.startPos.x) * command.easing(animProgress)) + moveCommand.startPos.x;
pixiObject.position.y = ((moveCommand.endPos.y - moveCommand.startPos.y) * command.easing(animProgress)) + moveCommand.startPos.y;
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);
break;
case CommandType.MoveX:
let moveXCommand = command as MoveXCommand;
pixiObject.position.x = ((moveXCommand.endX - moveXCommand.startX) * command.easing(animProgress)) + moveXCommand.startX;
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;
break;
case CommandType.MoveY:
let moveYCommand = command as MoveYCommand;
pixiObject.position.y = ((moveYCommand.endY - moveYCommand.startY) * command.easing(animProgress)) + moveYCommand.startY;
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;
break;
case CommandType.Rotate:
let rotateCommand = command as RotateCommand;
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;

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

protected getScreenHeight(): number {
public static getScreenHeight(): number {
return window.innerHeight;
}
}
49 changes: 49 additions & 0 deletions src/Util/StoryBoardUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as PIXI from "pixi.js";
import {Origin} from "./Beatmap/Data/Sections/Events/Storyboard/Origin";
import {Screen} from "../Screens/Screen";

export class StoryBoardUtil {
public static ConvertOsuPixels(position: PIXI.PointData, origin: Origin, wideScreen: boolean) {
let screenWidth = Screen.getScreenWidth();
let screenHeight = Screen.getScreenHeight();
let osuWidth43 = 640;
let osuWidth = wideScreen ? 854 : osuWidth43;
let osuHeight = 480;
let widthScaleFactor = screenWidth/osuWidth;
let heightScaleFactor = screenHeight/osuHeight;
let absolutePosition = new PIXI.Point(0, 0);
switch (origin) {
case Origin.Custom:
case Origin.TopLeft:
absolutePosition.set(position.x, position.y);
break;
case Origin.TopCenter:
absolutePosition.set((osuWidth/2) + position.x, position.y);
break;
case Origin.TopRight:
absolutePosition.set(osuWidth + position.x, position.y);
break;
case Origin.CenterLeft:
absolutePosition.set(position.x, (osuHeight/2) + position.y);
break;
case Origin.Center:
absolutePosition.set((osuWidth/2) + position.x, (osuHeight/2) + position.y);
break;
case Origin.CenterRight:
absolutePosition.set(osuWidth + position.x, (osuHeight/2) + position.y);
break;
case Origin.BottomLeft:
absolutePosition.set(position.x, osuHeight + position.y);
break;
case Origin.BottomCenter:
absolutePosition.set((osuWidth/2) + position.x, osuHeight + position.y);
break;
case Origin.BottomRight:
absolutePosition.set(osuWidth + position.x, osuHeight + position.y);
break;
}
absolutePosition.x = (absolutePosition.x + (wideScreen? ((osuWidth - osuWidth43)/2) : 0)) * widthScaleFactor;
absolutePosition.y *= heightScaleFactor;
return absolutePosition;
}
}

0 comments on commit 02ad272

Please sign in to comment.