UNPKG

roguelike-pumpkin-patch

Version:
49 lines (48 loc) 2.21 kB
import { DisplayParams, TileSize, Dimension, TileOptions } from './DisplayInterfaces.js'; import Tile from './Tile.js'; /** Display class, to create and control a display */ export default class Display { private _width; private _height; private target; readonly element: HTMLDivElement; private tiles; private centerPosition; private _tileSize; /** Create a new Display * @param {DisplayParams} parameters - Object of parameters to initialize the display. */ constructor(parameters: DisplayParams); /** Tile size */ get tileSize(): TileSize; set tileSize(newTileSize: TileSize); /** Get or set the display dimensions */ get dimensions(): Dimension; set dimensions(newDimensions: Dimension); /** Reset display element size */ resetSize(): void; /** Position to center the display view on */ centerDisplay(x?: number, y?: number): void; private moveToCenter; /** Build the array of tiles and attach them to the display */ allocateDisplay(): void; /** Get the display tile at the specified position * @param {number} x - Position from the left side of the display * @param {number} y - Position from the top of the display */ getTile(x: number, y: number): Tile | undefined; /** Take input and format into TileOptions */ private formatTileOptions; /** Set details for the specified tile */ setTile(x: number, y: number, newOptions: TileOptions | string | HTMLElement): void; /** Update details for the specified tile, preserving every unset property. */ updateTile(x: number, y: number, newOptions: TileOptions | string | HTMLElement): void; /** Given the size of the target container, and the tile size, determine the number of tiles needed. */ calculateDimensions(clientRect?: DOMRect): Dimension; /** Given the size of the target container, and the number of tiles, determine the tile size needed * This assumes square tiles are desired. */ calculateTileSize(clientRect?: DOMRect): TileSize; /** Add the default styles to the head of the page. */ applyDefaultStyles(): void; }