UNPKG

@nmmty/lazycanvas

Version:

A simple way to interact with @napi-rs/canvas in an advanced way!

100 lines (99 loc) 3.36 kB
"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 {Object} [opts] - Optional settings for the animation manager. * @param {boolean} [opts.debug] - Whether debugging is enabled. * @param {Object} [opts.settings] - Additional settings for the animation manager. * @param {IAnimationOptions} [opts.settings.options] - 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 {number} [frameRate] - 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 {boolean} [loop] - 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 {boolean} [transparency] - 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 {ColorSpace} [rgb] - 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 {number} [maxColors] - 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 {boolean} [clear] - Whether to clear the content of previous frames (default is true). * @param {number} [bufferSize] - 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;