Skip to content

Commit

Permalink
stuf
Browse files Browse the repository at this point in the history
Signed-off-by: ClaytonTDM <[email protected]>
  • Loading branch information
ClaytonTDM committed Oct 7, 2024
1 parent 86be711 commit dd3237b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 19 deletions.
24 changes: 23 additions & 1 deletion game/js/CFP_Beta.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = {};
Expand Down Expand Up @@ -126,7 +148,7 @@ async function captureScreenshot() {
reader.readAsDataURL(blob);
},
"image/webp",
0.75 // quality, 0-1
0.5 // quality, 0-1
);
})
.catch((error) => {
Expand Down
12 changes: 6 additions & 6 deletions game/js/Cheatcodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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");
}
Expand Down
39 changes: 27 additions & 12 deletions game/level/izombieleveleditorbeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit dd3237b

Please sign in to comment.