From 295065fcff38b88ad7f9943f89b8d329d0e5a5b8 Mon Sep 17 00:00:00 2001 From: JustATin555 Date: Tue, 4 Feb 2025 17:06:07 +0800 Subject: [PATCH 1/6] Bump phaser v3.55.2 to 3.87.0 --- package.json | 8 +++++--- src/features/game/input/GameInputManager.ts | 6 +++--- yarn.lock | 18 +++++++++++------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 82fadd2c5e..0afa9fd1c2 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "mdast-util-from-markdown": "^2.0.0", "mdast-util-to-hast": "^13.0.0", "normalize.css": "^8.0.1", - "phaser": "^3.55.2", + "phaser": "^3.87.0", "query-string": "^9.0.0", "re-resizable": "^6.9.9", "react": "^18.3.1", @@ -100,6 +100,7 @@ "yareco": "^0.1.5" }, "devDependencies": { + "//": "See: https://github.com/facebook/react/issues/28313#issuecomment-2076798972, https://github.com/t3-oss/create-t3-turbo/issues/984#issuecomment-2076413457", "@babel/core": "^7.24.5", "@babel/plugin-proposal-private-property-in-object": "^7.21.11", "@babel/preset-typescript": "^7.24.1", @@ -138,7 +139,6 @@ "cross-env": "^7.0.3", "eslint": "^9.9.0", "eslint-plugin-react": "^7.35.0", - "//": "See: https://github.com/facebook/react/issues/28313#issuecomment-2076798972, https://github.com/t3-oss/create-t3-turbo/issues/984#issuecomment-2076413457", "eslint-plugin-react-hooks": "5.1.0-canary-cb151849e1-20240424", "eslint-plugin-react-refresh": "^0.4.9", "eslint-plugin-simple-import-sort": "^12.1.1", @@ -146,6 +146,7 @@ "husky": "^9.0.0", "npm-run-all2": "^7.0.0", "os-browserify": "^0.3.0", + "path": "^0.12.7", "path-browserify": "^1.0.1", "prettier": "^3.3.3", "process": "^0.11.10", @@ -177,5 +178,6 @@ "last 1 firefox version", "last 1 safari version" ] - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/src/features/game/input/GameInputManager.ts b/src/features/game/input/GameInputManager.ts index 2ab78d792a..fff21fcfa7 100644 --- a/src/features/game/input/GameInputManager.ts +++ b/src/features/game/input/GameInputManager.ts @@ -32,7 +32,7 @@ class GameInputManager { * @param active if true, mouse input is enabled. Else, mouse input is disabled. */ public enableMouseInput(active: boolean) { - this.scene.input.mouse.enabled = active; + this.scene.input.mouse!.enabled = active; // ! to convince typescript Mouse Manager exists } /** @@ -41,7 +41,7 @@ class GameInputManager { * @param active if true, keyboard input is enabled. Else, keyboard input is disabled. */ public enableKeyboardInput(active: boolean) { - this.scene.input.keyboard.enabled = active; + this.scene.input.keyboard!.enabled = active; // ! to convince typescript Keyboard Plugin exists } /** @@ -57,7 +57,7 @@ class GameInputManager { event: string | symbol, callback: Function ) { - const keyObj = this.scene.input.keyboard.addKey(key); + const keyObj = this.scene.input.keyboard!.addKey(key); // ! to convince typescript Keyboard Plugin exists const keyboardListener = keyObj.addListener(event, callback); this.keyboardListeners.push(keyboardListener); } diff --git a/yarn.lock b/yarn.lock index 7bb26c2ea8..e9c70dd630 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6619,11 +6619,16 @@ event-emitter-es6@^1.1.5: resolved "https://registry.yarnpkg.com/event-emitter-es6/-/event-emitter-es6-1.1.5.tgz#ef95311b2e17aa39be763b031ce4af7ee9cb7849" integrity sha512-/n7qzkJBySdbe1W9/FBDdO7gzDIaewgj+Rj6Ayc2BdvVcaGP+p40DyViOFudCgV47UU8+cUFmcD3tJgjwY65qQ== -eventemitter3@^4.0.0, eventemitter3@^4.0.1, eventemitter3@^4.0.7: +eventemitter3@^4.0.0, eventemitter3@^4.0.1: version "4.0.7" resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f" integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw== +eventemitter3@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-5.0.1.tgz#53f5ffd0a492ac800721bb42c66b841de96423c4" + integrity sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA== + events@^3.2.0: version "3.3.0" resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400" @@ -10406,13 +10411,12 @@ performance-now@^2.1.0: resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" integrity sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow== -phaser@^3.55.2: - version "3.55.2" - resolved "https://registry.yarnpkg.com/phaser/-/phaser-3.55.2.tgz#c1e2e9e70de7085502885e06f46b7eb4bd95e29a" - integrity sha512-amKXsbb2Ht29dGPKvt1edq3yGGYKtq8373GpJYGKPNPnneYY6MtVTOgjHDuZwtmUyK4v86FugkT3hzW/N4tjxQ== +phaser@^3.87.0: + version "3.87.0" + resolved "https://registry.yarnpkg.com/phaser/-/phaser-3.87.0.tgz#209f1673b311a3f76d59f14b785699709a8f9cf5" + integrity sha512-AyI1b3T5fp05gzf6WUmu2FNqaZL+Y7w88yBRLf7YZXF9bncUSHpnDrupnTGoPqy/RKHRLBcay7zWeqQ2wiMWcw== dependencies: - eventemitter3 "^4.0.7" - path "^0.12.7" + eventemitter3 "^5.0.1" picocolors@^0.2.1: version "0.2.1" From 96fa4267765d0fded2555887414e670712a82846 Mon Sep 17 00:00:00 2001 From: JustATin555 Date: Tue, 4 Feb 2025 17:55:19 +0800 Subject: [PATCH 2/6] Add phaser3spectorjs to satisfy phaser problems --- package.json | 1 + yarn.lock | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/package.json b/package.json index 0afa9fd1c2..85d72e8c56 100644 --- a/package.json +++ b/package.json @@ -148,6 +148,7 @@ "os-browserify": "^0.3.0", "path": "^0.12.7", "path-browserify": "^1.0.1", + "phaser3spectorjs": "^0.0.8", "prettier": "^3.3.3", "process": "^0.11.10", "react-error-overlay": "^6.0.11", diff --git a/yarn.lock b/yarn.lock index e9c70dd630..79cd9002b4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10411,6 +10411,11 @@ performance-now@^2.1.0: resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" integrity sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow== +phaser3spectorjs@^0.0.8: + version "0.0.8" + resolved "https://registry.yarnpkg.com/phaser3spectorjs/-/phaser3spectorjs-0.0.8.tgz#a7996eebc9c498b6d9d19ecda35f16ad3918a8a8" + integrity sha512-0dSO7/aMjEUPrp5EcjRvRRsEf+jXDbmzalPeJ6VtTB2Pn1PeaKc+qlL/DmO3l1Dvc5lkzc+Sil1Ta+Hkyi5cbA== + phaser@^3.87.0: version "3.87.0" resolved "https://registry.yarnpkg.com/phaser/-/phaser-3.87.0.tgz#209f1673b311a3f76d59f14b785699709a8f9cf5" From fae817c79409a8b894165bb134d26ed7d732ec3e Mon Sep 17 00:00:00 2001 From: JustATin555 Date: Tue, 4 Feb 2025 20:30:08 +0800 Subject: [PATCH 3/6] Guard against MouseManager or Keyboard not existing --- src/features/game/input/GameInputManager.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/features/game/input/GameInputManager.ts b/src/features/game/input/GameInputManager.ts index fff21fcfa7..e2b420bfaf 100644 --- a/src/features/game/input/GameInputManager.ts +++ b/src/features/game/input/GameInputManager.ts @@ -32,7 +32,7 @@ class GameInputManager { * @param active if true, mouse input is enabled. Else, mouse input is disabled. */ public enableMouseInput(active: boolean) { - this.scene.input.mouse!.enabled = active; // ! to convince typescript Mouse Manager exists + if (this.scene.input.mouse) this.scene.input.mouse.enabled = active; } /** @@ -41,7 +41,7 @@ class GameInputManager { * @param active if true, keyboard input is enabled. Else, keyboard input is disabled. */ public enableKeyboardInput(active: boolean) { - this.scene.input.keyboard!.enabled = active; // ! to convince typescript Keyboard Plugin exists + if (this.scene.input.keyboard) this.scene.input.keyboard!.enabled = active; } /** @@ -57,9 +57,11 @@ class GameInputManager { event: string | symbol, callback: Function ) { - const keyObj = this.scene.input.keyboard!.addKey(key); // ! to convince typescript Keyboard Plugin exists - const keyboardListener = keyObj.addListener(event, callback); - this.keyboardListeners.push(keyboardListener); + if (this.scene.input.keyboard) { + const keyObj = this.scene.input.keyboard.addKey(key); + const keyboardListener = keyObj.addListener(event, callback); + this.keyboardListeners.push(keyboardListener); + } } /** From 10b11f4b6b3d8a8ae7d99765569073035193a21c Mon Sep 17 00:00:00 2001 From: JustATin555 Date: Tue, 4 Feb 2025 21:04:05 +0800 Subject: [PATCH 4/6] Remove ! from keyboard guard and use if-return syntax for GameInputManager --- src/features/game/input/GameInputManager.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/features/game/input/GameInputManager.ts b/src/features/game/input/GameInputManager.ts index e2b420bfaf..d1909a447c 100644 --- a/src/features/game/input/GameInputManager.ts +++ b/src/features/game/input/GameInputManager.ts @@ -41,7 +41,7 @@ class GameInputManager { * @param active if true, keyboard input is enabled. Else, keyboard input is disabled. */ public enableKeyboardInput(active: boolean) { - if (this.scene.input.keyboard) this.scene.input.keyboard!.enabled = active; + if (this.scene.input.keyboard) this.scene.input.keyboard.enabled = active; } /** @@ -57,11 +57,11 @@ class GameInputManager { event: string | symbol, callback: Function ) { - if (this.scene.input.keyboard) { - const keyObj = this.scene.input.keyboard.addKey(key); - const keyboardListener = keyObj.addListener(event, callback); - this.keyboardListeners.push(keyboardListener); - } + if (!this.scene.input.keyboard) return; + + const keyObj = this.scene.input.keyboard.addKey(key); + const keyboardListener = keyObj.addListener(event, callback); + this.keyboardListeners.push(keyboardListener); } /** From 64b6f65a5e851fd720a218e3af7c5a5b10335da1 Mon Sep 17 00:00:00 2001 From: JustATin555 Date: Mon, 10 Feb 2025 13:17:44 +0800 Subject: [PATCH 5/6] Catch missing background music asset error --- src/features/game/sound/GameSoundManager.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/features/game/sound/GameSoundManager.ts b/src/features/game/sound/GameSoundManager.ts index 8ae17c78d8..f2aa98ff84 100644 --- a/src/features/game/sound/GameSoundManager.ts +++ b/src/features/game/sound/GameSoundManager.ts @@ -161,14 +161,18 @@ class GameSoundManager { const soundAsset = mandatory(this.getSoundAsset(soundKey)); const bgmVol = soundAsset.config.volume !== undefined ? soundAsset.config.volume : 1; - this.currBgMusic = this.getBaseSoundManager().add(soundAsset.key, { - ...soundAsset.config, - volume: bgmVol * this.bgmVol - }) as Phaser.Sound.WebAudioSound; - this.currBgMusicKey = soundAsset.key; - - // Finally, play it - this.currBgMusic.play(); + try { + this.currBgMusic = this.getBaseSoundManager().add(soundAsset.key, { + ...soundAsset.config, + volume: bgmVol * this.bgmVol + }) as Phaser.Sound.WebAudioSound; + this.currBgMusicKey = soundAsset.key; + + // Finally, play it + this.currBgMusic.play(); + } catch (err) { + console.error(err); + } } /** From 8577379286207f1f89a65e3ed6fe42fc6e95fa11 Mon Sep 17 00:00:00 2001 From: JustATin555 Date: Mon, 10 Feb 2025 13:30:54 +0800 Subject: [PATCH 6/6] prettier GameSoundManager --- src/features/game/sound/GameSoundManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/game/sound/GameSoundManager.ts b/src/features/game/sound/GameSoundManager.ts index f2aa98ff84..9997944518 100644 --- a/src/features/game/sound/GameSoundManager.ts +++ b/src/features/game/sound/GameSoundManager.ts @@ -167,7 +167,7 @@ class GameSoundManager { volume: bgmVol * this.bgmVol }) as Phaser.Sound.WebAudioSound; this.currBgMusicKey = soundAsset.key; - + // Finally, play it this.currBgMusic.play(); } catch (err) {