https://pvzm.net/ to play [Read-only GitHub mirror] pvzm.net
modded vs pvz plants-vs-zombies plantsvszombies javascript online zombie noads jspvz pvzm game plants plant
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

saving levels as files

Signed-off-by: ClaytonTDM <claytontdm@gmail.com>

+93 -11
+1 -1
game/UI.css
··· 1384 1384 background-color: #8f431b; 1385 1385 color: #fc6; 1386 1386 font-weight: bold; 1387 - font-size: 20px; 1387 + font-size: 16px; 1388 1388 font-family: Tahoma; 1389 1389 left: 400px; 1390 1390 top: 507px;
+24 -2
game/js/CFP_Beta.js
··· 34 34 return compressed; 35 35 } 36 36 37 + function compressBytes(input) { 38 + const compressed = pako.deflate(input); 39 + const compressedBase64 = btoa(String.fromCharCode.apply(null, compressed)); 40 + return compressedBase64.replaceAll("=", ""); 41 + } 42 + 37 43 function decompressString(compressedBase64) { 38 44 const compressed = Uint8Array.from(atob(compressedBase64), (c) => 39 45 c.charCodeAt(0) ··· 43 49 return decompressedString; 44 50 } 45 51 52 + function decompressStringNoBase64(compressed) { 53 + compressed = Uint8Array.from(compressed, (c) => 54 + c.charCodeAt(0) 55 + ); 56 + const decompressed = pako.inflate(compressed); 57 + const decompressedString = new TextDecoder().decode(decompressed); 58 + return decompressedString; 59 + } 60 + 46 61 function decompressStringFromBytes(compressed) { 47 62 const decompressed = pako.inflate(compressed); 48 63 const decompressedString = new TextDecoder().decode(decompressed); ··· 60 75 a.click(); 61 76 document.body.removeChild(a); 62 77 URL.revokeObjectURL(url); 63 - } 78 + } 79 + 64 80 65 81 async function openAndLoadFileAsBytes() { 66 82 return new Promise((resolve, reject) => { 67 83 const input = document.createElement("input"); 68 84 input.type = "file"; 69 - input.accept = ".izl"; 85 + // accept izl and izl2 86 + input.accept = ".izl,.izl2"; 70 87 input.onchange = () => { 71 88 const file = input.files[0]; 72 89 const reader = new FileReader(); ··· 82 99 input.click(); 83 100 }); 84 101 } 102 + 103 + async function fileToLevelData() { 104 + return "=" + compressString(decompressStringFromBytes(await openAndLoadFileAsBytes())); // i hate this and want to fix it but its 4 am and i need to sleep. fuck text encoding 105 + } 106 + 85 107 86 108 function cloneFromPlants(name, sun, screenshot) { 87 109 name = name
+13
game/level/izombiecustommenu.js
··· 47 47 buttonElement.setAttribute("value", "LOAD LEVEL"); 48 48 buttonElement.id = "btnNextLevel"; // not actually a next level button, but it's the same style 49 49 buttonElement.style.top = "60%"; 50 + buttonElement.style.left = "calc(50% - 120px)"; 51 + let buttonElementUpload = document.createElement("input"); 52 + buttonElementUpload.setAttribute("type", "button"); 53 + buttonElementUpload.setAttribute("value", "SELECT FILE"); 54 + buttonElementUpload.id = "btnNextLevel"; // not actually a next level button, but it's the same style 55 + buttonElementUpload.style.top = "60%"; 56 + buttonElementUpload.style.left = "calc(50% + 5px)"; 57 + buttonElementUpload.onclick = async function () { 58 + let levelData = await fileToLevelData(); 59 + inputDataElement.value = levelData; 60 + buttonElement.click(); 61 + } 62 + $("dAll").appendChild(buttonElementUpload); 50 63 buttonElement.onclick = function () { 51 64 // store the input value and disable it, then make it say "Loading..." 52 65 let levelData = inputDataElement.value;
+55 -8
game/level/izombieleveleditor.js
··· 295 295 $("dAll").appendChild( 296 296 copyButtonElement 297 297 ); 298 - let buttonElement = 298 + let closeButton = 299 299 document.createElement("input"); 300 - buttonElement.setAttribute( 300 + closeButton.setAttribute( 301 301 "type", 302 302 "button" 303 303 ); 304 - buttonElement.setAttribute( 304 + closeButton.setAttribute( 305 305 "value", 306 306 "EXIT" 307 307 ); 308 - buttonElement.id = "btnNextLevel"; // not actually a next level button, but it's the same style 309 - buttonElement.style.top = "60%"; 310 - buttonElement.onclick = function () { 308 + closeButton.id = "btnNextLevel"; // not actually a next level button, but it's the same style 309 + closeButton.style.top = "60%"; 310 + closeButton.style.left = "calc(50% - 120px)"; // "calc(33.333% - 56.5px)"; 311 + closeButton.onclick = function () { 311 312 $("dAll").style.zIndex = ""; 312 313 let oldLv = oS.Lvl; 313 314 SelectModal(0); ··· 317 318 ); 318 319 oS.Lvl = oldLv; 319 320 }; 320 - buttonElement.style.zIndex = "1000"; 321 + closeButton.style.zIndex = "1000"; 322 + 323 + let uploadButton = 324 + document.createElement("input"); 325 + uploadButton.setAttribute( 326 + "type", 327 + "button" 328 + ); 329 + uploadButton.setAttribute( 330 + "value", 331 + "UPLOAD" 332 + ); 333 + uploadButton.id = "btnNextLevel"; // not actually a next level button, but it's the same style 334 + uploadButton.style.top = "60%"; 335 + uploadButton.style.left = "calc(50% - 56.5px)"; 336 + uploadButton.onclick = function () { 337 + // nothing for now 338 + }; 339 + uploadButton.style.zIndex = "1000"; 340 + uploadButton.style.display = "none"; // hide for now 341 + 342 + let downloadButton = 343 + document.createElement("input"); 344 + downloadButton.setAttribute( 345 + "type", 346 + "button" 347 + ); 348 + downloadButton.setAttribute( 349 + "value", 350 + "DOWNLOAD" 351 + ); 352 + downloadButton.id = "btnNextLevel"; // not actually a next level button, but it's the same style 353 + downloadButton.style.top = "60%"; 354 + downloadButton.style.left = "calc(50% + 5px)"; // "calc(66.666% - 56.5px)"; 355 + downloadButton.onclick = function () { 356 + downloadBytesAsFile( 357 + compressStringAsBytes( 358 + tinyifyClone( 359 + cloneFromPlants(l, f) 360 + ) 361 + ), l + ".izl2" 362 + ) 363 + }; 364 + downloadButton.style.zIndex = "1000"; 365 + 321 366 // put in #dAll 322 - $("dAll").appendChild(buttonElement); 367 + $("dAll").appendChild(closeButton); 368 + $("dAll").appendChild(uploadButton); 369 + $("dAll").appendChild(downloadButton); 323 370 let coverElement = 324 371 document.createElement("div"); 325 372 coverElement.style.position =