|
| 1 | +import { SoundAsset } from '../assets/AssetsTypes'; |
1 | 2 | import SoundAssets from '../assets/SoundAssets'; |
2 | 3 | import { ItemId } from '../commons/CommonTypes'; |
3 | 4 | import { GameItemType } from '../location/GameMapTypes'; |
@@ -204,28 +205,40 @@ export default class ParserValidator { |
204 | 205 | break; |
205 | 206 |
|
206 | 207 | 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); |
213 | 216 | 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}"`); |
215 | 222 | } else if (numberOfBgm > 1) { |
216 | 223 | throw new Error(`More than 1 bgm key "${itemId}"`); |
217 | 224 | } |
218 | 225 | break; |
219 | 226 |
|
220 | 227 | 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); |
227 | 236 | 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}"`); |
229 | 242 | } else if (numberOfSfx > 1) { |
230 | 243 | throw new Error(`More than 1 sfx key "${itemId}"`); |
231 | 244 | } |
|
0 commit comments