const Sounds={BGM_TITLE:0,BGM_TOWN:1,BGM_AREA1:2,BGM_AREA2:3,BGM_AREA3:4,BGM_AREA4:5,BGM_BATTLE:6,BGM_BOSS_BATTLE:7,BGM_LAST_BATTLE:8,BGM_ENDING:9,BGM_ENDING2:10,SE_SELECT:11,SE_ESC:12,SE_SPACE:13,SE_LOAD:14,SE_SAVE:15,SE_MY_TURN:16,SE_M_SHOT:17,SE_FIRE:18,SE_ICE:19,SE_THUNDER:20,SE_EXPLOSION:21,SE_STRIKE:22,SE_STRIKE_C:23,SE_SLASH:24,SE_GARD:25,SE_HOIHOI:26,SE_INPUT:27,SE_SHOP:28,SE_WARP:29,SE_STEP:30,SE_DEL0:31,SE_DOWN:32,SE_STRIKE_:33,SE_STRIKE_C_:34,SE_SLASH_:35};const soundFileNames=new Array("bgm/Shade/1_MapBGM.mp3","bgm/Shade/8_MapBGM2.mp3","bgm/Shade/BGM3_01.mp3","bgm/Shade/BGM3_02.mp3","bgm/Shade/BGM3_06_VAR1.mp3","bgm/Shade/BGM3_11.mp3","bgm/Shade/2_Battle_variation2.mp3","bgm/Shade/2_Battle_variation1.mp3","bgm/Shade/2_Battle.mp3","bgm/Shade/BGM3_07_VAR1.mp3","bgm/Shade/BGM3_07_VAR2.mp3","se/Shade/Cursor2.mp3","se/Shade/Cancel2.mp3","se/Shade/Decision1.mp3","se/Shade/Load.mp3","se/Shade/Save.mp3","se/pig/my_turn.mp3","se/m2/tm2_bom005.mp3","se/m2/tm2_bom003.mp3","se/m2/tm2_metalhit001.mp3","se/m2/tm2_lightning000.mp3","se/pig/explosion.mp3","se/m2/tm2_hit004.mp3","se/m2/hit_p08_c.mp3","se/m2/tm2_slash003.mp3","se/m2/tm2_metalhit001.mp3","se/m2/tm2_mind000.mp3","se/m2/tm2_swing005.mp3","se/m2/coin05.mp3","se/m2/tm2_laser002.mp3","se/m2/tm2_footstep000.mp3","se/m2/tm2_pon000.mp3","se/m2/tm2_bush001.mp3","se/m2/tm2_hit004_.mp3","se/m2/hit_p08_c_.mp3","se/m2/tm2_slash003_.mp3");let soundNum=0;let soundLoadTotal=0;let soundLoadDone=0;let soundLoadFail=[];function resetSoundLoadState(){soundNum=0;soundLoadTotal=soundFileNames.length;soundLoadDone=0;soundLoadFail=[];soundloaded=0;sf_name=new Array(256);soundfile=new Array(256);snd_init=0} function getSoundLoadProgress(){return{total:soundLoadTotal,done:soundLoadDone,fail:soundLoadFail.length}} function loadOneSoundStrict(index,url,retryCount=1,timeoutMs=20000){return new Promise((resolve)=>{const tryLoad=(remain)=>{let finished=!1;let timerId=0;let audio=null;try {audio=new Audio()}catch(e){soundLoadFail.push({index,url,reason:"create_audio_failed"});resolve({ok:!1,index,url,reason:"create_audio_failed"});return} const finish=(ok,reason="")=>{if(finished)return;finished=!0;clearTimeout(timerId);audio.removeEventListener("canplaythrough",onReady);audio.removeEventListener("loadeddata",onReady);audio.removeEventListener("error",onError);if(ok){soundfile[index]=audio;sf_name[index]=url;soundLoadDone++;resolve({ok:!0,index,url})}else{if(remain>0){setTimeout(()=>tryLoad(remain-1),250);return} soundLoadFail.push({index,url,reason});resolve({ok:!1,index,url,reason})}};const onReady=function(){finish(!0)};const onError=function(){finish(!1,"error")};audio.preload="auto";audio.addEventListener("canplaythrough",onReady,{once:!0});audio.addEventListener("loadeddata",onReady,{once:!0});audio.addEventListener("error",onError,{once:!0});timerId=setTimeout(function(){finish(!1,"timeout")},timeoutMs);audio.src=url;audio.load()};tryLoad(retryCount)})} function loadSounds(){resetSoundLoadState();const tasks=[];for(let num=0;num<soundFileNames.length;num++,soundNum++){const path="./material/"+soundFileNames[num];sf_name[soundNum]=path;soundloaded++;tasks.push(loadOneSoundStrict(soundNum,path))} return Promise.all(tasks).then((results)=>{snd_init=1;return{ok:soundLoadFail.length===0,total:soundLoadTotal,done:soundLoadDone,failed:soundLoadFail,results:results}})}