Skip to content

Commit

Permalink
move file and format
Browse files Browse the repository at this point in the history
Signed-off-by: ClaytonTDM <[email protected]>
  • Loading branch information
ClaytonTDM committed Oct 8, 2024
1 parent 0a4498c commit 78ea6a2
Show file tree
Hide file tree
Showing 14 changed files with 1,967 additions and 1,900 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion .github/workflows/gifToWebp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Run conversion script
run: |
node gif-to-webp-converter.js
node .github/workflows/gif-to-webp-converter.js
- name: Check for changes
id: git-check
Expand Down
2 changes: 1 addition & 1 deletion game/UI.css
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ td.HandBookZombie {
width: 99px;
height: 99px;
cursor: pointer;
background: url(images/interface/SelectorScreen_Almanac_32.png) no-repeat;
background: url(images/interface/SelectorScreen_Almanac_32.png) no-repeat;
_background: url(images/interface/SelectorScreen_Almanac_8.png) no-repeat;
}

Expand Down
211 changes: 107 additions & 104 deletions game/js/CFP_Beta.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,80 +40,83 @@ function downloadBytesAsFile(bytes, filename) {
URL.revokeObjectURL(url);
}

async function openAndLoadFileAsBytes() {
return new Promise((resolve, reject) => {
const input = document.createElement("input");
input.type = "file";
input.accept = ".izl";
input.onchange = () => {
const file = input.files[0];
const reader = new FileReader();
reader.onload = () => {
const bytes = new Uint8Array(reader.result);
resolve(bytes); // resolve the promise with the byte array
};
reader.onerror = () => {
reject(new Error("Failed to read file"));
};
reader.readAsArrayBuffer(file);
};
input.click();
});
async function openAndLoadFileAsBytes() {
return new Promise((resolve, reject) => {
const input = document.createElement("input");
input.type = "file";
input.accept = ".izl";
input.onchange = () => {
const file = input.files[0];
const reader = new FileReader();
reader.onload = () => {
const bytes = new Uint8Array(reader.result);
resolve(bytes); // resolve the promise with the byte array
};
reader.onerror = () => {
reject(new Error("Failed to read file"));
};
reader.readAsArrayBuffer(file);
};
input.click();
});
}

function cloneFromPlants(name, sun, screenshot) {
let keyedDict = Object.keys($P);
let plantDict = {};
// for every object in $P, save the following data:
// $P[keyedDict[i]].R // save as plantRow
// $P[keyedDict[i]].C // save as plantCol
// Object.getPrototypeOf($P[keyedDict[6]]).EName // save as plantName
let keyedDict = Object.keys($P);
let plantDict = {};
// for every object in $P, save the following data:
// $P[keyedDict[i]].R // save as plantRow
// $P[keyedDict[i]].C // save as plantCol
// Object.getPrototypeOf($P[keyedDict[6]]).EName // save as plantName

for (let i = 0; i < keyedDict.length; i++) {
let plantRow = $P[keyedDict[i]].R;
let plantCol = $P[keyedDict[i]].C;
let plantName = Object.getPrototypeOf($P[keyedDict[i]]).EName;
let zIndex = $P[keyedDict[i]].zIndex;
plantDict[keyedDict[i]] = { zIndex, plantRow, plantCol, plantName };
}
// now turn it into an array of dictionaries
let plantArray = Object.values(plantDict);
// now put that array into another array with the background
let levelData = {
plants: plantArray,
music: oS.LoadMusic,
sun,
name,
lfValue: oGd.$LF,
screenshot,
/*
* not sure what lf stands for but its for where u can place plants/zombies
* 0 is for nothing
* 1 is for normal
* 2 is for water
* 3 is for oxygen/pots
* the first value should always be 0
*/
};
for (let i = 0; i < keyedDict.length; i++) {
let plantRow = $P[keyedDict[i]].R;
let plantCol = $P[keyedDict[i]].C;
let plantName = Object.getPrototypeOf($P[keyedDict[i]]).EName;
let zIndex = $P[keyedDict[i]].zIndex;
plantDict[keyedDict[i]] = { zIndex, plantRow, plantCol, plantName };
}
// now turn it into an array of dictionaries
let plantArray = Object.values(plantDict);
// now put that array into another array with the background
let levelData = {
plants: plantArray,
music: oS.LoadMusic,
sun,
name,
lfValue: oGd.$LF,
screenshot,
/*
* not sure what lf stands for but its for where u can place plants/zombies
* 0 is for nothing
* 1 is for normal
* 2 is for water
* 3 is for oxygen/pots
* the first value should always be 0
*/
};

if (oS.ArP && oS.ArP.ArC && oS.ArP.ArC[1] !== undefined) {
levelData.stripeCol = oS.ArP.ArC[1];
}
if (oS.ArP && oS.ArP.ArC && oS.ArP.ArC[1] !== undefined) {
levelData.stripeCol = oS.ArP.ArC[1];
}

return levelData;
return levelData;
}
function stringifyClone(levelData) {
if (levelData.screenshot) {
let screenshot = (levelData.screenshot).replace("data:image/webp;base64,", "");
let screenshot = levelData.screenshot.replace(
"data:image/webp;base64,",
""
);
delete levelData.screenshot;
return compressString(JSON.stringify(levelData)) + ';' + screenshot;
return compressString(JSON.stringify(levelData)) + ";" + screenshot;
} else {
return compressString(JSON.stringify(levelData));
}
}
function parseClone(stringifiedData) {
let levelData = JSON.parse(decompressString(stringifiedData.split(';')[0]));
let screenshot = stringifiedData.split(';')[1];
let levelData = JSON.parse(decompressString(stringifiedData.split(";")[0]));
let screenshot = stringifiedData.split(";")[1];
if (screenshot) {
levelData.screenshot = "data:image/webp;base64," + screenshot;
}
Expand All @@ -133,48 +136,48 @@ function restoreToPlants(levelData) {
}

async function captureScreenshot() {
return new Promise((resolve, reject) => {
const element = document.querySelector("#dAll");
const cardList = document.querySelector("#dCardList");
if (!element) {
console.error("Element #dAll not found");
reject("Element #dAll not found");
return;
}
html2canvas(element, {
ignoreElements: (el) => el === cardList, // Ignore #dCardList in the capture
})
.then((canvas) => {
// Get the original dimensions of the canvas
const originalWidth = canvas.width;
const originalHeight = canvas.height;
// Calculate the new height while maintaining the aspect ratio
const newWidth = 215;
const newHeight = (newWidth / originalWidth) * originalHeight;
// Create an offscreen canvas to resize the screenshot
const resizedCanvas = document.createElement("canvas");
resizedCanvas.width = newWidth;
resizedCanvas.height = newHeight;
const ctx = resizedCanvas.getContext("2d");
ctx.drawImage(canvas, 0, 0, newWidth, newHeight);
// Convert to WebP
resizedCanvas.toBlob(
(blob) => {
const reader = new FileReader();
reader.onloadend = function () {
const base64data = reader.result;
console.log("Screenshot captured:", base64data);
resolve(base64data); // Resolve the Promise with the base64 data
};
reader.readAsDataURL(blob);
},
"image/webp",
0.5 // quality, 0-1
);
})
.catch((error) => {
console.error("Screenshot capture failed:", error);
reject(error); // Reject the Promise with the error
});
});
}
return new Promise((resolve, reject) => {
const element = document.querySelector("#dAll");
const cardList = document.querySelector("#dCardList");
if (!element) {
console.error("Element #dAll not found");
reject("Element #dAll not found");
return;
}
html2canvas(element, {
ignoreElements: (el) => el === cardList, // Ignore #dCardList in the capture
})
.then((canvas) => {
// Get the original dimensions of the canvas
const originalWidth = canvas.width;
const originalHeight = canvas.height;
// Calculate the new height while maintaining the aspect ratio
const newWidth = 215;
const newHeight = (newWidth / originalWidth) * originalHeight;
// Create an offscreen canvas to resize the screenshot
const resizedCanvas = document.createElement("canvas");
resizedCanvas.width = newWidth;
resizedCanvas.height = newHeight;
const ctx = resizedCanvas.getContext("2d");
ctx.drawImage(canvas, 0, 0, newWidth, newHeight);
// Convert to WebP
resizedCanvas.toBlob(
(blob) => {
const reader = new FileReader();
reader.onloadend = function () {
const base64data = reader.result;
console.log("Screenshot captured:", base64data);
resolve(base64data); // Resolve the Promise with the base64 data
};
reader.readAsDataURL(blob);
},
"image/webp",
0.5 // quality, 0-1
);
})
.catch((error) => {
console.error("Screenshot capture failed:", error);
reject(error); // Reject the Promise with the error
});
});
}
9 changes: 6 additions & 3 deletions game/js/CPlants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5266,7 +5266,8 @@ BirthStyle: function (c, e, b, a) {
c.HP < 134
? c.HurtStatus < 2 &&
((c.HurtStatus = 2),
(d.src = "images/Plants/Garlic/Garlic_body3.webp"))
(d.src =
"images/Plants/Garlic/Garlic_body3.webp"))
: c.HP < 267 &&
c.HurtStatus < 1 &&
((c.HurtStatus = 1),
Expand Down Expand Up @@ -5329,7 +5330,8 @@ BirthStyle: function (c, e, b, a) {
c.HP < 134
? c.HurtStatus < 2 &&
((c.HurtStatus = 2),
(d.src = "images/Plants/Garlic/Garlic_body3.webp"))
(d.src =
"images/Plants/Garlic/Garlic_body3.webp"))
: c.HP < 267 &&
c.HurtStatus < 1 &&
((c.HurtStatus = 1),
Expand Down Expand Up @@ -8198,7 +8200,8 @@ oSeedSeaShroom = InheritO(oPuffShroom, {
50,
function (e) {
var d = $(e);
d && (d.childNodes[1].src = "images/Plants/Cactus/Cactus2.webp");
d &&
(d.childNodes[1].src = "images/Plants/Cactus/Cactus2.webp");
},
[a]
);
Expand Down
6 changes: 4 additions & 2 deletions game/js/CZombie.js
Original file line number Diff line number Diff line change
Expand Up @@ -7362,7 +7362,8 @@ var CZombies = (function (b, a) {
c.Altitude = 1;
c.OSpeed = c.Speed = 1.6;
c.getFreeze = OrnIZombies.prototype.getFreeze;
c.EleBody.src = "images/Zombies/BalloonZombie/Walk.webp";
c.EleBody.src =
"images/Zombies/BalloonZombie/Walk.webp";
c.ChkActs = OrnIZombies.prototype.ChkActs;
c.ExplosionDie = function () {
var d = this;
Expand Down Expand Up @@ -10691,7 +10692,8 @@ oCBucketheadZombie = InheritO(
a + "FlagZombieLostHeadAttack.webp",
"images/Zombies/Zombie/ZombieHead.webp" +
$Random,
"images/Zombies/Zombie/ZombieDie.webp" + $Random,
"images/Zombies/Zombie/ZombieDie.webp" +
$Random,
"images/Zombies/Zombie/BoomDie.webp" + $Random,
a + "1.webp",
];
Expand Down
36 changes: 24 additions & 12 deletions game/js/Cfunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -1652,9 +1652,11 @@ var $User = (function () {
GroundOnmousedown = function (i) {
i = window.event || i;
var a =
(i.clientX - EDAlloffsetLeft + EBody.scrollLeft ||
EElement.scrollLeft) * 10 / 9,
k = (i.clientY + EBody.scrollTop || EElement.scrollTop) * 10 / 9,
((i.clientX - EDAlloffsetLeft + EBody.scrollLeft ||
EElement.scrollLeft) *
10) /
9,
k = ((i.clientY + EBody.scrollTop || EElement.scrollTop) * 10) / 9,
g = ChosePlantX(a),
h = ChosePlantY(k),
d = g[0],
Expand Down Expand Up @@ -1726,9 +1728,11 @@ var $User = (function () {
GroundOnmousemove1 = function (j) {
j = window.event || j;
var d =
(j.clientX - EDAlloffsetLeft + EBody.scrollLeft ||
EElement.scrollLeft) * 10 / 9,
b = (j.clientY + EBody.scrollTop || EElement.scrollTop) * 10 / 9,
((j.clientX - EDAlloffsetLeft + EBody.scrollLeft ||
EElement.scrollLeft) *
10) /
9,
b = ((j.clientY + EBody.scrollTop || EElement.scrollTop) * 10) / 9,
k = oS.ChoseCard,
h = ChosePlantX(d),
i = ChosePlantY(b),
Expand All @@ -1739,8 +1743,8 @@ var $User = (function () {
m = GetAP(d, b, g, a);
var l = ArCard[k].PName.prototype;
SetStyle($("MovePlant"), {
left: (d - 0.5 * (l.beAttackedPointL + l.beAttackedPointR))+ "px",
top: (b + 20 - l.height) + "px",
left: d - 0.5 * (l.beAttackedPointL + l.beAttackedPointR) + "px",
top: b + 20 - l.height + "px",
});
l.CanGrow(m[0], g, a)
? SetStyle($("MovePlantAlpha"), {
Expand Down Expand Up @@ -1770,7 +1774,10 @@ var $User = (function () {
p != l &&
(p && SetAlpha($(p).childNodes[1], 100, 1),
(oS.MPID = l) && SetAlpha($(l).childNodes[1], 60, 0.6));
SetStyle($("tShovel"), { left: (d - 15) * 10 / 9 + "px", top: (b - 16) * 10 / 9 + "px" });
SetStyle($("tShovel"), {
left: ((d - 15) * 10) / 9 + "px",
top: ((b - 16) * 10) / 9 + "px",
});
},
DisplayZombie = function () {
SetVisible($("bShowHandBook"));
Expand Down Expand Up @@ -2056,8 +2063,13 @@ var $User = (function () {
var a = $("dTitle");
a.innerHTML = b;
SetStyle(a, {
left: c.clientX + (EBody.scrollLeft || EElement.scrollLeft) - 3 + "px",
top: c.clientY + 18 + (EBody.scrollTop || EElement.scrollTop) + "px",
left:
c.clientX +
(EBody.scrollLeft || EElement.scrollLeft) -
3 +
"px",
top:
c.clientY + 18 + (EBody.scrollTop || EElement.scrollTop) + "px",
visibility: "visible",
});
},
Expand Down Expand Up @@ -3742,4 +3754,4 @@ var $User = (function () {
f(r);
});

NewEle("dTitle", "div", 0, 0, $("dBody"));
NewEle("dTitle", "div", 0, 0, $("dBody"));
Loading

0 comments on commit 78ea6a2

Please sign in to comment.