|
| 1 | +import { SoundAsset } from '../assets/AssetsTypes'; |
| 2 | +import SoundAssets from '../assets/SoundAssets'; |
1 | 3 | import { ItemId } from '../commons/CommonTypes'; |
2 | 4 | import { GameItemType } from '../location/GameMapTypes'; |
3 | 5 | import { GameSoundType } from '../sound/GameSoundTypes'; |
@@ -203,26 +205,40 @@ export default class ParserValidator { |
203 | 205 | break; |
204 | 206 |
|
205 | 207 | case GameEntityType.bgms: |
| 208 | + // Count BGMs matching itemId |
206 | 209 | const numberOfBgm = Parser.checkpoint.map |
207 | 210 | .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); |
211 | 216 | 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}"`); |
213 | 222 | } else if (numberOfBgm > 1) { |
214 | 223 | throw new Error(`More than 1 bgm key "${itemId}"`); |
215 | 224 | } |
216 | 225 | break; |
217 | 226 |
|
218 | 227 | case GameEntityType.sfxs: |
| 228 | + // Count SFXs matching itemId |
219 | 229 | const numberOfSfx = Parser.checkpoint.map |
220 | 230 | .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); |
224 | 236 | 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}"`); |
226 | 242 | } else if (numberOfSfx > 1) { |
227 | 243 | throw new Error(`More than 1 sfx key "${itemId}"`); |
228 | 244 | } |
|
0 commit comments