UNPKG

@oppo-minigame/cli

Version:

Command line interface for rapid OPPO minigame development

1 lines 40.5 kB
const EXCLUDE_FILES=["index.html","Build/UnityLoader.min.js","Build/UnityLoader.js","Build/.DS_Store",".DS_Store"],DEFAULT_PARENT_DIR="Build",DEFAULT_TPL_FILES=[],DEFAULT_TPL_FILES_JS=["main.js","store.js","unityAdapter.min.js"],DEFAULT_MAIN_JS_CONTENT=e=>['require("store.js")','require("unityAdapter.min.js")',"qg.setLoadingProgress({ progress: 0 })",`window["unityInstance"] = UnityLoader.instantiate("canvas", "Build/${e}.json", {\n onProgress: function(_, i) {\n qg.setLoadingProgress({ progress: (i * 100) | 0 });\n if (i == 1) {\n qg.loadingComplete({ complete: function(res) {} });\n }\n }\n });`],LOCAL_ADDRESSABLE_SETTINGS_CONTENT=(e="")=>[`${e}const fs = qg.getFileSystemManager();\n${e}const aaSettingsPath = 'StreamingAssets/aa/settings.json';\n${e}try {\n ${e}fs.accessSync(aaSettingsPath);\n ${e}const aaSettingsJson = fs.readFileSync(aaSettingsPath, 'utf8');\n ${e}if (aaSettingsJson) {\n ${e}const module = unityInstance['Module'];\n ${e}module['FS_createPath']('', 'StreamingAssets', true, true);\n ${e}module['FS_createPath']('StreamingAssets/', 'aa', true, true);\n ${e}module['FS_createDataFile'](aaSettingsPath, null, aaSettingsJson, true, true, true);\n ${e}const aaCatalogPath = 'StreamingAssets/aa/catalog.json';\n ${e}fs.accessSync(aaCatalogPath);\n ${e}const aaCatalogJson = fs.readFileSync(aaCatalogPath, 'utf8');\n ${e}if (aaCatalogJson) {\n ${e}module['FS_createDataFile'](aaCatalogPath, null, aaCatalogJson, true, true, true);\n ${e}}\n ${e}}\n${e}}\n${e}catch (e) {\n ${e}// No local Addressable settings file found, maybe is on the server or using traditional AssetBundle\n${e}}`],REPLACE_CONTENT={validate1:"function stringToUTF8Array(str,outU8Array,outIdx,maxBytesToWrite){if(str==undefined){return 0}",validate2:"function lengthBytesUTF8(str){if(str==undefined){return 0}",audio:'function _JS_Sound_Create_Channel(callback,userData){if(WEBAudio.audioWebEnabled==0)return;if(window["qg"]){var onEnded=(function(){if(callback)dynCall("vi",callback,[userData])});var channel={audio:null,loop:false,volume:1,isBind:false,isStop:false,stopTime:0,isPlay:false,playTime:0,isStopped:false,playAudio:(function(delay,offset){this.setup();if(delay>0){this.audio.volume=0;this.isPlay=true;this.playTime=delay}else{this.audio.volume=this.volume;this.audio.loop=this.loop}this.audio.play();if(offset!=0){this.audio.seek(offset)}}),setup:(function(){if(this.audio&&this.isBind==false){this.audio.offEnded(onEnded);this.audio.onEnded(onEnded);var self=this;this.isStoped=false;this.audio.offTimeUpdate(null);this.audio.onTimeUpdate((function(){if(self.isStop==true&&parseFloat(self.audio.currentTime)>=self.stopTime){self.stopTime=0;self.isStop=false;self.audio.stop();self.audio.destroy();self.audio.src="";self.isBind=false;self.isStoped=true}if(!self.isStoped&&self.isPlay==true&&parseFloat(self.audio.currentTime)>=self.playTime){self.isPlay=false;self.playTime=0;self.audio.volume=self.volume;self.audio.loop=self.loop}}));this.isBind=true}}),stopAudio:(function(time){if(time==0){this.audio.offTimeUpdate(null);this.audio.offEnded(onEnded);this.stopTime=0;this.isStop=false;this.audio.stop();this.audio.destroy();this.audio.src="";this.isBind=false}else{this.stopTime=time;this.isStop=true}})};return WEBAudio.audioInstances.push(channel)-1}else{var channel={gain:WEBAudio.audioContext.createGain(),panner:WEBAudio.audioContext.createPanner(),threeD:false,playBuffer:(function(delay,buffer,offset){this.source.buffer=buffer;var chan=this;this.source.onended=(function(){if(callback)dynCall("vi",callback,[userData]);chan.setup()});this.source.start(delay,offset)}),setup:(function(){this.source=WEBAudio.audioContext.createBufferSource();this.setupPanning()}),setupPanning:(function(){if(this.threeD){this.source.disconnect();this.source.connect(this.panner);this.panner.connect(this.gain)}else{this.panner.disconnect();this.source.connect(this.gain)}})};channel.panner.rolloffFactor=0;channel.gain.connect(WEBAudio.audioContext.destination);channel.setup();return WEBAudio.audioInstances.push(channel)-1}}function _JS_Sound_GetLength(bufferInstance){if(WEBAudio.audioWebEnabled==0)return 0;var sound=WEBAudio.audioInstances[bufferInstance];if(window["qg"]){return sound.bufferLength}else{var sampleRateRatio=44100/sound.buffer.sampleRate;return sound.buffer.length*sampleRateRatio}}function _JS_Sound_GetLoadState(bufferInstance){if(WEBAudio.audioWebEnabled==0)return 2;if(window["qg"]){var sound=WEBAudio.audioInstances[bufferInstance];var loadState=sound.loadState;if(loadState==1){return 2}else if(loadState==2){return 0}else{return 1}}else{var sound=WEBAudio.audioInstances[bufferInstance];if(sound.error)return 2;if(sound.buffer)return 0;return 1}}function _JS_Sound_Init(){if(window["qg"]){WEBAudio.audioWebEnabled=1}else{try{window.AudioContext=window.AudioContext||window.webkitAudioContext;WEBAudio.audioContext=new AudioContext;var tryToResumeAudioContext=(function(){if(WEBAudio.audioContext.state==="suspended")WEBAudio.audioContext.resume();else Module.clearInterval(resumeInterval)});var resumeInterval=Module.setInterval(tryToResumeAudioContext,400);WEBAudio.audioWebEnabled=1}catch(e){alert("Web Audio API is not supported in this browser")}}}function _JS_Sound_Load(ptr,length){if(WEBAudio.audioWebEnabled==0)return 0;if(window["qg"]){var sound={buffer:null,error:false,file:"",audio:window["qg"].createInnerAudioContext(),bufferLength:0,ptr:ptr,loadState:0};var __oppofs=window["qg"].getFileSystemManager();var instance=WEBAudio.audioInstances.push(sound)-1;sound.file=window["qg"].env.USER_DATA_PATH+"/audio"+ptr+""+length+".mp3";sound.buffer=HEAPU8.buffer.slice(ptr,ptr+length);try{__oppofs.accessSync(sound.file)}catch(e){__oppofs.writeFileSync(sound.file,sound.buffer,"binary")}sound.audio.onCanplay((function(){sound.bufferLength=44100*sound.audio.duration|0;sound.loadState=2}));sound.audio.onError((function(err){console.log(err);sound.loadState=1}));sound.audio.src=sound.file;return instance}else{var sound={buffer:null,error:false};var instance=WEBAudio.audioInstances.push(sound)-1;WEBAudio.audioContext.decodeAudioData(HEAPU8.buffer.slice(ptr,ptr+length),(function(buffer){sound.buffer=buffer}),(function(){sound.error=true;console.log("Decode error.")}));return instance}}function _JS_Sound_Load_PCM(channels,length,sampleRate,ptr){if(WEBAudio.audioWebEnabled==0)return 0;var sound={buffer:WEBAudio.audioContext.createBuffer(channels,length,sampleRate),error:false};for(var i=0;i<channels;i++){var offs=(ptr>>2)+length*i;var buffer=sound.buffer;var copyToChannel=buffer["copyToChannel"]||(function(source,channelNumber,startInChannel){var clipped=source.subarray(0,Math.min(source.length,this.length-(startInChannel|0)));this.getChannelData(channelNumber|0).set(clipped,startInChannel|0)});copyToChannel.apply(buffer,[HEAPF32.subarray(offs,offs+length),i,0])}var instance=WEBAudio.audioInstances.push(sound)-1;return instance}function _JS_Sound_Play(bufferInstance,channelInstance,offset,delay){if(window["qg"]){_JS_Sound_Stop(channelInstance,0);if(WEBAudio.audioWebEnabled==0)return;var sound=WEBAudio.audioInstances[bufferInstance];var channel=WEBAudio.audioInstances[channelInstance];if(sound.buffer){try{if(sound.audio.src!==""){channel.audio=sound.audio;channel.audio.volume=channel.volume;channel.audio.loop=channel.loop;channel.playAudio(parseFloat(sound.audio.currentTime)+delay,offset)}else{sound.loadState=0;sound.audio=window["qg"].createInnerAudioContext();sound.audio.onCanplay((function(){sound.bufferLength=44100*sound.audio.duration|0;sound.loadState=2}));sound.audio.onError((function(err){console.log(err);sound.loadState=1}));sound.audio.src=sound.file;channel.audio=sound.audio;channel.audio.volume=channel.volume;channel.audio.loop=channel.loop;var loadState=sound.loadState;if(loadState==0){var timer=setInterval((function(){if(sound.loadState!==0){if(sound.loadState==2){channel.playAudio(parseFloat(sound.audio.currentTime)+delay,offset)}clearInterval(timer)}}),100)}else if(loadState==2){channel.playAudio(parseFloat(sound.audio.currentTime)+delay,offset)}}}catch(e){console.error("playBuffer error. Exception: "+e)}}else console.log("Trying to play sound which is not loaded.")}else{_JS_Sound_Stop(channelInstance,0);if(WEBAudio.audioWebEnabled==0)return;var sound=WEBAudio.audioInstances[bufferInstance];var channel=WEBAudio.audioInstances[channelInstance];if(sound.buffer){try{channel.playBuffer(WEBAudio.audioContext.currentTime+delay,sound.buffer,offset)}catch(e){console.error("playBuffer error. Exception: "+e)}}else console.log("Trying to play sound which is not loaded.")}}function _JS_Sound_ReleaseInstance(instance){WEBAudio.audioInstances[instance]=null}function _JS_Sound_ResumeIfNeeded(){if(WEBAudio.audioWebEnabled==0)return;if(!window["qg"]){if(WEBAudio.audioContext.state==="suspended")WEBAudio.audioContext.resume()}}function _JS_Sound_Set3D(channelInstance,threeD){if(!window["qg"]){var channel=WEBAudio.audioInstances[channelInstance];if(channel.threeD!=threeD){channel.threeD=threeD;channel.setupPanning()}}}function _JS_Sound_SetListenerOrientation(x,y,z,xUp,yUp,zUp){if(WEBAudio.audioWebEnabled==0)return;if(!window["qg"]){if(WEBAudio.audioContext.listener.forwardX){WEBAudio.audioContext.listener.forwardX.setValueAtTime(-x,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.forwardY.setValueAtTime(-y,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.forwardZ.setValueAtTime(-z,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.upX.setValueAtTime(xUp,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.upY.setValueAtTime(yUp,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.upZ.setValueAtTime(zUp,WEBAudio.audioContext.currentTime)}else{WEBAudio.audioContext.listener.setOrientation(-x,-y,-z,xUp,yUp,zUp)}}}function _JS_Sound_SetListenerPosition(x,y,z){if(WEBAudio.audioWebEnabled==0)return;if(!window["qg"]){if(WEBAudio.audioContext.listener.positionX){WEBAudio.audioContext.listener.positionX.setValueAtTime(x,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.positionY.setValueAtTime(y,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.positionZ.setValueAtTime(z,WEBAudio.audioContext.currentTime)}else{WEBAudio.audioContext.listener.setPosition(x,y,z)}}}function _JS_Sound_SetLoop(channelInstance,loop){if(WEBAudio.audioWebEnabled==0)return;if(window["qg"]){var instance=WEBAudio.audioInstances[channelInstance];var isLoop=loop==1;instance.loop=isLoop;if(instance.audio!==null){instance.audio.loop=isLoop}}else{WEBAudio.audioInstances[channelInstance].source.loop=loop}}function _JS_Sound_SetLoopPoints(channelInstance,loopStart,loopEnd){if(!window["qg"]){if(WEBAudio.audioWebEnabled==0)return;var channel=WEBAudio.audioInstances[channelInstance];channel.source.loopStart=loopStart;channel.source.loopEnd=loopEnd}}function _JS_Sound_SetPitch(channelInstance,v){if(WEBAudio.audioWebEnabled==0)return;if(!window["qg"]){WEBAudio.audioInstances[channelInstance].source.playbackRate.setValueAtTime(v,WEBAudio.audioContext.currentTime)}else{var channel=WEBAudio.audioInstances[channelInstance];if(channel.audio){if(v==1){channel.audio.play()}else{channel.audio.pause()}}}}function _JS_Sound_SetPosition(channelInstance,x,y,z){if(WEBAudio.audioWebEnabled==0)return;if(!window["qg"]){WEBAudio.audioInstances[channelInstance].panner.setPosition(x,y,z)}}function _JS_Sound_SetVolume(channelInstance,v){if(window["qg"]){if(WEBAudio.audioWebEnabled==0)return;var instance=WEBAudio.audioInstances[channelInstance];instance.volume=v;if(instance.audio!==null){instance.audio.volume=v}}else{if(WEBAudio.audioWebEnabled==0)return;WEBAudio.audioInstances[channelInstance].gain.gain.setValueAtTime(v,WEBAudio.audioContext.currentTime)}}function _JS_Sound_Stop(channelInstance,delay){if(window["qg"]){if(WEBAudio.audioWebEnabled==0)return;var channel=WEBAudio.audioInstances[channelInstance];if(channel.audio){if(delay==0){channel.stopAudio(delay);channel.audio.offEnded(null)}else{channel.stopAudio(parseFloat(channel.audio.currentTime)+delay)}channel.audio=null}}else{if(WEBAudio.audioWebEnabled==0)return;var channel=WEBAudio.audioInstances[channelInstance];if(channel.source.buffer){try{channel.source.stop(WEBAudio.audioContext.currentTime+delay)}catch(e){channel.source.disconnect()}if(delay==0){channel.source.onended=(function(){});channel.setup()}}}}function _JS_SystemInfo_GetBrowserName',per1:'var start,end,__performance;if(window["qg"]){__performance=window["qg"].getPerformance()}else{__performance=window["performance"]}function receiveInstantiatedSource(output){end=__performance.now();if(window["qg"]){window["qg"].setWasmTaskCompile(false)}console.log("wasm compile time :",end-start);',per2:'function instantiateArrayBuffer(receiver){getBinaryPromise().then((function(binary){start=__performance.now();if(window["qg"]){window["qg"].setWasmTaskCompile(true)}',per3:"if (!window['qg'] && window.location.href.lastIndexOf(absoluteUrlMatch[0], 0))",per4:'meta.size=xhr.response.byteLength;meta.contentLength=xhr.getResponseHeader("content-length")||0;if(meta.contentLength!=0&&meta.contentLength==meta.size){CachedXMLHttpRequest.cache.put(cache.requestURL,meta,xhr.response,function(err){CachedXMLHttpRequest.log("\'"+cache.requestURL+"\' downloaded successfully ("+xhr.response.byteLength+" bytes) "+(err?"but not stored in indexedDB cache due to error.":"and stored in indexedDB cache."));if(onload){onload(e)}})};',per5:"if(err || !result || !result.meta || result.meta.responseType != xhr.responseType || result.response.byteLength == 0)",save:'if(window["qg"]){IDBFS.storeLocalEntry(entry["primaryKey"],entry,done)}else{IDBFS.storeLocalEntry(path,entry,done)}',selfper:'window["performance"]',requestReg:'if(!window["qg"]){var cacheControl=typeof Module.cacheControl=="function"?Module.cacheControl(_url):Module.cacheControl?Module.cacheControl["UnityWebRequest"]||Module.cacheControl["default"]:"no-cache";var http=Module.companyName&&Module.productName&&cacheControl&&cacheControl!="no-cache"?new UnityLoader.UnityCache.XMLHttpRequest({companyName:Module.companyName,productName:Module.productName,cacheControl:cacheControl}):new XMLHttpRequest;}else{var http=new XMLHttpRequest}',audio2:'function _JS_Sound_Create_Channel(callback,userData){if(WEBAudio.audioWebEnabled==0)return;if(window["qg"]){var onEnded=(function(){if(callback)dynCall("vi",callback,[userData])});var channel={audio:null,loop:false,volume:1,isBind:false,isStop:false,stopTime:0,isPlay:false,playTime:0,isStopped:false,playAudio:(function(delay,offset){this.setup();if(delay>0){this.audio.volume=0;this.isPlay=true;this.playTime=delay}else{this.audio.volume=this.volume;this.audio.loop=this.loop}this.audio.play();if(offset!=0){this.audio.seek(offset)}}),setup:(function(){if(this.audio&&this.isBind==false){this.audio.offEnded(onEnded);this.audio.onEnded(onEnded);var self=this;this.isStoped=false;this.audio.offTimeUpdate(null);this.audio.onTimeUpdate((function(){if(self.isStop==true&&parseFloat(self.audio.currentTime)>=self.stopTime){self.stopTime=0;self.isStop=false;self.audio.stop();self.audio.destroy();self.audio.src="";self.isBind=false;self.isStoped=true}if(!self.isStoped&&self.isPlay==true&&parseFloat(self.audio.currentTime)>=self.playTime){self.isPlay=false;self.playTime=0;self.audio.volume=self.volume;self.audio.loop=self.loop}}));this.isBind=true}}),stopAudio:(function(time){if(time==0){this.audio.offTimeUpdate(null);this.audio.offEnded(onEnded);this.stopTime=0;this.isStop=false;this.audio.stop();this.audio.destroy();this.audio.src="";this.isBind=false}else{this.stopTime=time;this.isStop=true}})};WEBAudio.audioInstances[++WEBAudio.audioInstanceIdCounter]=channel;return WEBAudio.audioInstanceIdCounter}else{var channel={gain:WEBAudio.audioContext.createGain(),panner:WEBAudio.audioContext.createPanner(),threeD:false,playBuffer:(function(startTime,buffer,startOffset){this.setup();this.source.buffer=buffer;var chan=this;this.source.onended=(function(){chan.disconnectSource();if(callback)dynCall("vi",callback,[userData])});this.source.start(startTime,startOffset);this.source.playbackStartTime=startTime-startOffset/this.source.playbackRate.value}),disconnectSource:(function(){if(this.source&&!this.source.isPausedMockNode){this.source.onended=null;this.source.disconnect();delete this.source}}),stop:(function(delay){if(channel.source&&channel.source.buffer){try{channel.source.stop(WEBAudio.audioContext.currentTime+delay)}catch(e){}if(delay==0){channel.disconnectSource()}}}),pause:(function(){var s=this.source;if(!s)return;var pausedSource={isPausedMockNode:true,loop:s.loop,loopStart:s.loopStart,loopEnd:s.loopEnd,buffer:s.buffer,playbackRate:s.playbackRate.value,playbackPausedAtPosition:s.estimatePlaybackPosition(),setPitch:(function(v){this.playbackRate=v})};this.stop(0);this.disconnectSource();this.source=pausedSource}),resume:(function(){var pausedSource=this.source;if(!pausedSource||!pausedSource.isPausedMockNode)return;delete this.source;this.setup();this.playBuffer(WEBAudio.audioContext.currentTime-Math.min(0,pausedSource.playbackPausedAtPosition),pausedSource.buffer,Math.max(0,pausedSource.playbackPausedAtPosition));this.source.loop=pausedSource.loop;this.source.loopStart=pausedSource.loopStart;this.source.loopEnd=pausedSource.loopEnd;this.source.setPitch(pausedSource.playbackRate)}),setup:(function(){if(this.source&&!this.source.isPausedMockNode)return;this.source=WEBAudio.audioContext.createBufferSource();this.source.estimatePlaybackPosition=(function(){var t=(WEBAudio.audioContext.currentTime-this.playbackStartTime)*this.playbackRate.value;if(this.loop&&t>=this.loopStart){t=(t-this.loopStart)%(this.loopEnd-this.loopStart)+this.loopStart}return t});this.source.setPitch=(function(newPitch){var curPosition=this.estimatePlaybackPosition();if(curPosition>=0){this.playbackStartTime=WEBAudio.audioContext.currentTime-curPosition/newPitch}this.playbackRate.value=newPitch});this.setupPanning()}),setupPanning:(function(){if(this.source.isPausedMockNode)return;this.source.disconnect();if(this.threeD){this.source.connect(this.panner);this.panner.connect(this.gain)}else{this.panner.disconnect();this.source.connect(this.gain)}})};channel.panner.rolloffFactor=0;channel.gain.connect(WEBAudio.audioContext.destination);WEBAudio.audioInstances[++WEBAudio.audioInstanceIdCounter]=channel;return WEBAudio.audioInstanceIdCounter}}function _JS_Sound_GetLength(bufferInstance){if(WEBAudio.audioWebEnabled==0)return 0;var sound=WEBAudio.audioInstances[bufferInstance];if(window["qg"]){return sound.bufferLength}else{var sampleRateRatio=44100/sound.buffer.sampleRate;return sound.buffer.length*sampleRateRatio}}function _JS_Sound_GetLoadState(bufferInstance){if(WEBAudio.audioWebEnabled==0)return 2;if(window["qg"]){var sound=WEBAudio.audioInstances[bufferInstance];var loadState=sound.loadState;if(loadState==1){return 2}else if(loadState==2){return 0}else{return 1}}else{var sound=WEBAudio.audioInstances[bufferInstance];if(sound.error)return 2;if(sound.buffer)return 0;return 1}}function _JS_Sound_Init(){if(window["qg"]){WEBAudio.audioWebEnabled=1}else{try{window.AudioContext=window.AudioContext||window.webkitAudioContext;WEBAudio.audioContext=new AudioContext;var tryToResumeAudioContext=(function(){if(WEBAudio.audioContext.state==="suspended")WEBAudio.audioContext.resume();else Module.clearInterval(resumeInterval)});var resumeInterval=Module.setInterval(tryToResumeAudioContext,400);WEBAudio.audioWebEnabled=1}catch(e){alert("Web Audio API is not supported in this browser")}}}function _JS_Sound_Load(ptr,length){if(WEBAudio.audioWebEnabled==0)return 0;if(window["qg"]){var sound={buffer:null,error:false,file:"",audio:window["qg"].createInnerAudioContext(),bufferLength:0,ptr:ptr,loadState:0};var __oppofs=window["qg"].getFileSystemManager();WEBAudio.audioInstances[++WEBAudio.audioInstanceIdCounter]=sound;sound.file=window["qg"].env.USER_DATA_PATH+"/audio"+ptr+""+length+".mp3";sound.buffer=HEAPU8.buffer.slice(ptr,ptr+length);try{__oppofs.accessSync(sound.file)}catch(e){__oppofs.writeFileSync(sound.file,sound.buffer,"binary")}sound.audio.onCanplay((function(){sound.bufferLength=44100*sound.audio.duration|0;sound.loadState=2}));sound.audio.onError((function(err){console.log(err);sound.loadState=1}));sound.audio.src=sound.file;return WEBAudio.audioInstanceIdCounter}else{var sound={buffer:null,error:false};WEBAudio.audioInstances[++WEBAudio.audioInstanceIdCounter]=sound;var audioData=HEAPU8.buffer.slice(ptr,ptr+length);WEBAudio.audioContext.decodeAudioData(audioData,(function(buffer){sound.buffer=buffer}),(function(){sound.error=true;console.log("Decode error.")}));return WEBAudio.audioInstanceIdCounter}}function _JS_Sound_Load_PCM(channels,length,sampleRate,ptr){if(WEBAudio.audioWebEnabled==0)return 0;var sound={buffer:WEBAudio.audioContext.createBuffer(channels,length,sampleRate),error:false};for(var i=0;i<channels;i++){var offs=(ptr>>2)+length*i;var buffer=sound.buffer;var copyToChannel=buffer["copyToChannel"]||(function(source,channelNumber,startInChannel){var clipped=source.subarray(0,Math.min(source.length,this.length-(startInChannel|0)));this.getChannelData(channelNumber|0).set(clipped,startInChannel|0)});copyToChannel.apply(buffer,[HEAPF32.subarray(offs,offs+length),i,0])}WEBAudio.audioInstances[++WEBAudio.audioInstanceIdCounter]=sound;return WEBAudio.audioInstanceIdCounter}function _JS_Sound_Play(bufferInstance,channelInstance,offset,delay){if(window["qg"]){_JS_Sound_Stop(channelInstance,0);if(WEBAudio.audioWebEnabled==0)return;var sound=WEBAudio.audioInstances[bufferInstance];var channel=WEBAudio.audioInstances[channelInstance];if(sound.buffer){try{if(sound.audio.src!==""){channel.audio=sound.audio;channel.audio.volume=channel.volume;channel.audio.loop=channel.loop;channel.playAudio(parseFloat(sound.audio.currentTime)+delay,offset)}else{sound.loadState=0;sound.audio=window["qg"].createInnerAudioContext();sound.audio.onCanplay((function(){sound.bufferLength=44100*sound.audio.duration|0;sound.loadState=2}));sound.audio.onError((function(err){console.log(err);sound.loadState=1}));sound.audio.src=sound.file;channel.audio=sound.audio;channel.audio.volume=channel.volume;channel.audio.loop=channel.loop;var loadState=sound.loadState;if(loadState==0){var timer=setInterval((function(){if(sound.loadState!==0){if(sound.loadState==2){channel.playAudio(parseFloat(sound.audio.currentTime)+delay,offset)}clearInterval(timer)}}),100)}else if(loadState==2){channel.playAudio(parseFloat(sound.audio.currentTime)+delay,offset)}}}catch(e){console.error("playBuffer error. Exception: "+e)}}else console.log("Trying to play sound which is not loaded.")}else{_JS_Sound_Stop(channelInstance,0);if(WEBAudio.audioWebEnabled==0)return;var sound=WEBAudio.audioInstances[bufferInstance];var channel=WEBAudio.audioInstances[channelInstance];if(sound.buffer){try{channel.playBuffer(WEBAudio.audioContext.currentTime+delay,sound.buffer,offset)}catch(e){console.error("playBuffer error. Exception: "+e)}}else console.log("Trying to play sound which is not loaded.")}}function _JS_Sound_ReleaseInstance(instance){delete WEBAudio.audioInstances[instance]}function _JS_Sound_ResumeIfNeeded(){if(WEBAudio.audioWebEnabled==0)return;if(!window["qg"]){if(WEBAudio.audioContext.state==="suspended")WEBAudio.audioContext.resume()}}function _JS_Sound_Set3D(channelInstance,threeD){if(!window["qg"]){var channel=WEBAudio.audioInstances[channelInstance];if(channel.threeD!=threeD){channel.threeD=threeD;if(!channel.source){channel.setup()}channel.setupPanning()}}}function _JS_Sound_SetListenerOrientation(x,y,z,xUp,yUp,zUp){if(WEBAudio.audioWebEnabled==0)return;if(!window["qg"]){if(WEBAudio.audioContext.listener.forwardX){WEBAudio.audioContext.listener.forwardX.setValueAtTime(-x,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.forwardY.setValueAtTime(-y,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.forwardZ.setValueAtTime(-z,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.upX.setValueAtTime(xUp,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.upY.setValueAtTime(yUp,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.upZ.setValueAtTime(zUp,WEBAudio.audioContext.currentTime)}else{WEBAudio.audioContext.listener.setOrientation(-x,-y,-z,xUp,yUp,zUp)}}}function _JS_Sound_SetListenerPosition(x,y,z){if(WEBAudio.audioWebEnabled==0)return;if(!window["qg"]){if(WEBAudio.audioContext.listener.positionX){WEBAudio.audioContext.listener.positionX.setValueAtTime(x,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.positionY.setValueAtTime(y,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.positionZ.setValueAtTime(z,WEBAudio.audioContext.currentTime)}else{WEBAudio.audioContext.listener.setPosition(x,y,z)}}}function _JS_Sound_SetLoop(channelInstance,loop){if(WEBAudio.audioWebEnabled==0)return;if(window["qg"]){var instance=WEBAudio.audioInstances[channelInstance];var isLoop=loop==1;instance.loop=isLoop;if(instance.audio!==null){instance.audio.loop=isLoop}}else{WEBAudio.audioInstances[channelInstance].source.loop=loop}}function _JS_Sound_SetLoopPoints(channelInstance,loopStart,loopEnd){if(!window["qg"]){if(WEBAudio.audioWebEnabled==0)return;var channel=WEBAudio.audioInstances[channelInstance];if(!channel.source){channel.setup()}channel.source.loopStart=loopStart;channel.source.loopEnd=loopEnd}}function _JS_Sound_SetPaused(channelInstance,paused){if(WEBAudio.audioWebEnabled==0)return;var channel=WEBAudio.audioInstances[channelInstance];if(channel.audio){if(!paused){channel.audio.play()}else{channel.audio.pause()}}}function _JS_Sound_SetPitch(channelInstance,v){if(WEBAudio.audioWebEnabled==0)return;if(!window["qg"]){try{WEBAudio.audioInstances[channelInstance].source.setPitch(v)}catch(e){console.error("Invalid audio pitch "+v+" specified to WebAudio backend!")}}else{var channel=WEBAudio.audioInstances[channelInstance];if(channel.audio){if(v==1){channel.audio.play()}else{channel.audio.pause()}}}}function _JS_Sound_SetPosition(channelInstance,x,y,z){if(WEBAudio.audioWebEnabled==0)return;if(!window["qg"]){var channel=WEBAudio.audioInstances[channelInstance];if(channel.x!=x||channel.y!=y||channel.z!=z){channel.panner.setPosition(x,y,z);channel.x=x;channel.y=y;channel.z=z}}}function _JS_Sound_SetVolume(channelInstance,v){if(window["qg"]){if(WEBAudio.audioWebEnabled==0)return;var instance=WEBAudio.audioInstances[channelInstance];instance.volume=v;if(instance.audio!==null){instance.audio.volume=v}}else{if(WEBAudio.audioWebEnabled==0)return;WEBAudio.audioInstances[channelInstance].gain.gain.setValueAtTime(v,WEBAudio.audioContext.currentTime)}}function _JS_Sound_Stop(channelInstance,delay){if(window["qg"]){if(WEBAudio.audioWebEnabled==0)return;var channel=WEBAudio.audioInstances[channelInstance];if(channel.audio){if(delay==0){channel.stopAudio(delay);channel.audio.offEnded(null)}else{channel.stopAudio(parseFloat(channel.audio.currentTime)+delay)}channel.audio=null}}else{if(WEBAudio.audioWebEnabled==0)return;var channel=WEBAudio.audioInstances[channelInstance];channel.stop(delay)}}function _JS_SystemInfo_GetBrowserName',audio3:'function _JS_Sound_Create_Channel(callback,userData){if(WEBAudio.audioWebEnabled==0)return;if(window["qg"]){var onEnded=(function(){if(callback)dynCall("vi",callback,[userData])});var channel={audio:null,loop:false,volume:1,isBind:false,isStop:false,stopTime:0,isPlay:false,playTime:0,isStopped:false,playAudio:(function(delay,offset){this.setup();if(delay>0){this.audio.volume=0;this.isPlay=true;this.playTime=delay}else{this.audio.volume=this.volume;this.audio.loop=this.loop}this.audio.play();if(offset!=0){this.audio.seek(offset)}}),setup:(function(){if(this.audio&&this.isBind==false){this.audio.offEnded(onEnded);this.audio.onEnded(onEnded);var self=this;this.isStoped=false;this.audio.offTimeUpdate(null);this.audio.onTimeUpdate((function(){if(self.isStop==true&&parseFloat(self.audio.currentTime)>=self.stopTime){self.stopTime=0;self.isStop=false;self.audio.stop();self.audio.destroy();self.audio.src="";self.isBind=false;self.isStoped=true}if(!self.isStoped&&self.isPlay==true&&parseFloat(self.audio.currentTime)>=self.playTime){self.isPlay=false;self.playTime=0;self.audio.volume=self.volume;self.audio.loop=self.loop}}));this.isBind=true}}),stopAudio:(function(time){if(time==0){this.audio.offTimeUpdate(null);this.audio.offEnded(onEnded);this.stopTime=0;this.isStop=false;this.audio.stop();this.audio.destroy();this.audio.src="";this.isBind=false}else{this.stopTime=time;this.isStop=true}})};WEBAudio.audioInstances[++WEBAudio.audioInstanceIdCounter]=channel;return WEBAudio.audioInstanceIdCounter}else{var channel={gain:WEBAudio.audioContext.createGain(),panner:WEBAudio.audioContext.createPanner(),threeD:false,playBuffer:(function(startTime,buffer,startOffset){this.setup();this.source.buffer=buffer;var chan=this;this.source.onended=(function(){chan.disconnectSource();if(callback)dynCall("vi",callback,[userData])});this.source.start(startTime,startOffset);this.source.playbackStartTime=startTime-startOffset/this.source.playbackRate.value}),disconnectSource:(function(){if(this.source&&!this.source.isPausedMockNode){this.source.onended=null;this.source.disconnect();delete this.source}}),stop:(function(delay){if(channel.source&&channel.source.buffer){try{channel.source.stop(WEBAudio.audioContext.currentTime+delay)}catch(e){}if(delay==0){channel.disconnectSource()}}}),pause:(function(){var s=this.source;if(!s)return;var pausedSource={isPausedMockNode:true,loop:s.loop,loopStart:s.loopStart,loopEnd:s.loopEnd,buffer:s.buffer,playbackRate:s.playbackRate.value,playbackPausedAtPosition:s.estimatePlaybackPosition(),setPitch:(function(v){this.playbackRate=v})};this.stop(0);this.disconnectSource();this.source=pausedSource}),resume:(function(){var pausedSource=this.source;if(!pausedSource||!pausedSource.isPausedMockNode)return;delete this.source;this.setup();this.playBuffer(WEBAudio.audioContext.currentTime-Math.min(0,pausedSource.playbackPausedAtPosition),pausedSource.buffer,Math.max(0,pausedSource.playbackPausedAtPosition));this.source.loop=pausedSource.loop;this.source.loopStart=pausedSource.loopStart;this.source.loopEnd=pausedSource.loopEnd;this.source.setPitch(pausedSource.playbackRate)}),setup:(function(){if(this.source&&!this.source.isPausedMockNode)return;this.source=WEBAudio.audioContext.createBufferSource();this.source.estimatePlaybackPosition=(function(){var t=(WEBAudio.audioContext.currentTime-this.playbackStartTime)*this.playbackRate.value;if(this.loop&&t>=this.loopStart){t=(t-this.loopStart)%(this.loopEnd-this.loopStart)+this.loopStart}return t});this.source.setPitch=(function(newPitch){var curPosition=this.estimatePlaybackPosition();if(curPosition>=0){this.playbackStartTime=WEBAudio.audioContext.currentTime-curPosition/newPitch}this.playbackRate.value=newPitch});this.setupPanning()}),setupPanning:(function(){if(this.source.isPausedMockNode)return;this.source.disconnect();if(this.threeD){this.source.connect(this.panner);this.panner.connect(this.gain)}else{this.panner.disconnect();this.source.connect(this.gain)}})};channel.panner.rolloffFactor=0;channel.gain.connect(WEBAudio.audioContext.destination);WEBAudio.audioInstances[++WEBAudio.audioInstanceIdCounter]=channel;return WEBAudio.audioInstanceIdCounter}}function _JS_Sound_GetLength(bufferInstance){if(WEBAudio.audioWebEnabled==0)return 0;var sound=WEBAudio.audioInstances[bufferInstance];if(window["qg"]){return sound.bufferLength}else{var sampleRateRatio=44100/sound.buffer.sampleRate;return sound.buffer.length*sampleRateRatio}}function _JS_Sound_GetLoadState(bufferInstance){if(WEBAudio.audioWebEnabled==0)return 2;if(window["qg"]){var sound=WEBAudio.audioInstances[bufferInstance];var loadState=sound.loadState;if(loadState==1){return 2}else if(loadState==2){return 0}else{return 1}}else{var sound=WEBAudio.audioInstances[bufferInstance];if(sound.error)return 2;if(sound.buffer)return 0;return 1}}function _JS_Sound_Init(){if(window["qg"]){WEBAudio.audioWebEnabled=1}else{try{window.AudioContext=window.AudioContext||window.webkitAudioContext;WEBAudio.audioContext=new AudioContext;var tryToResumeAudioContext=(function(){if(WEBAudio.audioContext.state==="suspended")WEBAudio.audioContext.resume();else Module.clearInterval(resumeInterval)});var resumeInterval=Module.setInterval(tryToResumeAudioContext,400);WEBAudio.audioWebEnabled=1}catch(e){alert("Web Audio API is not supported in this browser")}}}function _JS_Sound_Load(ptr,length){if(WEBAudio.audioWebEnabled==0)return 0;if(window["qg"]){var sound={buffer:null,error:false,file:"",audio:window["qg"].createInnerAudioContext(),bufferLength:0,ptr:ptr,loadState:0};var __oppofs=window["qg"].getFileSystemManager();WEBAudio.audioInstances[++WEBAudio.audioInstanceIdCounter]=sound;sound.file=window["qg"].env.USER_DATA_PATH+"/audio"+ptr+""+length+".mp3";sound.buffer=HEAPU8.buffer.slice(ptr,ptr+length);try{__oppofs.accessSync(sound.file)}catch(e){__oppofs.writeFileSync(sound.file,sound.buffer,"binary")}sound.audio.onCanplay((function(){sound.bufferLength=44100*sound.audio.duration|0;sound.loadState=2}));sound.audio.onError((function(err){console.log(err);sound.loadState=1}));sound.audio.src=sound.file;return WEBAudio.audioInstanceIdCounter}else{var sound={buffer:null,error:false};WEBAudio.audioInstances[++WEBAudio.audioInstanceIdCounter]=sound;var audioData=HEAPU8.buffer.slice(ptr,ptr+length);WEBAudio.audioContext.decodeAudioData(audioData,(function(buffer){sound.buffer=buffer}),(function(){sound.error=true;console.log("Decode error.")}));return WEBAudio.audioInstanceIdCounter}}function _JS_Sound_Load_PCM(channels,length,sampleRate,ptr){if(WEBAudio.audioWebEnabled==0)return 0;var sound={buffer:WEBAudio.audioContext.createBuffer(channels,length,sampleRate),error:false};for(var i=0;i<channels;i++){var offs=(ptr>>2)+length*i;var buffer=sound.buffer;var copyToChannel=buffer["copyToChannel"]||(function(source,channelNumber,startInChannel){var clipped=source.subarray(0,Math.min(source.length,this.length-(startInChannel|0)));this.getChannelData(channelNumber|0).set(clipped,startInChannel|0)});copyToChannel.apply(buffer,[HEAPF32.subarray(offs,offs+length),i,0])}WEBAudio.audioInstances[++WEBAudio.audioInstanceIdCounter]=sound;return WEBAudio.audioInstanceIdCounter}function _JS_Sound_Play(bufferInstance,channelInstance,offset,delay){if(window["qg"]){_JS_Sound_Stop(channelInstance,0);if(WEBAudio.audioWebEnabled==0)return;var sound=WEBAudio.audioInstances[bufferInstance];var channel=WEBAudio.audioInstances[channelInstance];if(sound.buffer){try{if(sound.audio.src!==""){channel.audio=sound.audio;channel.audio.volume=channel.volume;channel.audio.loop=channel.loop;channel.playAudio(parseFloat(sound.audio.currentTime)+delay,offset)}else{sound.loadState=0;sound.audio=window["qg"].createInnerAudioContext();sound.audio.onCanplay((function(){sound.bufferLength=44100*sound.audio.duration|0;sound.loadState=2}));sound.audio.onError((function(err){console.log(err);sound.loadState=1}));sound.audio.src=sound.file;channel.audio=sound.audio;channel.audio.volume=channel.volume;channel.audio.loop=channel.loop;var loadState=sound.loadState;if(loadState==0){var timer=setInterval((function(){if(sound.loadState!==0){if(sound.loadState==2){channel.playAudio(parseFloat(sound.audio.currentTime)+delay,offset)}clearInterval(timer)}}),100)}else if(loadState==2){channel.playAudio(parseFloat(sound.audio.currentTime)+delay,offset)}}}catch(e){console.error("playBuffer error. Exception: "+e)}}else console.log("Trying to play sound which is not loaded.")}else{_JS_Sound_Stop(channelInstance,0);if(WEBAudio.audioWebEnabled==0)return;var sound=WEBAudio.audioInstances[bufferInstance];var channel=WEBAudio.audioInstances[channelInstance];if(sound.buffer){try{channel.playBuffer(WEBAudio.audioContext.currentTime+delay,sound.buffer,offset)}catch(e){console.error("playBuffer error. Exception: "+e)}}else console.log("Trying to play sound which is not loaded.")}}function _JS_Sound_ReleaseInstance(instance){delete WEBAudio.audioInstances[instance]}function _JS_Sound_ResumeIfNeeded(){if(WEBAudio.audioWebEnabled==0)return;if(!window["qg"]){if(WEBAudio.audioContext.state==="suspended")WEBAudio.audioContext.resume()}}function _JS_Sound_Set3D(channelInstance,threeD){if(!window["qg"]){var channel=WEBAudio.audioInstances[channelInstance];if(channel.threeD!=threeD){channel.threeD=threeD;if(!channel.source){channel.setup()}channel.setupPanning()}}}function _JS_Sound_SetListenerOrientation(x,y,z,xUp,yUp,zUp){if(WEBAudio.audioWebEnabled==0)return;if(!window["qg"]){if(WEBAudio.audioContext.listener.forwardX){WEBAudio.audioContext.listener.forwardX.setValueAtTime(-x,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.forwardY.setValueAtTime(-y,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.forwardZ.setValueAtTime(-z,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.upX.setValueAtTime(xUp,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.upY.setValueAtTime(yUp,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.upZ.setValueAtTime(zUp,WEBAudio.audioContext.currentTime)}else{WEBAudio.audioContext.listener.setOrientation(-x,-y,-z,xUp,yUp,zUp)}}}function _JS_Sound_SetListenerPosition(x,y,z){if(WEBAudio.audioWebEnabled==0)return;if(!window["qg"]){if(WEBAudio.audioContext.listener.positionX){WEBAudio.audioContext.listener.positionX.setValueAtTime(x,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.positionY.setValueAtTime(y,WEBAudio.audioContext.currentTime);WEBAudio.audioContext.listener.positionZ.setValueAtTime(z,WEBAudio.audioContext.currentTime)}else{WEBAudio.audioContext.listener.setPosition(x,y,z)}}}function _JS_Sound_SetLoop(channelInstance,loop){if(WEBAudio.audioWebEnabled==0)return;if(window["qg"]){var instance=WEBAudio.audioInstances[channelInstance];var isLoop=loop==1;instance.loop=isLoop;if(instance.audio!==null){instance.audio.loop=isLoop}}else{WEBAudio.audioInstances[channelInstance].source.loop=loop}}function _JS_Sound_SetLoopPoints(channelInstance,loopStart,loopEnd){if(!window["qg"]){if(WEBAudio.audioWebEnabled==0)return;var channel=WEBAudio.audioInstances[channelInstance];if(!channel.source){channel.setup()}channel.source.loopStart=loopStart;channel.source.loopEnd=loopEnd}}function _JS_Sound_SetPaused(channelInstance,paused){if(WEBAudio.audioWebEnabled==0)return;var channel=WEBAudio.audioInstances[channelInstance];if(channel.audio){if(!paused){channel.audio.play()}else{channel.audio.pause()}}}function _JS_Sound_SetPitch(channelInstance,v){if(WEBAudio.audioWebEnabled==0)return;if(!window["qg"]){try{WEBAudio.audioInstances[channelInstance].source.setPitch(v)}catch(e){console.error("Invalid audio pitch "+v+" specified to WebAudio backend!")}}else{var channel=WEBAudio.audioInstances[channelInstance];if(channel.audio){if(v==1){channel.audio.play()}else{channel.audio.pause()}}}}function _JS_Sound_SetPosition(channelInstance,x,y,z){if(WEBAudio.audioWebEnabled==0)return;if(!window["qg"]){var channel=WEBAudio.audioInstances[channelInstance];if(channel.x!=x||channel.y!=y||channel.z!=z){channel.panner.setPosition(x,y,z);channel.x=x;channel.y=y;channel.z=z}}}function _JS_Sound_SetVolume(channelInstance,v){if(window["qg"]){if(WEBAudio.audioWebEnabled==0)return;var instance=WEBAudio.audioInstances[channelInstance];instance.volume=v;if(instance.audio!==null){instance.audio.volume=v}}else{if(WEBAudio.audioWebEnabled==0)return;WEBAudio.audioInstances[channelInstance].gain.gain.setValueAtTime(v,WEBAudio.audioContext.currentTime)}}function _JS_Sound_Stop(channelInstance,delay){if(window["qg"]){if(WEBAudio.audioWebEnabled==0)return;var channel=WEBAudio.audioInstances[channelInstance];if(channel.audio){if(delay==0){channel.stopAudio(delay);channel.audio.offEnded(null)}else{channel.stopAudio(parseFloat(channel.audio.currentTime)+delay)}channel.audio=null}}else{if(WEBAudio.audioWebEnabled==0)return;var channel=WEBAudio.audioInstances[channelInstance];channel.stop(delay)}}function _JS_SystemInfo_GetCanvasClientSize'};module.exports={EXCLUDE_FILES:EXCLUDE_FILES,DEFAULT_PARENT_DIR:"Build",DEFAULT_TPL_FILES:DEFAULT_TPL_FILES,DEFAULT_TPL_FILES_JS:DEFAULT_TPL_FILES_JS,DEFAULT_MAIN_JS_CONTENT:DEFAULT_MAIN_JS_CONTENT,LOCAL_ADDRESSABLE_SETTINGS_CONTENT:LOCAL_ADDRESSABLE_SETTINGS_CONTENT,REPLACE_CONTENT:REPLACE_CONTENT};