import { MapScreenrSettings , VariableFunctions , Variables } from "./types" ; /**
 * Flexible container for map attributes and viewport.
 */ export class MapScreenr { /**
     * A listing of variable Functions to be calculated on screen resets.
     */ public readonly variableFunctions : VariableFunctions ; /**
     * Top border measurement of the bounding box.
     */ public top : number ; /**
     * Right border measurement of the bounding box.
     */ public right : number ; /**
     * Bottom border measurement of the bounding box.
     */ public bottom : number ; /**
     * Left border measurement of the bounding box.
     */ public left : number ; /**
     * Constant horizontal midpoint of the bounding box, equal to (left + right) / 2.
     */ public middleX : number ; /**
     * Constant vertical midpoint of the bounding box, equal to (top + bottom) / 2.
     */ public middleY : number ; /**
     * Constant width of the bounding box.
     */ public readonly width : number ; /**
     * Constant height of the bounding box.
     */ public readonly height : number ; /**
     * Assorted known variables, keyed by name.
     */ public readonly variables : Variables = { } ; param settings public constructor ( settings ) { if ( settings . variables !== undefined ) { for ( const name in settings . variables ) { if ( { } . hasOwnProperty . call ( settings . variables , name ) ) { this . variables [ name ] = settings . variables [ name ] ; } } } this . height = settings . height ; this . width = settings . width ; this . variableFunctions = settings . variableFunctions === undefined ? { } : settings . variableFunctions ; } /**
     * Completely clears the MapScreenr for use in a new Area. Positioning is
     * reset to (0,0) and user-configured variables are recalculated.
     */ public clearScreen ( ) { this . left = 0 ; this . top = 0 ; this . right = this . width ; this . bottom = this . height ; this . setMiddleX ( ) ; this . setMiddleY ( ) ; this . setVariables ( ) ; } /**
     * Computes middleX as the midpoint between left and right.
     */ public setMiddleX ( ) { this . middleX = ( this . left + this . right ) / 2 ; } /**
     * Computes middleY as the midpoint between top and bottom.
     */ public setMiddleY ( ) { this . middleY = ( this . top + this . bottom ) / 2 ; } /**
     * Recalculates all variables.
     */ public setVariables ( ) { for ( const i in this . variableFunctions ) { this . setVariable ( i ) ; } } param name param value returns public setVariable ( name , value ? ) { this . variables [ name ] = arguments . length === 1 ? this . variableFunctions [ name ] ( ) : value ; } param dx param dy public shift ( dx , dy ) { if ( dx !== 0 ) { this . shiftX ( dx ) ; } if ( dy !== 0 ) { this . shiftY ( dy ) ; } } param dx public shiftX ( dx ) { this . left += dx ; this . right += dx ; } param dy public shiftY ( dy ) { this . top += dy ; this . bottom += dy ; } }