import { AudioClip } from 'cc'

import { GameConfig } from '../../game/config/GameConfig'

export default class MusicConfig {
  public static musicKey2Path: Map<string, string> = new Map<string, string>() // 资源预加载路径

  public static musicKey2Cache: Map<string, AudioClip> = new Map<string, AudioClip>() // 资源加载后cache路径

  public static init() {
    if (typeof GameConfig.GameName === 'undefined' || GameConfig.GameName === null) {
      console.error('GameConfig.GameName 未配置!')
      return
    }

    const musicConfig = {
      background_1: 'music/background_1',
      background_2: 'music/background_2',
      background_3: 'music/background_3',
      deadfish_1: 'music/deadfish_1',
      deadfish_2: 'music/deadfish_2',
      deadfish_3: 'music/deadfish_3',
      deadfish_4: 'music/deadfish_4',
      deadfish_5: 'music/deadfish_5',
      deadfish_6: 'music/deadfish_6',
      deadfish_7: 'music/deadfish_7',
      deadfish_8: 'music/deadfish_8',
      deadfish_9: 'music/deadfish_9',
      deadfish_10: 'music/deadfish_10',
      deadfish_11: 'music/deadfish_11',
      deadfish_12: 'music/deadfish_12',
      deadfish_13: 'music/deadfish_13',
      deadfish_14: 'music/deadfish_14',
      deadfish_15: 'music/deadfish_15',
      deadfish_16: 'music/deadfish_16',
      deadfish_17: 'music/deadfish_17',
      deadfish_18: 'music/deadfish_18',
      deadfish_19: 'music/deadfish_19',
      deadfish_20: 'music/deadfish_20',
      deadfish_21: 'music/deadfish_21',
      deadfish_22: 'music/deadfish_22',
      deadfish_23: 'music/deadfish_23',
      deadfish_24: 'music/deadfish_24',
      deadfish_25: 'music/deadfish_25',
      deadfish_26: 'music/deadfish_26',
      deadfish_27: 'music/deadfish_27',
      deadfish_28: 'music/deadfish_28',
      deadfish_29: 'music/deadfish_29',
      fire: 'music/fire',
    }
    // 音乐要预加载的配置
    for (const key in musicConfig) {
      if (Object.prototype.hasOwnProperty.call(musicConfig, key)) {
        const path = `${GameConfig.GameName}/${musicConfig[key]}`
        MusicConfig.musicKey2Path.set(key, path)
      }
    }
  }
}
