mirror of
https://github.com/NohamR/Pocket-Bird.git
synced 2026-05-25 04:07:23 +00:00
Add tag enum
This commit is contained in:
41
dist/extension/birb.js
vendored
41
dist/extension/birb.js
vendored
@@ -226,6 +226,22 @@
|
||||
return document.documentElement.clientHeight;
|
||||
}
|
||||
|
||||
const TAG = {
|
||||
DEFAULT: "default",
|
||||
TUFT: "tuft",
|
||||
};
|
||||
|
||||
class Layer {
|
||||
/**
|
||||
* @param {string[][]} pixels
|
||||
* @param {string} [tag]
|
||||
*/
|
||||
constructor(pixels, tag = TAG.DEFAULT) {
|
||||
this.pixels = pixels;
|
||||
this.tag = tag;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Palette color names
|
||||
* @type {Record<string, string>}
|
||||
@@ -333,7 +349,7 @@
|
||||
[PALETTE.UNDERBELLY]: "#d7cfcb",
|
||||
[PALETTE.WING]: "#b1b5c5",
|
||||
[PALETTE.WING_EDGE]: "#9d9fa9",
|
||||
}, ["tuft"]),
|
||||
}, [TAG.TUFT]),
|
||||
europeanRobin: new BirdType("European Robin",
|
||||
"Native to western Europe, this is the quintessential robin. Quite friendly, you'll often find them searching for worms.", {
|
||||
[PALETTE.FOOT]: "#af8e75",
|
||||
@@ -355,7 +371,7 @@
|
||||
[PALETTE.UNDERBELLY]: "#dc3719",
|
||||
[PALETTE.WING]: "#d23215",
|
||||
[PALETTE.WING_EDGE]: "#b1321c",
|
||||
}, ["tuft"]),
|
||||
}, [TAG.TUFT]),
|
||||
americanGoldfinch: new BirdType("American Goldfinch",
|
||||
"Coloured a brilliant yellow, this bird feeds almost entirely on the seeds of plants such as thistle, sunflowers, and coneflowers.", {
|
||||
[PALETTE.BEAK]: "#ffaf34",
|
||||
@@ -432,17 +448,6 @@
|
||||
}),
|
||||
};
|
||||
|
||||
class Layer {
|
||||
/**
|
||||
* @param {string[][]} pixels
|
||||
* @param {string} [tag]
|
||||
*/
|
||||
constructor(pixels, tag = "default") {
|
||||
this.pixels = pixels;
|
||||
this.tag = tag;
|
||||
}
|
||||
}
|
||||
|
||||
class Frame {
|
||||
|
||||
/** @type {{ [tag: string]: string[][] }} */
|
||||
@@ -457,10 +462,10 @@
|
||||
for (let layer of layers) {
|
||||
tags.add(layer.tag);
|
||||
}
|
||||
tags.add("default");
|
||||
tags.add(TAG.DEFAULT);
|
||||
for (let tag of tags) {
|
||||
let maxHeight = layers.reduce((max, layer) => Math.max(max, layer.pixels.length), 0);
|
||||
if (layers[0].tag !== "default") {
|
||||
if (layers[0].tag !== TAG.DEFAULT) {
|
||||
throw new Error("First layer must have the 'default' tag");
|
||||
}
|
||||
this.pixels = layers[0].pixels.map(row => row.slice());
|
||||
@@ -470,7 +475,7 @@
|
||||
}
|
||||
// Combine layers
|
||||
for (let i = 1; i < layers.length; i++) {
|
||||
if (layers[i].tag === "default" || layers[i].tag === tag) {
|
||||
if (layers[i].tag === TAG.DEFAULT || layers[i].tag === tag) {
|
||||
let layerPixels = layers[i].pixels;
|
||||
let topMargin = maxHeight - layerPixels.length;
|
||||
for (let y = 0; y < layerPixels.length; y++) {
|
||||
@@ -488,8 +493,8 @@
|
||||
* @param {string} [tag]
|
||||
* @returns {string[][]}
|
||||
*/
|
||||
getPixels(tag = "default") {
|
||||
return this.#pixelsByTag[tag] ?? this.#pixelsByTag["default"];
|
||||
getPixels(tag = TAG.DEFAULT) {
|
||||
return this.#pixelsByTag[tag] ?? this.#pixelsByTag[TAG.DEFAULT];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user