UNPKG

@tolokoban/tgd

Version:

ToloGameDev library for WebGL2

109 lines 3.99 kB
import type { TgdContext } from "../../context"; import { TgdDataset, type TgdDatasetTypeRecord } from "../../dataset"; import { TgdTransfo, TgdVec2 } from "../../math"; import { TgdProgram } from "../../program"; import { type TgdCodeBloc, type TgdCodeFunctions } from "../../shader"; import type { TgdTexture2D } from "../../texture"; import type { WebglAttributeType } from "../../types"; import { TgdVertexArray } from "../../vao"; import { AccessorProxy } from "./accessor"; import { TgdPainterSpritesAbstract } from "./sprites-abstract"; import type { AtlasItem, TgdSprite } from "./types"; export type { TgdSprite } from "./types"; export type TgdPainterSpritesAtlas = AtlasItem[]; export interface TgdPainterSpritesOptions { texture: TgdTexture2D; atlas: TgdPainterSpritesAtlas; /** * The biggest square contained in the atlas has a size of `atlasUnit`. * * Default: 1 */ atlasUnit?: number; /** * If there is not enough space when adding a sprite, * the capacity will be doubled. * * Default: 1 */ initialCapacity?: number; /** * If `true`, the sprites will always face the camera. */ faceCamera?: boolean; attributes?: TgdDatasetTypeRecord; attributesSetter?(attributes: Record<keyof TgdDatasetTypeRecord, AccessorProxy>, key: string | symbol, value: unknown, offset: number): void; varyings?: { [name: string]: WebglAttributeType; }; vert?: { functions?: TgdCodeFunctions | (() => TgdCodeFunctions); code?: TgdCodeBloc | (() => TgdCodeBloc); }; frag?: { functions?: TgdCodeFunctions | (() => TgdCodeFunctions); code?: TgdCodeBloc | (() => TgdCodeBloc); }; } type Sprite<T extends TgdSprite> = T & { _offset: number; }; export declare class TgdPainterSprites<T extends TgdSprite = TgdSprite> extends TgdPainterSpritesAbstract<TgdSprite, T> { protected readonly context: TgdContext; protected readonly options: TgdPainterSpritesOptions; readonly transfo: TgdTransfo; readonly texture: TgdTexture2D; protected readonly datasetInstances: TgdDataset; protected readonly prg: TgdProgram; protected readonly vao: TgdVertexArray; /** * Number of actual sprites. * * The capacity can be get with `this.dataset.count`. */ protected _count: number; protected readonly sprites: Sprite<T>[]; /** * Map[id] = index in array `sprites` */ protected readonly spriteIndexes: Map<number, number>; protected readonly attPosition: AccessorProxy; protected readonly attCos: AccessorProxy; protected readonly attSin: AccessorProxy; protected readonly attScale: AccessorProxy; protected readonly attUV: AccessorProxy; protected readonly attSize: AccessorProxy; protected readonly attOrigin: AccessorProxy; protected readonly attributes: Record<string, AccessorProxy>; protected readonly uniAtlasRatio: TgdVec2; protected dirty: boolean; private uniFaceCamera; private static id; constructor(context: TgdContext, options: TgdPainterSpritesOptions); list(): ReadonlyArray<T>; forEach(callback: (sprite: T) => void): void; filter(test: (sprite: T) => boolean): ReadonlyArray<T>; get count(): number; protected set count(value: number); get capacity(): number; protected set capacity(value: number); /** * Delete all sprites. */ clear(): void; add(data: Omit<T, keyof TgdSprite> & Partial<Omit<T, "id">>): T; protected initialize(sprite: T, info: T): void; protected interceptSetter(key: string | symbol, value: unknown, { offset, atlas }: { id: number; offset: number; atlas: TgdPainterSpritesAtlas; }): boolean; remove(sprite: { id: number; }): boolean; delete(): void; paint(): void; debug(caption?: string): void; protected updateAccessors(): void; } //# sourceMappingURL=sprites.d.ts.map