Spaces:
Sleeping
Sleeping
File size: 1,446 Bytes
343eed9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | class BackgroundMusic {
private static readonly SUPPORTED = ['ambient', 'epic', 'scary', 'none'];
private constructor(private readonly _value: string) {}
static create(value: string): BackgroundMusic {
if (!this.SUPPORTED.includes(value.toLowerCase())) {
throw new Error(`Music not supported: ${value}`);
}
return new BackgroundMusic(value.toLowerCase());
}
get value(): string {
return this._value;
}
}
class SoundEffect {
private static readonly SUPPORTED = ['scream', 'whoosh', 'none'];
private constructor(private readonly _value: string) {}
static create(value: string): SoundEffect {
if (!this.SUPPORTED.includes(value.toLowerCase())) {
throw new Error(`Sound effect not supported: ${value}`);
}
return new SoundEffect(value.toLowerCase());
}
get value(): string {
return this._value;
}
}
export interface MusicConfigProps {
backgroundMusic: string;
soundEffect: string;
}
export class MusicConfig {
private constructor(
public readonly backgroundMusic: BackgroundMusic,
public readonly soundEffect: SoundEffect
) {}
static create(props: MusicConfigProps): MusicConfig {
return new MusicConfig(
BackgroundMusic.create(props.backgroundMusic),
SoundEffect.create(props.soundEffect)
);
}
static createDefault(): MusicConfig {
return this.create({
backgroundMusic: 'none',
soundEffect: 'none'
});
}
}
|