diff --git a/game/js/CFP_Beta.js b/game/js/CFP_Beta.js index 2db35f1c..71b745c4 100644 --- a/game/js/CFP_Beta.js +++ b/game/js/CFP_Beta.js @@ -9,6 +9,12 @@ function compressString(input) { return compressedBase64.replaceAll("=", ""); } +function compressStringAsBytes(input) { + const inputUTF8 = new TextEncoder().encode(input); + const compressed = pako.deflate(inputUTF8); + return compressed; +} + function decompressString(compressedBase64) { const compressed = Uint8Array.from(atob(compressedBase64), (c) => c.charCodeAt(0) @@ -18,6 +24,22 @@ function decompressString(compressedBase64) { return decompressedString; } +function decompressStringFromBytes(compressed) { + const decompressed = pako.inflate(compressed); + const decompressedString = new TextDecoder().decode(decompressed); + return decompressedString; +} + +function downloadBytesAsFile(bytes, filename) { + const blob = new Blob([bytes], { type: "application/octet-stream" }); + const url = URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = url; + a.download = filename; + a.click(); + URL.revokeObjectURL(url); +} + function cloneFromPlants(name, sun, screenshot) { let keyedDict = Object.keys($P); let plantDict = {}; @@ -126,7 +148,7 @@ async function captureScreenshot() { reader.readAsDataURL(blob); }, "image/webp", - 0.75 // quality, 0-1 + 0.5 // quality, 0-1 ); }) .catch((error) => { diff --git a/game/js/Cheatcodes.js b/game/js/Cheatcodes.js index 2750e15c..e23247db 100644 --- a/game/js/Cheatcodes.js +++ b/game/js/Cheatcodes.js @@ -3,23 +3,23 @@ let keysPressed = {}; document.addEventListener("keydown", (event) => { keysPressed[event.key] = true; // super fast - if (keysPressed["s"] && keysPressed["f"]) { + if (keysPressed["s"] && keysPressed["f"] && document.activeElement.nodeName != 'TEXTAREA' && document.activeElement.nodeName != 'INPUT') { CSpeed(1000, 10, 1000); } // balloon - if (keysPressed["b"] && keysPressed["l"] && keysPressed["n"]) { + if (keysPressed["b"] && keysPressed["l"] && keysPressed["n"] && document.activeElement.nodeName != 'TEXTAREA' && document.activeElement.nodeName != 'INPUT') { oP.Balloon(); } // restart - /*if (keysPressed["r"]) { + /*if (keysPressed["r"] && document.activeElement.nodeName != 'TEXTAREA' && document.activeElement.nodeName != 'INPUT') { SelectModal(oS.Lvl); }*/ // almanac (handbook) - if (keysPressed["k"]) { + if (keysPressed["k"] && document.activeElement.nodeName != 'TEXTAREA' && document.activeElement.nodeName != 'INPUT') { ViewHandBook(); } // sun - if (keysPressed["j"]) { + if (keysPressed["j"] && document.activeElement.nodeName != 'TEXTAREA' && document.activeElement.nodeName != 'INPUT') { AppearSun( GetX(Math.floor(1 + Math.random() * oS.C)), GetY(Math.floor(1 + Math.random() * oS.R)), @@ -28,7 +28,7 @@ document.addEventListener("keydown", (event) => { ); } // oneko - if (keysPressed["c"] && keysPressed["a"] && keysPressed["t"]) { + if (keysPressed["c"] && keysPressed["a"] && keysPressed["t"] && document.activeElement.nodeName != 'TEXTAREA' && document.activeElement.nodeName != 'INPUT') { // remove .hidden from #oneko document.getElementById("oneko").classList.remove("hidden"); } diff --git a/game/level/izombieleveleditorbeta.js b/game/level/izombieleveleditorbeta.js index 2b4a12b0..9c4813e8 100644 --- a/game/level/izombieleveleditorbeta.js +++ b/game/level/izombieleveleditorbeta.js @@ -219,8 +219,10 @@ "Please enter a number in the range 50-1000!" ); // 输入阳光 - takeScreenshot = confirm("Take a screenshot? This will drastically increase the size of the level data."); - function finishSave() { + takeScreenshot = confirm( + "Take a screenshot? This will drastically increase the size of the level data." + ); + function finishSave(doScreenshot) { $("btnClickSave").innerHTML = "Saved!"; let levelDataElement = document.createElement("input"); @@ -243,9 +245,18 @@ levelDataElement.style.fontSize = "large"; levelDataElement.style.zIndex = "1000"; - levelDataElement.value = stringifyClone( - cloneFromPlants(l, f) - ); + if (doScreenshot) { + levelDataElement.value = + stringifyClone( + cloneFromPlants( + l, + f, + doScreenshot + ) + ); + } else { + levelDataElement.value = cloneFromPlants(l, f); + } $("dAll").appendChild(levelDataElement); let buttonElement = document.createElement("input"); @@ -317,13 +328,17 @@ "disabled"); // 按钮样式 // Ajax("asp/ImZombieCreateGame.asp", "post", "mapkind=" + oS.MapKind + "&SNum=" + f + "&T=" + escape(l) + "&C=" + escape(m), function(c){eval(c)}); // 发送请求 if (takeScreenshot) { - captureScreenshot().then((data) => { - finishSave(); - } - ).catch((error) => { - console.error("Screenshot capture failed:", error); - finishSave(); - }); + captureScreenshot() + .then((data) => { + finishSave(data); + }) + .catch((error) => { + console.error( + "Screenshot capture failed:", + error + ); + finishSave(); + }); } else { finishSave(); }