mirror of
https://github.com/NohamR/Pocket-Bird.git
synced 2026-05-25 19:59:38 +00:00
Control hat type from application
This commit is contained in:
@@ -59,10 +59,11 @@ class Anim {
|
||||
* @param {number} direction
|
||||
* @param {number} timeStart The start time of the animation in milliseconds
|
||||
* @param {number} canvasPixelSize The size of a canvas pixel in pixels
|
||||
* @param {BirdType} [species] The species to use for the animation
|
||||
* @param {{ [key: string]: string }} colorScheme The color scheme to use for the animation
|
||||
* @param {string[]} tags The tags to use for the animation
|
||||
* @returns {boolean} Whether the animation is complete
|
||||
*/
|
||||
draw(ctx, direction, timeStart, canvasPixelSize, species) {
|
||||
draw(ctx, direction, timeStart, canvasPixelSize, colorScheme, tags) {
|
||||
// Reset cache if animation was restarted
|
||||
if (this.lastTimeStart !== timeStart) {
|
||||
this.#clearCache();
|
||||
@@ -79,7 +80,7 @@ class Anim {
|
||||
const currentFrameIndex = this.getCurrentFrameIndex(time);
|
||||
|
||||
if (this.#shouldRedraw(currentFrameIndex, direction)) {
|
||||
this.frames[currentFrameIndex].draw(ctx, direction, canvasPixelSize, species);
|
||||
this.frames[currentFrameIndex].draw(ctx, direction, canvasPixelSize, colorScheme, tags);
|
||||
this.lastFrameIndex = currentFrameIndex;
|
||||
this.lastDirection = direction;
|
||||
}
|
||||
|
||||
@@ -53,20 +53,21 @@ class Frame {
|
||||
|
||||
/**
|
||||
* @param {CanvasRenderingContext2D} ctx
|
||||
* @param {BirdType} [species]
|
||||
* @param {number} direction
|
||||
* @param {number} direction
|
||||
* @param {number} canvasPixelSize
|
||||
* @param {{ [key: string]: string }} colorScheme
|
||||
* @param {string[]} tags
|
||||
*/
|
||||
draw(ctx, direction, canvasPixelSize, species) {
|
||||
draw(ctx, direction, canvasPixelSize, colorScheme, tags) {
|
||||
// Clear the canvas before drawing the new frame
|
||||
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||
|
||||
const pixels = this.getPixels(species?.tags[0]);
|
||||
const pixels = this.getPixels(tags[0]);
|
||||
for (let y = 0; y < pixels.length; y++) {
|
||||
const row = pixels[y];
|
||||
for (let x = 0; x < pixels[y].length; x++) {
|
||||
const cell = direction === Directions.LEFT ? row[x] : row[pixels[y].length - x - 1];
|
||||
ctx.fillStyle = species?.colors[cell] ?? cell;
|
||||
ctx.fillStyle = colorScheme[cell] ?? cell;
|
||||
ctx.fillRect(x * canvasPixelSize, y * canvasPixelSize, canvasPixelSize, canvasPixelSize);
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user