Rename variables

This commit is contained in:
Idrees Hassan
2024-12-26 16:37:44 -05:00
parent 727f2a2dde
commit 2120e802ec

98
birb.js
View File

@@ -179,7 +179,7 @@ class Frame {
this.pixels = layers[0].pixels.map(row => row.slice()); this.pixels = layers[0].pixels.map(row => row.slice());
// Pad from top with transparent pixels // Pad from top with transparent pixels
while (this.pixels.length < maxHeight) { while (this.pixels.length < maxHeight) {
this.pixels.unshift(new Array(this.pixels[0].length).fill(___)); this.pixels.unshift(new Array(this.pixels[0].length).fill(TRANSPARENT));
} }
// Combine layers // Combine layers
for (let i = 1; i < layers.length; i++) { for (let i = 1; i < layers.length; i++) {
@@ -187,15 +187,15 @@ class Frame {
let topMargin = maxHeight - layerPixels.length; let topMargin = maxHeight - layerPixels.length;
for (let y = 0; y < layerPixels.length; y++) { for (let y = 0; y < layerPixels.length; y++) {
for (let x = 0; x < layerPixels[y].length; x++) { for (let x = 0; x < layerPixels[y].length; x++) {
this.pixels[y + topMargin][x] = layerPixels[y][x] !== ___ ? layerPixels[y][x] : this.pixels[y + topMargin][x]; this.pixels[y + topMargin][x] = layerPixels[y][x] !== TRANSPARENT ? layerPixels[y][x] : this.pixels[y + topMargin][x];
} }
} }
} }
// Surround non-transparent pixels with border // Surround non-transparent pixels with border
for (let y = 0; y < this.pixels.length; y++) { for (let y = 0; y < this.pixels.length; y++) {
for (let x = 0; x < this.pixels[y].length; x++) { for (let x = 0; x < this.pixels[y].length; x++) {
if (this.pixels[y][x] === ___ && this.hasAdjacent(x, y)) { if (this.pixels[y][x] === TRANSPARENT && this.hasAdjacent(x, y)) {
this.pixels[y][x] = BOR; this.pixels[y][x] = BORDER;
} }
} }
} }
@@ -207,7 +207,7 @@ class Frame {
if (i === 0 && j === 0) { if (i === 0 && j === 0) {
continue; continue;
} }
if (this.pixels[y + i] && this.pixels[y + i][x + j] && this.pixels[y + i][x + j] !== ___ && this.pixels[y + i][x + j] !== BOR) { if (this.pixels[y + i] && this.pixels[y + i][x + j] && this.pixels[y + i][x + j] !== TRANSPARENT && this.pixels[y + i][x + j] !== BORDER) {
return true; return true;
} }
} }
@@ -274,53 +274,53 @@ class Anim {
} }
} }
const ___ = "transparent"; const TRANSPARENT = "transparent";
const OUT = "outline"; const OUTLINE = "outline";
const BOR = "border"; const BORDER = "border";
const FOT = "foot"; const FOOT = "foot";
const BEK = "beak"; const BEAK = "beak";
const EYE = "eye"; const EYE = "eye";
const FAC = "face"; const FACE = "face";
const BEL = "belly"; const BELLY = "belly";
const UND = "underbelly"; const UNDERBELLY = "underbelly";
const WNG = "wing"; const WING = "wing";
const WNE = "wing-edge"; const WING_EDGE = "wing-edge";
const HRT = "heart"; const HEART = "heart";
const HRB = "heart-border"; const HEART_BORDER = "heart-border";
const HRS = "heart-shine"; const HEART_SHINE = "heart-shine";
const colorsToKeys = { const SPRITESHEET_COLOR_MAP = {
"transparent": ___, "transparent": TRANSPARENT,
"#ffffff": ___, "#ffffff": TRANSPARENT,
"#000000": OUT, "#000000": OUTLINE,
"#010a19": BEK, "#010a19": BEAK,
"#190301": EYE, "#190301": EYE,
"#af8e75": FOT, "#af8e75": FOOT,
"#639bff": FAC, "#639bff": FACE,
"#f8b143": BEL, "#f8b143": BELLY,
"#ec8637": UND, "#ec8637": UNDERBELLY,
"#578ae6": WNG, "#578ae6": WING,
"#326ed9": WNE, "#326ed9": WING_EDGE,
"#c82e2e": HRT, "#c82e2e": HEART,
"#501a1a": HRB, "#501a1a": HEART_BORDER,
"#ff6b6b": HRS "#ff6b6b": HEART_SHINE
}; };
const bluebirdColors = { const bluebirdColors = {
[___]: "transparent", [TRANSPARENT]: "transparent",
[OUT]: "#000000", [OUTLINE]: "#000000",
[BOR]: "#ffffff", [BORDER]: "#ffffff",
[BEK]: "#000000", [BEAK]: "#000000",
[FOT]: "#af8e75", [FOOT]: "#af8e75",
[EYE]: "#000000", [EYE]: "#000000",
[FAC]: "#639bff", [FACE]: "#639bff",
[BEL]: "#f8b143", [BELLY]: "#f8b143",
[UND]: "#ec8637", [UNDERBELLY]: "#ec8637",
[WNG]: "#578ae6", [WING]: "#578ae6",
[WNE]: "#326ed9", [WING_EDGE]: "#326ed9",
[HRT]: "#c82e2e", [HEART]: "#c82e2e",
[HRB]: "#501a1a", [HEART_BORDER]: "#501a1a",
[HRS]: "#ff6b6b", [HEART_SHINE]: "#ff6b6b",
}; };
const SPRITE_WIDTH = 32; const SPRITE_WIDTH = 32;
@@ -698,15 +698,15 @@ function dataUriTo2DArray(dataUri) {
const b = pixels[index + 2]; const b = pixels[index + 2];
const a = pixels[index + 3]; const a = pixels[index + 3];
if (a === 0) { if (a === 0) {
row.push(___); row.push(TRANSPARENT);
continue; continue;
} }
const hex = `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`; const hex = `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`;
if (colorsToKeys[hex] === undefined) { if (SPRITESHEET_COLOR_MAP[hex] === undefined) {
console.error(`Unknown color: ${hex}`); console.error(`Unknown color: ${hex}`);
row.push(___); row.push(TRANSPARENT);
} }
row.push(colorsToKeys[hex]); row.push(SPRITESHEET_COLOR_MAP[hex]);
} }
hexArray.push(row); hexArray.push(row);
} }