Skip to content

Commit c2bab32

Browse files
committed
Make title changeable
1 parent 631a827 commit c2bab32

File tree

3 files changed

+12
-27
lines changed

3 files changed

+12
-27
lines changed

.yarn/install-state.gz

1 Byte
Binary file not shown.

src/components/Game.tsx

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ import { useCallback, useEffect, useRef, useState } from "react";
22
import Phaser from "phaser";
33
import { gameConfig } from "../game/config";
44
import { ConnectDevice } from "./ConnectDevice";
5-
import { GameScene } from "../game/scenes/GameScene";
6-
import { MenuScene } from "../game/scenes/MenuScene";
7-
import { GameOverScene } from "../game/scenes/GameOverScene";
8-
import { NameEntryScene } from "../game/scenes/NameEntryScene";
9-
import { HighScoresScene } from "../game/scenes/HighScoresScene";
10-
import { ScenarioScene } from "../game/scenes/ScenarioScene";
115

126
const Game = () => {
137
const [device, setDevice] = useState<HIDDevice | null>(null);
@@ -25,19 +19,16 @@ const Game = () => {
2519
...gameConfig,
2620
};
2721

22+
const params = new URLSearchParams(window.location.search);
23+
const titleString = params.get("title") || "Switchy plushie when? ;)";
24+
2825
// Small delay to ensure DOM has fully rendered
2926
const initTimer = setTimeout(() => {
3027
gameRef.current = new Phaser.Game({
3128
...config,
32-
scene: [
33-
MenuScene,
34-
GameScene,
35-
GameOverScene,
36-
NameEntryScene,
37-
HighScoresScene,
38-
ScenarioScene,
39-
],
4029
});
30+
31+
gameRef.current.scene.start("MenuScene", { titleString });
4132
}, 50);
4233

4334
// Handle orientation change and resize events
@@ -89,18 +80,6 @@ const Game = () => {
8980
}
9081
}, []);
9182

92-
useEffect(() => {
93-
if (device) {
94-
(
95-
gameRef.current?.scene.getScene("ScenarioScene") as GameScene
96-
)?.setDevice(device);
97-
} else {
98-
(
99-
gameRef.current?.scene.getScene("ScenarioScene") as GameScene
100-
)?.closeDevice();
101-
}
102-
}, [device, gameRef, gameRef.current]);
103-
10483
const onDeviceConnect = useCallback((device: HIDDevice) => {
10584
setDevice((existing) => {
10685
if (existing) {

src/game/scenes/MenuScene.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import Phaser from "phaser";
22
import { SpriteAssets } from "../createSpriteAssets";
3+
import { gameConfig } from "../config";
34

45
export class MenuScene extends Phaser.Scene {
56
private selectedIndex: number = 0;
67
private options: string[] = ["START GAME", "HI SCORES"];
78
private optionTexts: Phaser.GameObjects.Text[] = [];
9+
private titleString: string = "";
810
private cursor!: Phaser.GameObjects.Triangle;
911

1012
constructor() {
1113
super("MenuScene");
1214
}
1315

16+
init(data: { titleString?: string }) {
17+
this.titleString = data.titleString || "Switchy plushie when? ;)";
18+
}
19+
1420
preload() {
1521
SpriteAssets.loadSimpleSprites(this);
1622
}
@@ -22,7 +28,7 @@ export class MenuScene extends Phaser.Scene {
2228

2329
document.fonts.load('16px "Monogram"').then(() => {
2430
this.add
25-
.text(width / 2, height - 32, "Hello ZFX Shanghai 2025!", {
31+
.text(width / 2, height - 32, this.titleString, {
2632
fontFamily: "Monogram",
2733
fontSize: "16px",
2834
color: "#0f380f",

0 commit comments

Comments
 (0)