mirror of
https://github.com/NohamR/Pocket-Bird.git
synced 2026-05-24 19:59:36 +00:00
Add tag enum
This commit is contained in:
BIN
dist/extension.zip
vendored
BIN
dist/extension.zip
vendored
Binary file not shown.
41
dist/extension/birb.js
vendored
41
dist/extension/birb.js
vendored
@@ -226,6 +226,22 @@
|
|||||||
return document.documentElement.clientHeight;
|
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
|
* Palette color names
|
||||||
* @type {Record<string, string>}
|
* @type {Record<string, string>}
|
||||||
@@ -333,7 +349,7 @@
|
|||||||
[PALETTE.UNDERBELLY]: "#d7cfcb",
|
[PALETTE.UNDERBELLY]: "#d7cfcb",
|
||||||
[PALETTE.WING]: "#b1b5c5",
|
[PALETTE.WING]: "#b1b5c5",
|
||||||
[PALETTE.WING_EDGE]: "#9d9fa9",
|
[PALETTE.WING_EDGE]: "#9d9fa9",
|
||||||
}, ["tuft"]),
|
}, [TAG.TUFT]),
|
||||||
europeanRobin: new BirdType("European Robin",
|
europeanRobin: new BirdType("European Robin",
|
||||||
"Native to western Europe, this is the quintessential robin. Quite friendly, you'll often find them searching for worms.", {
|
"Native to western Europe, this is the quintessential robin. Quite friendly, you'll often find them searching for worms.", {
|
||||||
[PALETTE.FOOT]: "#af8e75",
|
[PALETTE.FOOT]: "#af8e75",
|
||||||
@@ -355,7 +371,7 @@
|
|||||||
[PALETTE.UNDERBELLY]: "#dc3719",
|
[PALETTE.UNDERBELLY]: "#dc3719",
|
||||||
[PALETTE.WING]: "#d23215",
|
[PALETTE.WING]: "#d23215",
|
||||||
[PALETTE.WING_EDGE]: "#b1321c",
|
[PALETTE.WING_EDGE]: "#b1321c",
|
||||||
}, ["tuft"]),
|
}, [TAG.TUFT]),
|
||||||
americanGoldfinch: new BirdType("American Goldfinch",
|
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.", {
|
"Coloured a brilliant yellow, this bird feeds almost entirely on the seeds of plants such as thistle, sunflowers, and coneflowers.", {
|
||||||
[PALETTE.BEAK]: "#ffaf34",
|
[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 {
|
class Frame {
|
||||||
|
|
||||||
/** @type {{ [tag: string]: string[][] }} */
|
/** @type {{ [tag: string]: string[][] }} */
|
||||||
@@ -457,10 +462,10 @@
|
|||||||
for (let layer of layers) {
|
for (let layer of layers) {
|
||||||
tags.add(layer.tag);
|
tags.add(layer.tag);
|
||||||
}
|
}
|
||||||
tags.add("default");
|
tags.add(TAG.DEFAULT);
|
||||||
for (let tag of tags) {
|
for (let tag of tags) {
|
||||||
let maxHeight = layers.reduce((max, layer) => Math.max(max, layer.pixels.length), 0);
|
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");
|
throw new Error("First layer must have the 'default' tag");
|
||||||
}
|
}
|
||||||
this.pixels = layers[0].pixels.map(row => row.slice());
|
this.pixels = layers[0].pixels.map(row => row.slice());
|
||||||
@@ -470,7 +475,7 @@
|
|||||||
}
|
}
|
||||||
// Combine layers
|
// Combine layers
|
||||||
for (let i = 1; i < layers.length; i++) {
|
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 layerPixels = layers[i].pixels;
|
||||||
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++) {
|
||||||
@@ -488,8 +493,8 @@
|
|||||||
* @param {string} [tag]
|
* @param {string} [tag]
|
||||||
* @returns {string[][]}
|
* @returns {string[][]}
|
||||||
*/
|
*/
|
||||||
getPixels(tag = "default") {
|
getPixels(tag = TAG.DEFAULT) {
|
||||||
return this.#pixelsByTag[tag] ?? this.#pixelsByTag["default"];
|
return this.#pixelsByTag[tag] ?? this.#pixelsByTag[TAG.DEFAULT];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
41
dist/obsidian/main.js
vendored
41
dist/obsidian/main.js
vendored
@@ -231,6 +231,22 @@ module.exports = class PocketBird extends Plugin {
|
|||||||
return document.documentElement.clientHeight;
|
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
|
* Palette color names
|
||||||
* @type {Record<string, string>}
|
* @type {Record<string, string>}
|
||||||
@@ -338,7 +354,7 @@ module.exports = class PocketBird extends Plugin {
|
|||||||
[PALETTE.UNDERBELLY]: "#d7cfcb",
|
[PALETTE.UNDERBELLY]: "#d7cfcb",
|
||||||
[PALETTE.WING]: "#b1b5c5",
|
[PALETTE.WING]: "#b1b5c5",
|
||||||
[PALETTE.WING_EDGE]: "#9d9fa9",
|
[PALETTE.WING_EDGE]: "#9d9fa9",
|
||||||
}, ["tuft"]),
|
}, [TAG.TUFT]),
|
||||||
europeanRobin: new BirdType("European Robin",
|
europeanRobin: new BirdType("European Robin",
|
||||||
"Native to western Europe, this is the quintessential robin. Quite friendly, you'll often find them searching for worms.", {
|
"Native to western Europe, this is the quintessential robin. Quite friendly, you'll often find them searching for worms.", {
|
||||||
[PALETTE.FOOT]: "#af8e75",
|
[PALETTE.FOOT]: "#af8e75",
|
||||||
@@ -360,7 +376,7 @@ module.exports = class PocketBird extends Plugin {
|
|||||||
[PALETTE.UNDERBELLY]: "#dc3719",
|
[PALETTE.UNDERBELLY]: "#dc3719",
|
||||||
[PALETTE.WING]: "#d23215",
|
[PALETTE.WING]: "#d23215",
|
||||||
[PALETTE.WING_EDGE]: "#b1321c",
|
[PALETTE.WING_EDGE]: "#b1321c",
|
||||||
}, ["tuft"]),
|
}, [TAG.TUFT]),
|
||||||
americanGoldfinch: new BirdType("American Goldfinch",
|
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.", {
|
"Coloured a brilliant yellow, this bird feeds almost entirely on the seeds of plants such as thistle, sunflowers, and coneflowers.", {
|
||||||
[PALETTE.BEAK]: "#ffaf34",
|
[PALETTE.BEAK]: "#ffaf34",
|
||||||
@@ -437,17 +453,6 @@ module.exports = class PocketBird extends Plugin {
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
class Layer {
|
|
||||||
/**
|
|
||||||
* @param {string[][]} pixels
|
|
||||||
* @param {string} [tag]
|
|
||||||
*/
|
|
||||||
constructor(pixels, tag = "default") {
|
|
||||||
this.pixels = pixels;
|
|
||||||
this.tag = tag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Frame {
|
class Frame {
|
||||||
|
|
||||||
/** @type {{ [tag: string]: string[][] }} */
|
/** @type {{ [tag: string]: string[][] }} */
|
||||||
@@ -462,10 +467,10 @@ module.exports = class PocketBird extends Plugin {
|
|||||||
for (let layer of layers) {
|
for (let layer of layers) {
|
||||||
tags.add(layer.tag);
|
tags.add(layer.tag);
|
||||||
}
|
}
|
||||||
tags.add("default");
|
tags.add(TAG.DEFAULT);
|
||||||
for (let tag of tags) {
|
for (let tag of tags) {
|
||||||
let maxHeight = layers.reduce((max, layer) => Math.max(max, layer.pixels.length), 0);
|
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");
|
throw new Error("First layer must have the 'default' tag");
|
||||||
}
|
}
|
||||||
this.pixels = layers[0].pixels.map(row => row.slice());
|
this.pixels = layers[0].pixels.map(row => row.slice());
|
||||||
@@ -475,7 +480,7 @@ module.exports = class PocketBird extends Plugin {
|
|||||||
}
|
}
|
||||||
// Combine layers
|
// Combine layers
|
||||||
for (let i = 1; i < layers.length; i++) {
|
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 layerPixels = layers[i].pixels;
|
||||||
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++) {
|
||||||
@@ -493,8 +498,8 @@ module.exports = class PocketBird extends Plugin {
|
|||||||
* @param {string} [tag]
|
* @param {string} [tag]
|
||||||
* @returns {string[][]}
|
* @returns {string[][]}
|
||||||
*/
|
*/
|
||||||
getPixels(tag = "default") {
|
getPixels(tag = TAG.DEFAULT) {
|
||||||
return this.#pixelsByTag[tag] ?? this.#pixelsByTag["default"];
|
return this.#pixelsByTag[tag] ?? this.#pixelsByTag[TAG.DEFAULT];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
41
dist/userscript/birb.user.js
vendored
41
dist/userscript/birb.user.js
vendored
@@ -240,6 +240,22 @@
|
|||||||
return document.documentElement.clientHeight;
|
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
|
* Palette color names
|
||||||
* @type {Record<string, string>}
|
* @type {Record<string, string>}
|
||||||
@@ -347,7 +363,7 @@
|
|||||||
[PALETTE.UNDERBELLY]: "#d7cfcb",
|
[PALETTE.UNDERBELLY]: "#d7cfcb",
|
||||||
[PALETTE.WING]: "#b1b5c5",
|
[PALETTE.WING]: "#b1b5c5",
|
||||||
[PALETTE.WING_EDGE]: "#9d9fa9",
|
[PALETTE.WING_EDGE]: "#9d9fa9",
|
||||||
}, ["tuft"]),
|
}, [TAG.TUFT]),
|
||||||
europeanRobin: new BirdType("European Robin",
|
europeanRobin: new BirdType("European Robin",
|
||||||
"Native to western Europe, this is the quintessential robin. Quite friendly, you'll often find them searching for worms.", {
|
"Native to western Europe, this is the quintessential robin. Quite friendly, you'll often find them searching for worms.", {
|
||||||
[PALETTE.FOOT]: "#af8e75",
|
[PALETTE.FOOT]: "#af8e75",
|
||||||
@@ -369,7 +385,7 @@
|
|||||||
[PALETTE.UNDERBELLY]: "#dc3719",
|
[PALETTE.UNDERBELLY]: "#dc3719",
|
||||||
[PALETTE.WING]: "#d23215",
|
[PALETTE.WING]: "#d23215",
|
||||||
[PALETTE.WING_EDGE]: "#b1321c",
|
[PALETTE.WING_EDGE]: "#b1321c",
|
||||||
}, ["tuft"]),
|
}, [TAG.TUFT]),
|
||||||
americanGoldfinch: new BirdType("American Goldfinch",
|
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.", {
|
"Coloured a brilliant yellow, this bird feeds almost entirely on the seeds of plants such as thistle, sunflowers, and coneflowers.", {
|
||||||
[PALETTE.BEAK]: "#ffaf34",
|
[PALETTE.BEAK]: "#ffaf34",
|
||||||
@@ -446,17 +462,6 @@
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
class Layer {
|
|
||||||
/**
|
|
||||||
* @param {string[][]} pixels
|
|
||||||
* @param {string} [tag]
|
|
||||||
*/
|
|
||||||
constructor(pixels, tag = "default") {
|
|
||||||
this.pixels = pixels;
|
|
||||||
this.tag = tag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Frame {
|
class Frame {
|
||||||
|
|
||||||
/** @type {{ [tag: string]: string[][] }} */
|
/** @type {{ [tag: string]: string[][] }} */
|
||||||
@@ -471,10 +476,10 @@
|
|||||||
for (let layer of layers) {
|
for (let layer of layers) {
|
||||||
tags.add(layer.tag);
|
tags.add(layer.tag);
|
||||||
}
|
}
|
||||||
tags.add("default");
|
tags.add(TAG.DEFAULT);
|
||||||
for (let tag of tags) {
|
for (let tag of tags) {
|
||||||
let maxHeight = layers.reduce((max, layer) => Math.max(max, layer.pixels.length), 0);
|
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");
|
throw new Error("First layer must have the 'default' tag");
|
||||||
}
|
}
|
||||||
this.pixels = layers[0].pixels.map(row => row.slice());
|
this.pixels = layers[0].pixels.map(row => row.slice());
|
||||||
@@ -484,7 +489,7 @@
|
|||||||
}
|
}
|
||||||
// Combine layers
|
// Combine layers
|
||||||
for (let i = 1; i < layers.length; i++) {
|
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 layerPixels = layers[i].pixels;
|
||||||
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++) {
|
||||||
@@ -502,8 +507,8 @@
|
|||||||
* @param {string} [tag]
|
* @param {string} [tag]
|
||||||
* @returns {string[][]}
|
* @returns {string[][]}
|
||||||
*/
|
*/
|
||||||
getPixels(tag = "default") {
|
getPixels(tag = TAG.DEFAULT) {
|
||||||
return this.#pixelsByTag[tag] ?? this.#pixelsByTag["default"];
|
return this.#pixelsByTag[tag] ?? this.#pixelsByTag[TAG.DEFAULT];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
41
dist/web/birb.embed.js
vendored
41
dist/web/birb.embed.js
vendored
@@ -226,6 +226,22 @@
|
|||||||
return document.documentElement.clientHeight;
|
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
|
* Palette color names
|
||||||
* @type {Record<string, string>}
|
* @type {Record<string, string>}
|
||||||
@@ -333,7 +349,7 @@
|
|||||||
[PALETTE.UNDERBELLY]: "#d7cfcb",
|
[PALETTE.UNDERBELLY]: "#d7cfcb",
|
||||||
[PALETTE.WING]: "#b1b5c5",
|
[PALETTE.WING]: "#b1b5c5",
|
||||||
[PALETTE.WING_EDGE]: "#9d9fa9",
|
[PALETTE.WING_EDGE]: "#9d9fa9",
|
||||||
}, ["tuft"]),
|
}, [TAG.TUFT]),
|
||||||
europeanRobin: new BirdType("European Robin",
|
europeanRobin: new BirdType("European Robin",
|
||||||
"Native to western Europe, this is the quintessential robin. Quite friendly, you'll often find them searching for worms.", {
|
"Native to western Europe, this is the quintessential robin. Quite friendly, you'll often find them searching for worms.", {
|
||||||
[PALETTE.FOOT]: "#af8e75",
|
[PALETTE.FOOT]: "#af8e75",
|
||||||
@@ -355,7 +371,7 @@
|
|||||||
[PALETTE.UNDERBELLY]: "#dc3719",
|
[PALETTE.UNDERBELLY]: "#dc3719",
|
||||||
[PALETTE.WING]: "#d23215",
|
[PALETTE.WING]: "#d23215",
|
||||||
[PALETTE.WING_EDGE]: "#b1321c",
|
[PALETTE.WING_EDGE]: "#b1321c",
|
||||||
}, ["tuft"]),
|
}, [TAG.TUFT]),
|
||||||
americanGoldfinch: new BirdType("American Goldfinch",
|
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.", {
|
"Coloured a brilliant yellow, this bird feeds almost entirely on the seeds of plants such as thistle, sunflowers, and coneflowers.", {
|
||||||
[PALETTE.BEAK]: "#ffaf34",
|
[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 {
|
class Frame {
|
||||||
|
|
||||||
/** @type {{ [tag: string]: string[][] }} */
|
/** @type {{ [tag: string]: string[][] }} */
|
||||||
@@ -457,10 +462,10 @@
|
|||||||
for (let layer of layers) {
|
for (let layer of layers) {
|
||||||
tags.add(layer.tag);
|
tags.add(layer.tag);
|
||||||
}
|
}
|
||||||
tags.add("default");
|
tags.add(TAG.DEFAULT);
|
||||||
for (let tag of tags) {
|
for (let tag of tags) {
|
||||||
let maxHeight = layers.reduce((max, layer) => Math.max(max, layer.pixels.length), 0);
|
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");
|
throw new Error("First layer must have the 'default' tag");
|
||||||
}
|
}
|
||||||
this.pixels = layers[0].pixels.map(row => row.slice());
|
this.pixels = layers[0].pixels.map(row => row.slice());
|
||||||
@@ -470,7 +475,7 @@
|
|||||||
}
|
}
|
||||||
// Combine layers
|
// Combine layers
|
||||||
for (let i = 1; i < layers.length; i++) {
|
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 layerPixels = layers[i].pixels;
|
||||||
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++) {
|
||||||
@@ -488,8 +493,8 @@
|
|||||||
* @param {string} [tag]
|
* @param {string} [tag]
|
||||||
* @returns {string[][]}
|
* @returns {string[][]}
|
||||||
*/
|
*/
|
||||||
getPixels(tag = "default") {
|
getPixels(tag = TAG.DEFAULT) {
|
||||||
return this.#pixelsByTag[tag] ?? this.#pixelsByTag["default"];
|
return this.#pixelsByTag[tag] ?? this.#pixelsByTag[TAG.DEFAULT];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
41
dist/web/birb.js
vendored
41
dist/web/birb.js
vendored
@@ -226,6 +226,22 @@
|
|||||||
return document.documentElement.clientHeight;
|
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
|
* Palette color names
|
||||||
* @type {Record<string, string>}
|
* @type {Record<string, string>}
|
||||||
@@ -333,7 +349,7 @@
|
|||||||
[PALETTE.UNDERBELLY]: "#d7cfcb",
|
[PALETTE.UNDERBELLY]: "#d7cfcb",
|
||||||
[PALETTE.WING]: "#b1b5c5",
|
[PALETTE.WING]: "#b1b5c5",
|
||||||
[PALETTE.WING_EDGE]: "#9d9fa9",
|
[PALETTE.WING_EDGE]: "#9d9fa9",
|
||||||
}, ["tuft"]),
|
}, [TAG.TUFT]),
|
||||||
europeanRobin: new BirdType("European Robin",
|
europeanRobin: new BirdType("European Robin",
|
||||||
"Native to western Europe, this is the quintessential robin. Quite friendly, you'll often find them searching for worms.", {
|
"Native to western Europe, this is the quintessential robin. Quite friendly, you'll often find them searching for worms.", {
|
||||||
[PALETTE.FOOT]: "#af8e75",
|
[PALETTE.FOOT]: "#af8e75",
|
||||||
@@ -355,7 +371,7 @@
|
|||||||
[PALETTE.UNDERBELLY]: "#dc3719",
|
[PALETTE.UNDERBELLY]: "#dc3719",
|
||||||
[PALETTE.WING]: "#d23215",
|
[PALETTE.WING]: "#d23215",
|
||||||
[PALETTE.WING_EDGE]: "#b1321c",
|
[PALETTE.WING_EDGE]: "#b1321c",
|
||||||
}, ["tuft"]),
|
}, [TAG.TUFT]),
|
||||||
americanGoldfinch: new BirdType("American Goldfinch",
|
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.", {
|
"Coloured a brilliant yellow, this bird feeds almost entirely on the seeds of plants such as thistle, sunflowers, and coneflowers.", {
|
||||||
[PALETTE.BEAK]: "#ffaf34",
|
[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 {
|
class Frame {
|
||||||
|
|
||||||
/** @type {{ [tag: string]: string[][] }} */
|
/** @type {{ [tag: string]: string[][] }} */
|
||||||
@@ -457,10 +462,10 @@
|
|||||||
for (let layer of layers) {
|
for (let layer of layers) {
|
||||||
tags.add(layer.tag);
|
tags.add(layer.tag);
|
||||||
}
|
}
|
||||||
tags.add("default");
|
tags.add(TAG.DEFAULT);
|
||||||
for (let tag of tags) {
|
for (let tag of tags) {
|
||||||
let maxHeight = layers.reduce((max, layer) => Math.max(max, layer.pixels.length), 0);
|
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");
|
throw new Error("First layer must have the 'default' tag");
|
||||||
}
|
}
|
||||||
this.pixels = layers[0].pixels.map(row => row.slice());
|
this.pixels = layers[0].pixels.map(row => row.slice());
|
||||||
@@ -470,7 +475,7 @@
|
|||||||
}
|
}
|
||||||
// Combine layers
|
// Combine layers
|
||||||
for (let i = 1; i < layers.length; i++) {
|
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 layerPixels = layers[i].pixels;
|
||||||
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++) {
|
||||||
@@ -488,8 +493,8 @@
|
|||||||
* @param {string} [tag]
|
* @param {string} [tag]
|
||||||
* @returns {string[][]}
|
* @returns {string[][]}
|
||||||
*/
|
*/
|
||||||
getPixels(tag = "default") {
|
getPixels(tag = TAG.DEFAULT) {
|
||||||
return this.#pixelsByTag[tag] ?? this.#pixelsByTag["default"];
|
return this.#pixelsByTag[tag] ?? this.#pixelsByTag[TAG.DEFAULT];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Directions } from '../shared.js';
|
import { Directions } from '../shared.js';
|
||||||
import { PALETTE, BirdType } from './sprites.js';
|
import { PALETTE, BirdType } from './sprites.js';
|
||||||
import Layer from './layer.js';
|
import Layer, { TAG } from './layer.js';
|
||||||
|
|
||||||
class Frame {
|
class Frame {
|
||||||
|
|
||||||
@@ -16,10 +16,10 @@ class Frame {
|
|||||||
for (let layer of layers) {
|
for (let layer of layers) {
|
||||||
tags.add(layer.tag);
|
tags.add(layer.tag);
|
||||||
}
|
}
|
||||||
tags.add("default");
|
tags.add(TAG.DEFAULT);
|
||||||
for (let tag of tags) {
|
for (let tag of tags) {
|
||||||
let maxHeight = layers.reduce((max, layer) => Math.max(max, layer.pixels.length), 0);
|
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");
|
throw new Error("First layer must have the 'default' tag");
|
||||||
}
|
}
|
||||||
this.pixels = layers[0].pixels.map(row => row.slice());
|
this.pixels = layers[0].pixels.map(row => row.slice());
|
||||||
@@ -29,7 +29,7 @@ class Frame {
|
|||||||
}
|
}
|
||||||
// Combine layers
|
// Combine layers
|
||||||
for (let i = 1; i < layers.length; i++) {
|
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 layerPixels = layers[i].pixels;
|
||||||
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++) {
|
||||||
@@ -47,8 +47,8 @@ class Frame {
|
|||||||
* @param {string} [tag]
|
* @param {string} [tag]
|
||||||
* @returns {string[][]}
|
* @returns {string[][]}
|
||||||
*/
|
*/
|
||||||
getPixels(tag = "default") {
|
getPixels(tag = TAG.DEFAULT) {
|
||||||
return this.#pixelsByTag[tag] ?? this.#pixelsByTag["default"];
|
return this.#pixelsByTag[tag] ?? this.#pixelsByTag[TAG.DEFAULT];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
|
export const TAG = {
|
||||||
|
DEFAULT: "default",
|
||||||
|
TUFT: "tuft",
|
||||||
|
};
|
||||||
|
|
||||||
class Layer {
|
class Layer {
|
||||||
/**
|
/**
|
||||||
* @param {string[][]} pixels
|
* @param {string[][]} pixels
|
||||||
* @param {string} [tag]
|
* @param {string} [tag]
|
||||||
*/
|
*/
|
||||||
constructor(pixels, tag = "default") {
|
constructor(pixels, tag = TAG.DEFAULT) {
|
||||||
this.pixels = pixels;
|
this.pixels = pixels;
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { TAG } from "./layer.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Palette color names
|
* Palette color names
|
||||||
* @type {Record<string, string>}
|
* @type {Record<string, string>}
|
||||||
@@ -105,7 +107,7 @@ export const SPECIES = {
|
|||||||
[PALETTE.UNDERBELLY]: "#d7cfcb",
|
[PALETTE.UNDERBELLY]: "#d7cfcb",
|
||||||
[PALETTE.WING]: "#b1b5c5",
|
[PALETTE.WING]: "#b1b5c5",
|
||||||
[PALETTE.WING_EDGE]: "#9d9fa9",
|
[PALETTE.WING_EDGE]: "#9d9fa9",
|
||||||
}, ["tuft"]),
|
}, [TAG.TUFT]),
|
||||||
europeanRobin: new BirdType("European Robin",
|
europeanRobin: new BirdType("European Robin",
|
||||||
"Native to western Europe, this is the quintessential robin. Quite friendly, you'll often find them searching for worms.", {
|
"Native to western Europe, this is the quintessential robin. Quite friendly, you'll often find them searching for worms.", {
|
||||||
[PALETTE.FOOT]: "#af8e75",
|
[PALETTE.FOOT]: "#af8e75",
|
||||||
@@ -127,7 +129,7 @@ export const SPECIES = {
|
|||||||
[PALETTE.UNDERBELLY]: "#dc3719",
|
[PALETTE.UNDERBELLY]: "#dc3719",
|
||||||
[PALETTE.WING]: "#d23215",
|
[PALETTE.WING]: "#d23215",
|
||||||
[PALETTE.WING_EDGE]: "#b1321c",
|
[PALETTE.WING_EDGE]: "#b1321c",
|
||||||
}, ["tuft"]),
|
}, [TAG.TUFT]),
|
||||||
americanGoldfinch: new BirdType("American Goldfinch",
|
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.", {
|
"Coloured a brilliant yellow, this bird feeds almost entirely on the seeds of plants such as thistle, sunflowers, and coneflowers.", {
|
||||||
[PALETTE.BEAK]: "#ffaf34",
|
[PALETTE.BEAK]: "#ffaf34",
|
||||||
|
|||||||
Reference in New Issue
Block a user