UNPKG

@runejs/filestore

Version:

Tools for managing the RuneJS filestore.

85 lines (84 loc) 2.98 kB
import type { Filestore } from '../filestore'; import { type SpritePack, type SpriteStore, type Sprite } from './sprite-store'; /** * A list of game font file names. */ export declare enum FontName { p11_full = "p11_full", p12_full = "p12_full", b12_full = "b12_full", q8_full = "q8_full", lunar_alphabet = "lunar_alphabet", lunar_alphabet_lrg = "lunar_alphabet_lrg" } export declare const fontNames: FontName[]; export declare class Font { readonly name: string; private readonly spriteStore; /** * The `SpritePack` containing this `Font`'s various character glypth. */ readonly spritePack: SpritePack; constructor(name: string, spriteStore: SpriteStore); /** * Draws the given string and returns it as a base64 encoded PNG image string. * @param string The string to draw. * @param textColor The color to draw the text in. * @returns A base64 encoded PNG image. */ drawString(string: string, textColor?: number): string; /** * Fetches all of the pixels of a character glyph in `Uint8ClampedArray` rgba pixel format. * @param char The character or character code to get the pixels of. * @param color The color to set the character's pixels to. Defaults to white. */ getCharPixels(char: string | number, color?: number): Uint8ClampedArray | null; /** * Finds and returns the height of the the specified string. * @param string The string to find the height of. */ getStringHeight(string: string): number; /** * Calculates the total width of all character glyphs within the specified string. * @param string The string to find the width of. */ getStringWidth(string: string): number; /** * Gets the glyph height for the specified character or character code. * @param char The character or character code to get the height of. */ getCharHeight(char: string | number): number; /** * Gets the glyph width for the specified character or character code. * @param char The character or character code to get the width of. */ getCharWidth(char: string | number): number; /** * Gets the `Sprite` for the specified character or character code. * @param char The character or character code to get the sprite glyph for. */ getSprite(inputChar: string | number): Sprite | null; } /** * Contains information and tools for the game's fonts. */ export declare class FontStore { private readonly filestore; /** * A map of loaded game fonts by name. */ readonly fonts: Map<FontName, Font>; constructor(filestore: Filestore); /** * Load the list of registered game fonts and their associated Sprite Packs. */ loadFonts(): FontStore; /** * Fetches a font by its file name */ getFontByName(fontName: FontName): Font; /** * Fetches a font by its ID */ getFontById(spriteId: number): Font; }