UNPKG

duckengine

Version:
124 lines (123 loc) 4.31 kB
import { Duck } from '../..'; import Vector2 from '../math/vector2'; export default class TextureBase<type extends Duck.Types.Texture.Type> { /** * @memberof TextureBase * @description The unique identifier for the texture * @type string * @since 2.1.0 */ readonly id: string; /** * @memberof TextureBase * @description The type of texture source, 'image' | 'color' | 'either' * @type Duck.Types.Texture.Type * @since 2.1.0 */ readonly type: Duck.Types.Texture.Type; /** * @memberof TextureBase * @description The data type of texture, 'sheet' | 'base' | 'atlas' | 'list' * @type Duck.Types.Texture.DataType * @since 2.1.0 */ readonly dataType: Duck.Types.Texture.DataType; /** * @memberof TextureBase * @description The texture itself, can be an image or color * @type HTMLImageElement | string * @since 2.1.0 */ texture: type extends 'image' ? HTMLImageElement : type extends 'either' ? string | HTMLImageElement : string; /** * @memberof Texture * @description The scale of the texture * @type Vector2 * @since 2.1.0 */ scale: Vector2; /** * @constructor Texture * @description Creates an image texture * @param {'image'} type Texture type * @param {HTMLImageElement} texture Texture source * @param {number} w Width of texture * @param {number} h Height of texture * @since 2.1.0 */ constructor(type: 'image', dataType: Duck.Types.Texture.DataType, texture: HTMLImageElement, w: number, h: number); /** * @constructor Texture * @description Creates a color texture * @param {'color'} type Texture type * @param {string} texture Texture source * @param {number} w Width of texture * @param {number} h Height of texture * @since 2.1.0 */ constructor(type: 'color', dataType: Duck.Types.Texture.DataType, texture: string, w: number, h: number); /** * @constructor Texture * @description Creates a color or image texture * @param {'either'} type Texture type * @param {HTMLImageElement | string} texture Texture source * @param {number} w Width of texture * @param {number} h Height of texture * @since 2.1.0 */ constructor(type: 'either', dataType: Duck.Types.Texture.DataType, texture: HTMLImageElement | string, w: number, h: number); /** * @memberof Texture * @description Sets the Texture Scale * @param {Duck.Types.Misc.Scale} scale New scale of the texture * @since 2.1.0 */ setScale(scale: Duck.Types.Misc.Scale): Vector2; /** * @memberof Texture * @description Sets the Texture Image Path if the type is image * @param {string} imagePath New imagePath of the texture * @since 2.1.0 */ setImagePath(imagePath: string): void; /** * @memberof Texture * @description Sets the Texture color if the type is color * @param {string} color New color of the texture * @since 2.1.0 */ setFillColor(color: string | number): void; /** * @memberof TextureBase * @description Creates a new TextureBase instance from a color * @param {string} color Color * @param {number} w Width * @param {number} h Height * @static * @returns {TextureBase<'color'>} * @since 2.1.0 */ static fromColor(color: string, w: number, h: number): TextureBase<"color">; /** * @memberof TextureBase * @description Creates a new TextureBase instance from an image path * @param {string} imgpath Image path * @param {number} w Width * @param {number} h Height * @static * @returns {TextureBase<'image'>} * @since 2.1.0 */ static fromTexture(imgpath: string, w: number, h: number): TextureBase<"image">; /** * @memberof TextureBase * @description Creates a new TextureBase instance from a color or an image path * @param {string} fillColorOrIMGPath Color or Image path * @param {number} w Width * @param {number} h Height * @static * @returns {TextureBase<'either'>} * @since 2.1.0 */ static fromEither(fillColorOrIMGPath: string, w: number, h: number): TextureBase<"either">; }