Skip to content

Commit 594a530

Browse files
committed
fix level editor
1 parent e95db53 commit 594a530

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

game/js/CFP_Beta.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,24 @@ function decodeIZL3Bytes(bytes) {
191191
return untinyifyClone(obj);
192192
}
193193

194+
function bytesToBase64(bytes) {
195+
// Convert Uint8Array -> base64 without blowing the call stack.
196+
let binary = "";
197+
const chunkSize = 0x8000;
198+
for (let i = 0; i < bytes.length; i += chunkSize) {
199+
const chunk = bytes.subarray(i, i + chunkSize);
200+
binary += String.fromCharCode(...chunk);
201+
}
202+
return btoa(binary);
203+
}
204+
205+
function encodeStringIZL3(levelData) {
206+
const bytes = encodeIZL3(levelData);
207+
// Strip the "IZL3" header; strings store only the compressed payload.
208+
const compressed = bytes.slice(4);
209+
return "|" + bytesToBase64(compressed);
210+
}
211+
194212
function stringToBytesIZL3(str) {
195213
// Remove "|" prefix if present
196214
const base64 = str[0] === "|" ? str.slice(1) : str;

game/level/izombieleveleditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@
234234
levelDataElement.style.borderRadius = "10px";
235235
levelDataElement.style.fontSize = "large";
236236
levelDataElement.style.zIndex = "1000";
237-
levelDataElement.value = stringifyCloneTiny(cloneFromPlants(l, f));
237+
levelDataElement.value = encodeStringIZL3(cloneFromPlants(l, f));
238238
$("dAll").appendChild(levelDataElement);
239239
const copyButtonElement = document.createElement("button");
240240
copyButtonElement.style.position = "absolute";

0 commit comments

Comments
 (0)