Skip to content

Commit 56b1ab0

Browse files
authored
Bump Phaser from v3.55.2 to v3.87.0 (#3090)
* Bump phaser v3.55.2 to 3.87.0 * Add phaser3spectorjs to satisfy phaser problems * Guard against MouseManager or Keyboard not existing * Remove ! from keyboard guard and use if-return syntax for GameInputManager * Catch missing background music asset error * prettier GameSoundManager * Added REACT_APP_USE_BACKEND_ASSET_PREFIX to .env to allow for base url usage during development * Prettify using format:tsx * Invert useEmptyAssetPrefix for backwards compatibility * Stop fatal error on missing bgm key in ParserValidator * Fix versioning strategy and package.json post-merge * Update lockfile post-merge * ParserValidator now checks default sound assets for bgms and sfxs * ESLint sort imports * Shift USE_EMPTY_ASSET_PREFIX reading to commons/utils/Constants instead * Only check for default asset if BGM / SFX not found
1 parent 4c75816 commit 56b1ab0

File tree

10 files changed

+77
-31
lines changed

10 files changed

+77
-31
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ REACT_APP_DEPLOYMENT_NAME=Source Academy
22

33
REACT_APP_BACKEND_URL=http://localhost:4000
44
REACT_APP_USE_BACKEND=TRUE
5+
REACT_APP_USE_EMPTY_ASSET_PREFIX=FALSE
56
REACT_APP_PLAYGROUND_ONLY=FALSE
67
REACT_APP_SHOW_RESEARCH_PROMPT=FALSE
78

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"mdast-util-from-markdown": "^2.0.0",
6868
"mdast-util-to-hast": "^13.0.0",
6969
"normalize.css": "^8.0.1",
70-
"phaser": "^3.55.2",
70+
"phaser": "~3.87.0",
7171
"query-string": "^9.0.0",
7272
"re-resizable": "^6.9.9",
7373
"react": "^18.3.1",
@@ -148,7 +148,9 @@
148148
"husky": "^9.0.0",
149149
"npm-run-all2": "^7.0.0",
150150
"os-browserify": "^0.3.0",
151+
"path": "^0.12.7",
151152
"path-browserify": "^1.0.1",
153+
"phaser3spectorjs": "^0.0.8",
152154
"prettier": "^3.3.3",
153155
"process": "^0.11.10",
154156
"react-error-overlay": "^6.0.11",

public/assets/mockChapter0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ dialogues
113113
Hmmm
114114
update_assessment_status*()
115115
Let me check
116-
goto 2 if !userstate.assessments.173 else 3
116+
goto 1 if !userstate.assessments.173 else 3
117117

118118
what, What should I do now, Scottie?
119119
@you

src/commons/utils/Constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const storiesBackendUrl = process.env.REACT_APP_STORIES_BACKEND_URL;
2121
const cadetLoggerUrl = isTest ? undefined : process.env.REACT_APP_CADET_LOGGER;
2222
const cadetLoggerInterval = parseInt(process.env.REACT_APP_CADET_LOGGER_INTERVAL || '10000', 10);
2323
const useBackend = !isTest && isTrue(process.env.REACT_APP_USE_BACKEND);
24+
const useEmptyAssetPrefix = isTrue(process.env.REACT_APP_USE_EMPTY_ASSET_PREFIX);
2425
const defaultSourceChapter = Chapter.SOURCE_4;
2526
const defaultSourceVariant = Variant.DEFAULT;
2627
const defaultQuestionId = 0;
@@ -154,6 +155,7 @@ const Constants = {
154155
storiesBackendUrl,
155156
cadetLoggerUrl,
156157
useBackend,
158+
useEmptyAssetPrefix,
157159
defaultSourceChapter,
158160
defaultSourceVariant,
159161
defaultQuestionId,

src/features/game/commons/CommonConstants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Links } from 'src/commons/utils/Constants';
1+
import UtilConstants, { Links } from 'src/commons/utils/Constants';
22

33
import FontAssets from '../assets/FontAssets';
44

55
export const Constants = {
66
assetsFolder: Links.sourceAcademyAssets,
7+
useEmptyAssetPrefix: UtilConstants.useEmptyAssetPrefix,
78
fadeDuration: 600,
89
nullFunction: () => {},
910
nullInteractionId: '',

src/features/game/input/GameInputManager.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class GameInputManager {
3232
* @param active if true, mouse input is enabled. Else, mouse input is disabled.
3333
*/
3434
public enableMouseInput(active: boolean) {
35-
this.scene.input.mouse.enabled = active;
35+
if (this.scene.input.mouse) this.scene.input.mouse.enabled = active;
3636
}
3737

3838
/**
@@ -41,7 +41,7 @@ class GameInputManager {
4141
* @param active if true, keyboard input is enabled. Else, keyboard input is disabled.
4242
*/
4343
public enableKeyboardInput(active: boolean) {
44-
this.scene.input.keyboard.enabled = active;
44+
if (this.scene.input.keyboard) this.scene.input.keyboard.enabled = active;
4545
}
4646

4747
/**
@@ -57,6 +57,8 @@ class GameInputManager {
5757
event: string | symbol,
5858
callback: Function
5959
) {
60+
if (!this.scene.input.keyboard) return;
61+
6062
const keyObj = this.scene.input.keyboard.addKey(key);
6163
const keyboardListener = keyObj.addListener(event, callback);
6264
this.keyboardListeners.push(keyboardListener);

src/features/game/parser/ParserValidator.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { SoundAsset } from '../assets/AssetsTypes';
2+
import SoundAssets from '../assets/SoundAssets';
13
import { ItemId } from '../commons/CommonTypes';
24
import { GameItemType } from '../location/GameMapTypes';
35
import { GameSoundType } from '../sound/GameSoundTypes';
@@ -203,26 +205,40 @@ export default class ParserValidator {
203205
break;
204206

205207
case GameEntityType.bgms:
208+
// Count BGMs matching itemId
206209
const numberOfBgm = Parser.checkpoint.map
207210
.getSoundAssets()
208-
.filter(
209-
sound => sound.soundType === GameSoundType.BGM && sound.key === itemId
210-
).length;
211+
.reduce((acc: number, sound: SoundAsset): number => {
212+
return (
213+
acc + (sound.soundType === GameSoundType.BGM && sound.key === itemId ? 1 : 0)
214+
);
215+
}, 0);
211216
if (numberOfBgm === 0) {
212-
throw new Error(`Cannot find bgm key "${itemId}"`);
217+
// Check if itemId is a default BGM
218+
const isDefaultAsset = Object.values(SoundAssets).some(
219+
sound => sound.soundType === GameSoundType.BGM && sound.key === itemId
220+
);
221+
if (!isDefaultAsset) throw new Error(`Cannot find bgm key "${itemId}"`);
213222
} else if (numberOfBgm > 1) {
214223
throw new Error(`More than 1 bgm key "${itemId}"`);
215224
}
216225
break;
217226

218227
case GameEntityType.sfxs:
228+
// Count SFXs matching itemId
219229
const numberOfSfx = Parser.checkpoint.map
220230
.getSoundAssets()
221-
.filter(
222-
sound => sound.soundType === GameSoundType.SFX && sound.key === itemId
223-
).length;
231+
.reduce((acc: number, sound: SoundAsset): number => {
232+
return (
233+
acc + (sound.soundType === GameSoundType.SFX && sound.key === itemId ? 1 : 0)
234+
);
235+
}, 0);
224236
if (numberOfSfx === 0) {
225-
throw new Error(`Cannot find sfx key "${itemId}"`);
237+
// Check if itemId is a default SFX
238+
const isDefaultAsset = Object.values(SoundAssets).some(
239+
sound => sound.soundType === GameSoundType.SFX && sound.key === itemId
240+
);
241+
if (!isDefaultAsset) throw new Error(`Cannot find sfx key "${itemId}"`);
226242
} else if (numberOfSfx > 1) {
227243
throw new Error(`More than 1 sfx key "${itemId}"`);
228244
}

src/features/game/sound/GameSoundManager.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,18 @@ class GameSoundManager {
161161
const soundAsset = mandatory(this.getSoundAsset(soundKey));
162162
const bgmVol = soundAsset.config.volume !== undefined ? soundAsset.config.volume : 1;
163163

164-
this.currBgMusic = this.getBaseSoundManager().add(soundAsset.key, {
165-
...soundAsset.config,
166-
volume: bgmVol * this.bgmVol
167-
}) as Phaser.Sound.WebAudioSound;
168-
this.currBgMusicKey = soundAsset.key;
169-
170-
// Finally, play it
171-
this.currBgMusic.play();
164+
try {
165+
this.currBgMusic = this.getBaseSoundManager().add(soundAsset.key, {
166+
...soundAsset.config,
167+
volume: bgmVol * this.bgmVol
168+
}) as Phaser.Sound.WebAudioSound;
169+
this.currBgMusicKey = soundAsset.key;
170+
171+
// Finally, play it
172+
this.currBgMusic.play();
173+
} catch (err) {
174+
console.error(err);
175+
}
172176
}
173177

174178
/**

src/features/game/utils/GameUtils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ export function limitNumber(value: number, min: number, max: number) {
5858
*/
5959
export function toS3Path(fileName: string, courseCoded = false) {
6060
if (fileName.startsWith('/')) {
61-
fileName = fileName.substr(1);
61+
fileName = fileName.substring(1);
6262
}
63-
return Constants.assetsFolder + (courseCoded ? assetsPrefix() + fileName : fileName);
63+
return (
64+
Constants.assetsFolder +
65+
(courseCoded && !Constants.useEmptyAssetPrefix ? assetsPrefix() + fileName : fileName)
66+
);
6467
}
6568

6669
/**

yarn.lock

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9063,13 +9063,20 @@ __metadata:
90639063
languageName: node
90649064
linkType: hard
90659065

9066-
"eventemitter3@npm:^4.0.0, eventemitter3@npm:^4.0.1, eventemitter3@npm:^4.0.7":
9066+
"eventemitter3@npm:^4.0.0, eventemitter3@npm:^4.0.1":
90679067
version: 4.0.7
90689068
resolution: "eventemitter3@npm:4.0.7"
90699069
checksum: 10c0/5f6d97cbcbac47be798e6355e3a7639a84ee1f7d9b199a07017f1d2f1e2fe236004d14fa5dfaeba661f94ea57805385e326236a6debbc7145c8877fbc0297c6b
90709070
languageName: node
90719071
linkType: hard
90729072

9073+
"eventemitter3@npm:^5.0.1":
9074+
version: 5.0.1
9075+
resolution: "eventemitter3@npm:5.0.1"
9076+
checksum: 10c0/4ba5c00c506e6c786b4d6262cfbce90ddc14c10d4667e5c83ae993c9de88aa856033994dd2b35b83e8dc1170e224e66a319fa80adc4c32adcd2379bbc75da814
9077+
languageName: node
9078+
linkType: hard
9079+
90739080
"events@npm:^3.2.0":
90749081
version: 3.3.0
90759082
resolution: "events@npm:3.3.0"
@@ -9671,8 +9678,10 @@ __metadata:
96719678
normalize.css: "npm:^8.0.1"
96729679
npm-run-all2: "npm:^7.0.0"
96739680
os-browserify: "npm:^0.3.0"
9681+
path: "npm:^0.12.7"
96749682
path-browserify: "npm:^1.0.1"
9675-
phaser: "npm:^3.55.2"
9683+
phaser: "npm:~3.87.0"
9684+
phaser3spectorjs: "npm:^0.0.8"
96769685
prettier: "npm:^3.3.3"
96779686
process: "npm:^0.11.10"
96789687
query-string: "npm:^9.0.0"
@@ -14263,13 +14272,19 @@ __metadata:
1426314272
languageName: node
1426414273
linkType: hard
1426514274

14266-
"phaser@npm:^3.55.2":
14267-
version: 3.55.2
14268-
resolution: "phaser@npm:3.55.2"
14275+
"phaser3spectorjs@npm:^0.0.8":
14276+
version: 0.0.8
14277+
resolution: "phaser3spectorjs@npm:0.0.8"
14278+
checksum: 10c0/84933cc3e314279d2bd2c4b3356f2c93e0fe6918dcf6d7ab88d0df4d3457df05703e895012a27ba50d8dd3d9bc61183b58a7b8dde9ec81fc3d887e0fd77184dd
14279+
languageName: node
14280+
linkType: hard
14281+
14282+
"phaser@npm:~3.87.0":
14283+
version: 3.87.0
14284+
resolution: "phaser@npm:3.87.0"
1426914285
dependencies:
14270-
eventemitter3: "npm:^4.0.7"
14271-
path: "npm:^0.12.7"
14272-
checksum: 10c0/aed4c37a22174e843344328c6b0cc0a6160a49fe12d37a6fa0aab82d37d6bfc00a3c76fa792621fa61b02148e340c39dae5be4f0f5b7cb95df7c774b826455b3
14286+
eventemitter3: "npm:^5.0.1"
14287+
checksum: 10c0/39f5baef2cbd3c30ae65efb7f1b4a034f5fd87f51f74547574602a6bada014999a900561cb0efa17e086a6a06f886525d0832b1d465af382db8674c1ed42ef67
1427314288
languageName: node
1427414289
linkType: hard
1427514290

0 commit comments

Comments
 (0)