api.graphics
GraphicsApi
The pictures the viewport draws, for a plugin's own lists and previews: the same cached canvases, so asking for one costs nothing after the first time. Everything is null when the graphics it needs were never extracted — a plugin shows a name instead.
- ready
- load
- unitImage
- spriteImage
- tileImage
- doodadImage
- renderRect
- playerColor
- requestUnit
- requestSprite
- onImageLoaded
Members
ready
ready(): { tileset: boolean; units: boolean; };
Whether the tileset graphics and the unit tables are in memory.
load
load(): Promise<{ tileset: boolean; units: boolean; }>;
Fetch both; resolves with what is available afterwards.
unitImage
unitImage(unitId: number, options?: { owner?: number; }): PluginImage | null;
A unit type in its editor pose, in a player's colours (owner 0 by default).
spriteImage
spriteImage(kind: SpriteKind, id: number, options?: { owner?: number; flipped?: boolean; }): PluginImage | null;
A THG2 sprite: a sprites.dat image for "pure", a unit for "unit".
tileImage
tileImage(tileId: number): PluginImage | null;
One 32 × 32 megatile of the open map's tileset.
renderRect
renderRect(rect: Rect, options?: Partial<MapImageOptions>): Promise<Blob | null>;
Part of the map as File ▸ Export ▸ Image draws it — the same render, cropped to a tile rect. Everything it needs is loaded first; null without a map or a canvas.
requestUnit
requestUnit(unitId: number): boolean;
Start fetching the GRPs a unit type needs, and say whether they are already in
memory. Graphics load lazily, so the first unitImage for a type is often null —
ask for it here, redraw on onImageLoaded, and the list fills in.
requestSprite
requestSprite(kind: SpriteKind, id: number): boolean;
onImageLoaded
onImageLoaded(listener: () => void): Disposable;
A GRP finished loading: anything drawn from one may look different now.
Types
Declarations only this group names.
PluginImageinterface
interface PluginImage
A picture the editor already has: the canvas it draws from, and its size in pixels.
image: HTMLCanvasElement | |
|---|---|
width: number | |
height: number |