diff --git a/.env.example b/.env.example index e9c6cbbcd9..4cb5cc4867 100644 --- a/.env.example +++ b/.env.example @@ -2,6 +2,7 @@ REACT_APP_DEPLOYMENT_NAME=Source Academy REACT_APP_BACKEND_URL=http://localhost:4000 REACT_APP_USE_BACKEND=TRUE +REACT_APP_USE_BACKEND_ASSET_PREFIX=FALSE REACT_APP_PLAYGROUND_ONLY=FALSE REACT_APP_SHOW_RESEARCH_PROMPT=FALSE diff --git a/package.json b/package.json index 547140f029..409f9ce601 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,7 +146,9 @@ "husky": "^9.0.0", "npm-run-all2": "^7.0.0", "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", @@ -177,5 +179,6 @@ "last 1 firefox version", "last 1 safari version" ] - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/public/assets/mockChapter0.txt b/public/assets/mockChapter0.txt index 7a985d9fb0..b22cc9febf 100644 --- a/public/assets/mockChapter0.txt +++ b/public/assets/mockChapter0.txt @@ -113,7 +113,7 @@ dialogues Hmmm update_assessment_status*() Let me check - goto 2 if !userstate.assessments.173 else 3 + goto 1 if !userstate.assessments.173 else 3 what, What should I do now, Scottie? @you diff --git a/src/features/game/commons/CommonConstants.ts b/src/features/game/commons/CommonConstants.ts index 64ab1b6ee5..a0f06ea345 100644 --- a/src/features/game/commons/CommonConstants.ts +++ b/src/features/game/commons/CommonConstants.ts @@ -4,6 +4,7 @@ import FontAssets from '../assets/FontAssets'; export const Constants = { assetsFolder: Links.sourceAcademyAssets, + useBackendAssetPrefix: process.env.REACT_APP_USE_BACKEND_ASSET_PREFIX?.toUpperCase() === 'TRUE', fadeDuration: 600, nullFunction: () => {}, nullInteractionId: '', diff --git a/src/features/game/input/GameInputManager.ts b/src/features/game/input/GameInputManager.ts index 2ab78d792a..d1909a447c 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; + 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; + if (this.scene.input.keyboard) this.scene.input.keyboard.enabled = active; } /** @@ -57,6 +57,8 @@ class GameInputManager { event: string | symbol, callback: Function ) { + if (!this.scene.input.keyboard) return; + const keyObj = this.scene.input.keyboard.addKey(key); const keyboardListener = keyObj.addListener(event, callback); this.keyboardListeners.push(keyboardListener); diff --git a/src/features/game/sound/GameSoundManager.ts b/src/features/game/sound/GameSoundManager.ts index 8ae17c78d8..9997944518 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); + } } /** diff --git a/src/features/game/utils/GameUtils.ts b/src/features/game/utils/GameUtils.ts index 76852077ad..bb5de7a789 100644 --- a/src/features/game/utils/GameUtils.ts +++ b/src/features/game/utils/GameUtils.ts @@ -58,9 +58,12 @@ export function limitNumber(value: number, min: number, max: number) { */ export function toS3Path(fileName: string, courseCoded = false) { if (fileName.startsWith('/')) { - fileName = fileName.substr(1); + fileName = fileName.substring(1); } - return Constants.assetsFolder + (courseCoded ? assetsPrefix() + fileName : fileName); + return ( + Constants.assetsFolder + + (courseCoded && Constants.useBackendAssetPrefix ? assetsPrefix() + fileName : fileName) + ); } /** diff --git a/yarn.lock b/yarn.lock index a4f7376dfc..5166ea1922 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6633,11 +6633,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" @@ -10420,13 +10425,17 @@ 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== +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" + 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"