diff --git a/README.md b/README.md index c68778d1..4c6e71e4 100644 --- a/README.md +++ b/README.md @@ -101,4 +101,5 @@ Please refer to existing files. * [pad-rikuu](//github.com/kiootic/pad-rikuu) //Parse data * [html2canvas](//github.com/niklasvh/html2canvas) //Capture Image * [localforage](//github.com/localForage/localForage) //Easy IndexedDB +* [pako](//github.com/nodeca/pako) //Deflate URL length * [aaa](//github.com/jy4340132/aaa) //Play voice(ADPCM wav) \ No newline at end of file diff --git a/multi.html b/multi.html index afdbc458..03b853c3 100644 --- a/multi.html +++ b/multi.html @@ -19,6 +19,7 @@ const teamsCount = 2; + diff --git a/script-universal_function.js b/script-universal_function.js index cf088250..67005ac0 100644 --- a/script-universal_function.js +++ b/script-universal_function.js @@ -88,6 +88,13 @@ function getQueryString(name,url) { } } +function Uint8ArrayToString(fileData){ + return Array.from(fileData).map(int=>String.fromCharCode(int)).join(''); +} +function stringToUint8Array(str){ + const codeArr = Array.from(str).map(chr=>chr.charCodeAt(0)); + return new Uint8Array(codeArr); +} //数组去重 /* https://www.cnblogs.com/baiyangyuanzi/p/6726258.html * 实现思路:获取没重复的最右一值放入新数组。 @@ -111,15 +118,15 @@ Array.prototype.uniq = function() const pcmMemory = new WebAssembly.Memory({initial: 256, maximum: 256}); const pcmImportObj = { - env: { - abortStackOverflow: () => { throw new Error("overflow"); }, - table: new WebAssembly.Table({ initial: 0, maximum: 0, element: "anyfunc" }), - tableBase: 0, - memory: pcmMemory, - memoryBase: 102400, - STACKTOP: 0, - STACK_MAX: pcmMemory.buffer.byteLength, - } + env: { + abortStackOverflow: () => { throw new Error("overflow"); }, + table: new WebAssembly.Table({ initial: 0, maximum: 0, element: "anyfunc" }), + tableBase: 0, + memory: pcmMemory, + memoryBase: 102400, + STACKTOP: 0, + STACK_MAX: pcmMemory.buffer.byteLength, + } }; let pcmPlayer = null; @@ -127,33 +134,33 @@ let adpcm_wasm = null; function decodeAudio(fileName, decodeCallback) { - if(pcmPlayer != null) - { - pcmPlayer.close(); - } - pcmPlayer = new PCMPlayer(1, 44100); - fetch(fileName).then((response) => response.arrayBuffer()) - .then((bytes) => { - let audioData = new Uint8Array(bytes); - let step = 160; - for(let i = 0; i < audioData.byteLength; i += step) - { - let pcm16BitData = decodeCallback(audioData.slice(i, i + step)); - let pcmFloat32Data = Std.shortToFloatData(pcm16BitData); - pcmPlayer.feed(pcmFloat32Data); - } - }); + if(pcmPlayer != null) + { + pcmPlayer.close(); + } + pcmPlayer = new PCMPlayer(1, 44100); + fetch(fileName).then((response) => response.arrayBuffer()) + .then((bytes) => { + let audioData = new Uint8Array(bytes); + let step = 160; + for(let i = 0; i < audioData.byteLength; i += step) + { + let pcm16BitData = decodeCallback(audioData.slice(i, i + step)); + let pcmFloat32Data = Std.shortToFloatData(pcm16BitData); + pcmPlayer.feed(pcmFloat32Data); + } + }); } fetch("library/jy4340132-aaa/adpcm.wasm").then((response) => response.arrayBuffer()) .then((bytes) => WebAssembly.instantiate(bytes, pcmImportObj)) .then((wasm) => { adpcm_wasm = wasm; - /*addButton("adpcm").onclick = function () { - let decoder = new Adpcm(wasm, pcmImportObj); - decoder.resetDecodeState(new Adpcm.State(0, 0)); - decodeAudio("demo.adpcm", decoder.decode.bind(decoder)); - }*/ + /*addButton("adpcm").onclick = function () { + let decoder = new Adpcm(wasm, pcmImportObj); + decoder.resetDecodeState(new Adpcm.State(0, 0)); + decodeAudio("demo.adpcm", decoder.decode.bind(decoder)); + }*/ }); //▲ADPCM播放相关 function latentUseHole(latentId) @@ -519,7 +526,7 @@ function countTeamHp(memberArr, leader1id, leader2id, solo) return hp; }); - console.log(mHpArr); + console.log('单个队伍血量:',mHpArr); function memberHpMul(card,ls,memberArr,solo) { diff --git a/script.js b/script.js index 1bc84fa6..d7f30876 100644 --- a/script.js +++ b/script.js @@ -597,9 +597,14 @@ function reloadFormationData() let formationData; try { - const parameterDataString = getQueryString("d") || getQueryString("data"); + let parameterDataString = getQueryString("d") || getQueryString("data"); if (parameterDataString) { + if (parameterDataString.charAt(0) != '{') + { + parameterDataString = pako.inflate(parameterDataString,{to:'string'}) + console.log('数据字符串解压结果:',parameterDataString); + } formationData = JSON.parse(parameterDataString); } }catch(e) @@ -626,7 +631,14 @@ function creatNewUrl(arg){ const newSearch = new URLSearchParams(); if (language_i18n) newSearch.set("l",language_i18n); if (datasource && datasource!="ja") newSearch.set("s",datasource); - if (outObj) newSearch.set("d", JSON.stringify(outObj)); + + const dataJsonStr = JSON.stringify(outObj); //数据部分的字符串 + const deflate = pako.deflate(dataJsonStr,{to:'string'}); + + if (outObj) newSearch.set("d", + deflate.length < dataJsonStr.length ? //压缩后长度小于压缩前长度 + deflate : //使用压缩字符串 + dataJsonStr); //使用原始字符串 const newUrl = (arg.url || "") + '?' + newSearch.toString(); diff --git a/solo.html b/solo.html index 41205479..db2ca802 100644 --- a/solo.html +++ b/solo.html @@ -19,6 +19,7 @@ const teamsCount = 1; + diff --git a/triple.html b/triple.html index 175490d7..57d8f8f1 100644 --- a/triple.html +++ b/triple.html @@ -19,6 +19,7 @@ const teamsCount = 3; +