All files / blacktrigram/src/audio AudioAssetRegistry.ts

0% Statements 0/272
100% Branches 1/1
100% Functions 1/1
0% Lines 0/272

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
/**
 * Audio Asset Registry for Black Trigram Korean Martial Arts
 * Manages all audio assets including Korean martial arts specific sounds
 */
 
import {
  AudioCategory,
  CombatAudioMap,
  MusicTrack,
  MusicTrackId,
  SoundEffect,
  SoundEffectId,
  VoiceLine,
  VoiceLineId,
} from "./types";
 
export interface IAudioAssetRegistry {
  readonly music: Record<string, MusicTrack>;
  readonly sfx: Record<string, SoundEffect>;
  readonly voice: Record<string, VoiceLine>;
  readonly combat: CombatAudioMap;
}
 
export interface EnhancedAudioAsset {
  readonly id: string;
  readonly type: "sound" | "music" | "voice";
  readonly url: string;
  readonly formats: readonly string[];
  readonly loaded: boolean;
  volume?: number;
  readonly loop?: boolean;
  category?: AudioCategory;
  readonly metadata?: {
    readonly duration: number;
    readonly bitrate?: number;
    readonly channels?: number;
    readonly sampleRate?: number;
  };
  readonly preloadPriority?: "high" | "medium" | "low";
  readonly streaming?: boolean;
  readonly compressionOptions?: {
    readonly format: string;
    readonly quality: number;
  };
}
 
// Enhanced audio registry with proper types
export interface EnhancedAudioAssetRegistry extends AudioAssetRegistry {
  readonly enhanced?: Record<string, EnhancedAudioAsset>;
}
 
// Fix: Use class implementation instead of interface merging
export class AudioAssetRegistry {
  private sfxMap = new Map<SoundEffectId, SoundEffect>();
  private musicMap = new Map<MusicTrackId, MusicTrack>();
  private voiceMap = new Map<VoiceLineId, VoiceLine>();
 
  // Fix: Implement required combat property with proper stances
  public combat: CombatAudioMap = {
    attacks: {},
    impacts: {},
    stances: {
      geon: "stance_geon_sfx",
      tae: "stance_tae_sfx",
      li: "stance_li_sfx",
      jin: "stance_jin_sfx",
      son: "stance_son_sfx",
      gam: "stance_gam_sfx",
      gan: "stance_gan_sfx",
      gon: "stance_gon_sfx",
    },
    environments: {},
    ui: {},
  };
 
  public sfx: Record<SoundEffectId, SoundEffect> = {};
  public music: Record<MusicTrackId, MusicTrack> = {};
  public voice: Record<VoiceLineId, VoiceLine> = {};
 
  constructor() {
    this.initializeDefaultAssets();
  }
 
  private initializeDefaultAssets(): void {
    // Initialize with placeholder Korean martial arts sound effects
    this.registerSFX("hit_light", {
      id: "hit_light",
      type: "sound",
      name: "Light Hit", // Fix: Use simple string instead of KoreanText object
      category: "sfx", // Fix: Use string literal instead of enum
      url: "placeholder://hit_light",
      formats: ["audio/wav", "audio/mp3"],
      loaded: false,
      volume: 1.0,
      variations: [],
    });
 
    this.registerMusic("combat_theme", {
      id: "combat_theme",
      type: "music",
      name: "Combat Theme", // Fix: Use simple string instead of KoreanText object
      title: { korean: "전투 테마", english: "Combat Theme" },
      category: "music", // Fix: Use string literal instead of enum
      url: "placeholder://combat_theme",
      formats: ["audio/wav", "audio/mp3"],
      loaded: false,
      volume: 0.7,
      loop: true,
    });
 
    // Add intro_theme music with both mp3 and webm for intro screen
    this.registerMusic("intro_theme", {
      id: "intro_theme",
      type: "music",
      name: "Black Trigram Theme",
      title: { korean: "흑괘 테마", english: "Black Trigram Theme" },
      category: "music",
      url: "/assets/audio/music/intro_theme.mp3",
      formats: ["audio/mp3", "audio/webm"],
      loaded: false,
      volume: 0.7,
      loop: true,
      variations: [
        "/assets/audio/music/intro_theme.mp3",
        "/assets/audio/music/intro_theme.webm",
      ],
      bpm: 90,
      fadeInTime: 3000,
      fadeOutTime: 3000,
    });
  }
 
  public registerSFX(id: SoundEffectId, effect: SoundEffect): void {
    this.sfxMap.set(id, effect);
    this.sfx[id] = effect;
  }
 
  public registerMusic(id: MusicTrackId, track: MusicTrack): void {
    this.musicMap.set(id, track);
    this.music[id] = track;
  }
 
  public registerVoice(id: VoiceLineId, voice: VoiceLine): void {
    this.voiceMap.set(id, voice);
    this.voice[id] = voice;
  }
 
  public getSFX(id: SoundEffectId): SoundEffect | undefined {
    return this.sfxMap.get(id);
  }
 
  public getMusic(id: MusicTrackId): MusicTrack | undefined {
    return this.musicMap.get(id);
  }
 
  public getVoice(id: VoiceLineId): VoiceLine | undefined {
    return this.voiceMap.get(id);
  }
 
  public getAll(): IAudioAssetRegistry {
    return {
      sfx: this.sfx,
      music: this.music,
      voice: this.voice,
      combat: this.combat,
    };
  }
 
  // Korean martial arts sound effects registry
  private readonly soundEffects: Map<SoundEffectId, SoundEffect> = new Map([
    [
      "attack_light",
      {
        id: "attack_light",
        name: "Light Attack", // Fix: Use string instead of KoreanText object
        type: "sound",
        url: "/assets/audio/sfx/attack_light.mp3",
        formats: ["audio/mp3", "audio/wav"],
        loaded: false,
        volume: 0.8,
        category: "sfx", // Fix: Use string literal instead of enum
        pitch: 1.0,
        variations: ["attack_light_1.mp3", "attack_light_2.mp3"],
      },
    ],
    [
      "stance_change",
      {
        id: "stance_change",
        name: "Stance Change", // Fix: Use string instead of KoreanText object
        type: "sound",
        url: "/assets/audio/sfx/stance_change.mp3",
        formats: ["audio/mp3", "audio/wav"],
        loaded: false,
        volume: 0.6,
        category: "sfx", // Fix: Use string literal instead of enum
        pitch: 1.2,
      },
    ],
    [
      "vital_hit_critical",
      {
        id: "vital_hit_critical",
        name: "Critical Vital Point Hit", // Fix: Use string instead of KoreanText object
        type: "sound",
        url: "/assets/audio/sfx/vital_hit_critical.mp3",
        formats: ["audio/mp3", "audio/wav"],
        loaded: false,
        volume: 0.9,
        category: "sfx", // Fix: Use string literal instead of enum
        pitch: 0.8,
      },
    ],
    [
      "hit_light",
      {
        id: "hit_light",
        name: "Light Hit", // Fix: Use simple string instead of KoreanText object
        type: "sound",
        url: "/assets/audio/sfx/hit_light.mp3",
        formats: ["audio/mp3", "audio/wav"],
        loaded: false,
        volume: 0.7,
        category: "sfx", // Fix: Use string literal instead of enum
        pitch: 1.0,
        variations: [
          "/assets/audio/sfx/hit_light_1.mp3",
          "/assets/audio/sfx/hit_light_2.mp3",
        ],
      },
    ],
  ] as unknown as ReadonlyArray<[SoundEffectId, SoundEffect]>);
 
  // Korean martial arts music tracks
  private readonly musicTracks: Map<MusicTrackId, MusicTrack> = new Map([
    [
      "intro_theme",
      {
        id: "intro_theme",
        name: "Black Trigram Theme", // Fix: Use simple string instead of KoreanText object
        type: "music",
        url: "/assets/audio/music/intro_theme.mp3",
        formats: ["audio/mp3", "audio/webm"],
        loaded: false,
        volume: 0.7,
        loop: true,
        category: "music", // Fix: Use string literal instead of enum
        variations: [
          "/assets/audio/music/intro_theme.mp3",
          "/assets/audio/music/intro_theme.webm",
        ],
        bpm: 90,
        fadeInTime: 3000,
        fadeOutTime: 3000,
      },
    ],
    [
      "combat_theme",
      {
        id: "combat_theme",
        name: "Combat Music", // Fix: Use string instead of KoreanText object
        type: "music",
        url: "/assets/audio/music/combat_theme.mp3",
        formats: ["audio/mp3", "audio/webm"],
        loaded: false,
        title: { korean: "전투 음악", english: "Combat Music" },
        volume: 0.8,
        loop: true,
        category: "music", // Fix: Use string literal instead of enum
        bpm: 140,
        fadeInTime: 1000,
        fadeOutTime: 2000,
      },
    ],
    [
      "dojang_ambience",
      {
        id: "dojang_ambience",
        name: "Dojang Atmosphere", // Fix: Use string instead of KoreanText object
        type: "music",
        url: "/assets/audio/music/dojang_ambience.mp3",
        formats: ["audio/mp3", "audio/wav"],
        loaded: false,
        title: { korean: "도장 분위기", english: "Dojang Atmosphere" },
        volume: 0.4,
        loop: true,
        category: "music", // Fix: Use string literal instead of enum
        bpm: 60,
        fadeInTime: 3000,
        fadeOutTime: 3000,
      },
    ],
  ] as unknown as ReadonlyArray<[MusicTrackId, MusicTrack]>);
 
  // Fix: Remove unused destructured variables
  public loadSoundEffects(): void {
    // Process sound effects without unused variables
    this.soundEffects.forEach((effect) => {
      console.log(`Loading sound effect: ${effect.id}`);
    });
  }
 
  public loadMusicTracks(): void {
    // Process music tracks without unused variables
    this.musicTracks.forEach((track) => {
      console.log(`Loading music track: ${track.id}`);
    });
  }
 
  // Fix: Remove Map.find usage - Maps don't have find method
  public findSoundEffectByName(name: string): SoundEffect | undefined {
    for (const [_, effect] of this.soundEffects) {
      if (effect.name === name) {
        return effect;
      }
    }
    return undefined;
  }
 
  public findMusicTrackByName(name: string): MusicTrack | undefined {
    for (const [_, track] of this.musicTracks) {
      if (track.name === name) {
        return track;
      }
    }
    return undefined;
  }
 
  // Fix: Add getSoundEffect method
  public getSoundEffect(id: SoundEffectId): SoundEffect | undefined {
    return this.soundEffects.get(id);
  }
 
  // Fix: Add getMusicTrack method
  public getMusicTrack(id: MusicTrackId): MusicTrack | undefined {
    return this.musicTracks.get(id);
  }
 
  // Fix: Remove unused lightHitEffect and use string for name
  public getPlaceholderEffect(): SoundEffect {
    return {
      id: "placeholder_hit",
      name: "Placeholder Hit", // Fix: Use string instead of KoreanText object
      type: "sound",
      url: "/placeholder/hit.mp3",
      formats: ["audio/mp3"],
      loaded: false,
      volume: 0.5,
      category: "sfx", // Fix: Use string literal instead of enum
      pitch: 1.0,
    };
  }
 
  // Add missing loadAssets method
  public async loadAssets(): Promise<void> {
    console.log("Loading audio assets...");
    // Implementation would preload audio files
  }
}
 
// Export singleton instance
export const audioAssetRegistry = new AudioAssetRegistry();
 
// Default export
export default audioAssetRegistry;