@nmmty/lazycanvas
Version:
A simple way to interact with @napi-rs/canvas in an advanced way!
100 lines (99 loc) • 3.34 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AnimationManager = void 0;
const types_1 = require("../../types");
/**
* Class representing the animation manager, which handles animation settings and options.
*/
class AnimationManager {
/**
* The options for the animation manager.
*/
options;
/**
* Whether debugging is enabled.
*/
debug;
/**
* Constructs a new AnimationManager instance.
* @param opts {Object} - Optional settings for the animation manager.
* @param opts.debug {boolean} - Whether debugging is enabled.
* @param opts.settings {Object} - Additional settings for the animation manager.
* @param opts.settings.options {IAnimationOptions} - The animation options.
*/
constructor(opts) {
this.options = opts?.settings?.options || {
frameRate: 30,
maxColors: 256,
colorSpace: types_1.ColorSpace.RGB565,
loop: true,
transparency: true,
utils: {
clear: true,
buffer: {
size: 0
}
}
};
this.debug = opts?.debug || false;
}
/**
* Sets the frame rate of the animation.
* @param frameRate {number} - The frame rate of the animation (default is 30).
* @returns {this} The current instance for chaining.
*/
setFrameRate(frameRate) {
this.options.frameRate = frameRate;
return this;
}
/**
* Sets whether the animation should loop.
* @param loop {boolean} - Whether the animation should loop (default is true).
* @returns {this} The current instance for chaining.
*/
setLoop(loop) {
this.options.loop = loop;
return this;
}
/**
* Sets whether the animation should have transparency.
* @param transparency {boolean} - Whether the animation should have transparency (default is true).
* @returns {this} The current instance for chaining.
*/
setTransparent(transparency) {
this.options.transparency = transparency;
return this;
}
/**
* Sets the RGB format of the animation.
* @param rgb {ColorSpace} - The RGB format of the animation (default is RGB565).
* @returns {this} The current instance for chaining.
*/
setRGBFormat(rgb) {
this.options.colorSpace = rgb;
return this;
}
/**
* Sets the maximum number of colors in the animation.
* @param maxColors {number} - The maximum number of colors (default is 256).
* @returns {this} The current instance for chaining.
*/
setMaxColors(maxColors) {
this.options.maxColors = maxColors;
return this;
}
/**
* Sets whether the content of previous frames will be cleared.
* @param clear {boolean} - Whether to clear the content of previous frames (default is true).
* @param bufferSize {number} - The size of the frame buffer (default is 0).
* @returns {this} The current instance for chaining.
*/
setClear(clear, bufferSize) {
this.options.utils.clear = clear;
if (bufferSize) {
this.options.utils.buffer.size = bufferSize;
}
return this;
}
}
exports.AnimationManager = AnimationManager;