Skip to content

Commit 5cd04db

Browse files
committed
Only check for default asset if BGM / SFX not found
1 parent ad079e7 commit 5cd04db

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

src/features/game/parser/ParserValidator.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SoundAsset } from '../assets/AssetsTypes';
12
import SoundAssets from '../assets/SoundAssets';
23
import { ItemId } from '../commons/CommonTypes';
34
import { GameItemType } from '../location/GameMapTypes';
@@ -204,28 +205,40 @@ export default class ParserValidator {
204205
break;
205206

206207
case GameEntityType.bgms:
207-
const numberOfBgm = [
208-
...Parser.checkpoint.map.getSoundAssets(), // Imported sound assets
209-
...Object.values(SoundAssets) // Default sound assets
210-
].filter(
211-
sound => sound.soundType === GameSoundType.BGM && sound.key === itemId
212-
).length;
208+
// Count BGMs matching itemId
209+
const numberOfBgm = Parser.checkpoint.map
210+
.getSoundAssets()
211+
.reduce((acc: number, sound: SoundAsset): number => {
212+
return (
213+
acc + (sound.soundType === GameSoundType.BGM && sound.key === itemId ? 1 : 0)
214+
);
215+
}, 0);
213216
if (numberOfBgm === 0) {
214-
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}"`);
215222
} else if (numberOfBgm > 1) {
216223
throw new Error(`More than 1 bgm key "${itemId}"`);
217224
}
218225
break;
219226

220227
case GameEntityType.sfxs:
221-
const numberOfSfx = [
222-
...Parser.checkpoint.map.getSoundAssets(), // Imported sound assets
223-
...Object.values(SoundAssets) // Default sound assets
224-
].filter(
225-
sound => sound.soundType === GameSoundType.SFX && sound.key === itemId
226-
).length;
228+
// Count SFXs matching itemId
229+
const numberOfSfx = Parser.checkpoint.map
230+
.getSoundAssets()
231+
.reduce((acc: number, sound: SoundAsset): number => {
232+
return (
233+
acc + (sound.soundType === GameSoundType.SFX && sound.key === itemId ? 1 : 0)
234+
);
235+
}, 0);
227236
if (numberOfSfx === 0) {
228-
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}"`);
229242
} else if (numberOfSfx > 1) {
230243
throw new Error(`More than 1 sfx key "${itemId}"`);
231244
}

0 commit comments

Comments
 (0)