## Modules
Tile : Object
Colors : Object
SOLVED : number
MINE : number
SECTOR_SIZE : number
DIFFICULTY : number
CENTRAL_AREA_DIFFICULTY_MODIFIER : number
DETAIL_THRESHOLD : number
DRAG_THRESHOLD : number
MAX_TRIES : number
ANIMATION_SPEED_BASE : number
CANVAS_ID : string
EventBus
EventHandler
GameController
GameLogic
GameRenderer
Saver
SipHash
LZW
UIRendererGameRenderer
DataHasher : object

An object with methods hash and generate_key such that hash(key, data) returns a number between 0 and 1 (deterministically), and generate_key(seed) returns an approprite key for hash

DataCompressor : object

An object with methods zip and unzip that accept/return strings and are reversable

LOOPS : object

An object with common loops used in game.

convertArray.<number>

Converts between tile and sector coordinates.

isMineboolean

Get the type of a tile (mine or not) deterministically.

## Members
game : GameController

The game controller instance.

## Events
"DOMContentLoaded"
## Tile : Object **Properties** | Name | Type | Description | | --- | --- | --- | | LOST | number | Tile is lost | | HIDDEN | number | Tile is hidden | | FLAGGED | number | Tile is flagged | | REVEALED | number | Tile is revealed | ## Colors : Object **Properties** | Name | Type | Description | | --- | --- | --- | | BACKGROUND | string | Background color | | BACKGROUND_ZOOMED | string | Background color when zoomed | | TILE_DEFAULT | string | Default tile color | | TILE_CLICKABLE | string | Tile color when it is clickable | | TILE_REVEALED_NUMBERED | string | Tile color when it is revealed and has a number | | TILE_REVEALED_EMPTY | string | Tile color when it is revealed and is empty | | TILE_FLAGGED | string | Tile color when it is flagged | | SECTOR_OVERLAY | string | Sector overlay color | | SECTOR_LOST_OVERLAY | string | Lost sector overlay color | | SECTOR_BORDER | string | Sector border color | | FLAG_PARTICLE_COLOR | string | Flag particle color | | SOLVED_PARTICLE_COLOR | string | Solved particle color | | LOST_PARTICLE_COLOR | string | Lost particle color | ## SOLVED : number ## MINE : number ## SECTOR\_SIZE : number ## DIFFICULTY : number ## CENTRAL\_AREA\_DIFFICULTY\_MODIFIER : number ## DETAIL\_THRESHOLD : number ## DRAG\_THRESHOLD : number ## MAX\_TRIES : number ## ANIMATION\_SPEED\_BASE : number ## CANVAS\_ID : string ## EventBus **Access**: public * [EventBus](#module_EventBus) * [~constructor()](#module_EventBus..constructor) * [~on(event, callback)](#module_EventBus..on) * [~emit(event, ...args)](#module_EventBus..emit) * [~onRetrievable(event, callback)](#module_EventBus..onRetrievable) * [~get(event, ...args)](#module_EventBus..get) ⇒ any \| undefined ### EventBus~constructor() Initializes the event bus **Kind**: inner method of [EventBus](#module_EventBus) ### EventBus~on(event, callback) Sets up an event listener **Kind**: inner method of [EventBus](#module_EventBus) | Param | Type | Description | | --- | --- | --- | | event | string | Event name | | callback | function | Callback function to call (multiple functions can be added) | ### EventBus~emit(event, ...args) Emits an event **Kind**: inner method of [EventBus](#module_EventBus) | Param | Type | Description | | --- | --- | --- | | event | string | Event name | | ...args | \* | Arguments to pass to the callback functions (0 or more) | ### EventBus~onRetrievable(event, callback) Sets up a retrievable event listener **Kind**: inner method of [EventBus](#module_EventBus) | Param | Type | Description | | --- | --- | --- | | event | string | Event name | | callback | function | Callback function to call (can only be used once) | ### EventBus~get(event, ...args) ⇒ any \| undefined Retrieves data from an event **Kind**: inner method of [EventBus](#module_EventBus) **Returns**: any \| undefined - - Data from the event or undefined | Param | Type | Description | | --- | --- | --- | | event | string | Event name | | ...args | \* | Arguments to pass to the callback function (only one) | ## EventHandler **Access**: public * [EventHandler](#module_EventHandler) * [~constructor(canvas, bus)](#module_EventHandler..constructor) * ["mousedown"](#event_mousedown) * ["mousemove"](#event_mousemove) * ["mouseup"](#event_mouseup) * ["mouseleave"](#event_mouseleave) * ["wheel"](#event_wheel) * ["click"](#event_click) * ["contextmenu"](#event_contextmenu) * ["resize"](#event_resize) * ["beforeunload"](#event_beforeunload) * ["visibilitychange"](#event_visibilitychange) ### EventHandler~constructor(canvas, bus) Initializes the event handler **Kind**: inner method of [EventHandler](#module_EventHandler) | Param | Type | | --- | --- | | canvas | HTMLCanvasElement | | bus | EventBus | ### "mousedown" **Kind**: event emitted by [EventHandler](#module_EventHandler) ### "mousemove" **Kind**: event emitted by [EventHandler](#module_EventHandler) **Emits**: EventBus#event:drag - optionally ### "mouseup" **Kind**: event emitted by [EventHandler](#module_EventHandler) **Emits**: EventBus#event:click - optionally, EventBus#event:clean\_cache - optionally ### "mouseleave" **Kind**: event emitted by [EventHandler](#module_EventHandler) **Emits**: EventBus#event:clean\_cache - optionally ### "wheel" **Kind**: event emitted by [EventHandler](#module_EventHandler) **Emits**: EventBus#event:zoom, EventBus#event:clean\_cache ### "click" **Kind**: event emitted by [EventHandler](#module_EventHandler) ### "contextmenu" **Kind**: event emitted by [EventHandler](#module_EventHandler) ### "resize" **Kind**: event emitted by [EventHandler](#module_EventHandler) **Emits**: EventBus#event:resize ### "beforeunload" **Kind**: event emitted by [EventHandler](#module_EventHandler) **Emits**: EventBus#event:save ### "visibilitychange" **Kind**: event emitted by [EventHandler](#module_EventHandler) **Emits**: EventBus#event:save - optionally ## GameController **Access**: public * [GameController](#module_GameController) * _instance_ * [.seed](#module_GameController+seed) : string * [.key](#module_GameController+key) : Uint32Array * _inner_ * [~constructor(seed)](#module_GameController..constructor) * [~init()](#module_GameController..init) * [~loadImage()](#module_GameController..loadImage) ⇒ Promise.<void> * [~start(tries)](#module_GameController..start) * [~reset(tries)](#module_GameController..reset) ### gameController.seed : string - Seed for the game (by default a stringified 16 digit random number) **Kind**: instance property of [GameController](#module_GameController) ### gameController.key : Uint32Array **Kind**: instance property of [GameController](#module_GameController) ### GameController~constructor(seed) Initializes the game controller **Kind**: inner method of [GameController](#module_GameController) | Param | Type | Description | | --- | --- | --- | | seed | string | Seed for the game | ### GameController~init() Initializes the game **Kind**: inner method of [GameController](#module_GameController) ### GameController~loadImage() ⇒ Promise.<void> Loads the game image **Kind**: inner method of [GameController](#module_GameController) **Returns**: Promise.<void> - - Promise that resolves when the image is loaded **Throws**: - Error - If the image fails to load ### GameController~start(tries) Starts the game **Kind**: inner method of [GameController](#module_GameController) **Emits**: EventBus#event:start | Param | Type | Description | | --- | --- | --- | | tries | number | Number of times the game has been reset | ### GameController~reset(tries) Resets the game **Kind**: inner method of [GameController](#module_GameController) | Param | Type | Description | | --- | --- | --- | | tries | number | Number of times the game has been reset | ## GameLogic **Access**: public * [GameLogic](#module_GameLogic) * _instance_ * [.start_time](#module_GameLogic+start_time) : Date * _inner_ * [~constructor(game_pos, key, bus)](#module_GameLogic..constructor) * [~timeAndStats()](#module_GameLogic..timeAndStats) ⇒ Object * [~setStats(stats)](#module_GameLogic..setStats) * [~click(x, y, button)](#module_GameLogic..click) * [~updateKey(key)](#module_GameLogic..updateKey) * [~buy(x, y, [s_x], [s_y])](#module_GameLogic..buy) * [~reveal(x, y, [s_x], [s_y], [no_animate])](#module_GameLogic..reveal) ⇒ Promise.<boolean> * [~flag(x, y, [s_x], [s_y])](#module_GameLogic..flag) * [~isClickable(x, y, [s_x], [s_y])](#module_GameLogic..isClickable) ⇒ boolean * [~isFlagged(x, y, [s_x], [s_y])](#module_GameLogic..isFlagged) ⇒ boolean * [~isRevealed(x, y, [s_x], [s_y])](#module_GameLogic..isRevealed) ⇒ boolean * [~isSectorSolved(sector_key)](#module_GameLogic..isSectorSolved) ⇒ boolean * [~collectStats(s_x, s_y)](#module_GameLogic..collectStats) * [~flagCount(x, y, [s_x], [s_y])](#module_GameLogic..flagCount) ⇒ number * [~mineCount(x, y, [s_x], [s_y], [force])](#module_GameLogic..mineCount) ⇒ number * [~buildSector(s_x, s_y)](#module_GameLogic..buildSector) ⇒ Array.<Array.<Array.<number>>> * [~buildSectorCache(s_x, s_y)](#module_GameLogic..buildSectorCache) ⇒ Array.<Array.<Array.<number>>> \| false * [~cleanSectorCache()](#module_GameLogic..cleanSectorCache) * [~animate(key, type, is_tile, [duration])](#module_GameLogic..animate) ### gameLogic.start\_time : Date **Kind**: instance property of [GameLogic](#module_GameLogic) ### GameLogic~constructor(game_pos, key, bus) Initializes the game logic **Kind**: inner method of [GameLogic](#module_GameLogic) | Param | Type | | --- | --- | | game_pos | Object | | key | Uint32Array | | bus | EventBus | ### GameLogic~timeAndStats() ⇒ Object Returns the current time in seconds **Kind**: inner method of [GameLogic](#module_GameLogic) **Returns**: Object - - Time and stats ### GameLogic~setStats(stats) Sets the stats **Kind**: inner method of [GameLogic](#module_GameLogic) | Param | Type | Description | | --- | --- | --- | | stats | Object | Stats from the save | ### GameLogic~click(x, y, button) Handles a click **Kind**: inner method of [GameLogic](#module_GameLogic) **Emits**: EventBus#event:click\_convert, EventBus#event:is\_buy\_button | Param | Type | Description | | --- | --- | --- | | x | number | X-coordinate in terms of screen | | y | number | Y-coordinate in terms of screen | | button | number | 0 for left, 1 for middle, 2 for right (from Event#button) | ### GameLogic~updateKey(key) Updates the game key **Kind**: inner method of [GameLogic](#module_GameLogic) | Param | Type | | --- | --- | | key | Uint32Array | ### GameLogic~buy(x, y, [s_x], [s_y]) Buys a sector **Kind**: inner method of [GameLogic](#module_GameLogic) | Param | Type | Description | | --- | --- | --- | | x | number | X-coordinate of tile | | y | number | Y-coordinate of tile | | [s_x] | number | X-coordinate of sector if `x` is relative | | [s_y] | number | Y-coordinate of sector if `y` is relative | ### GameLogic~reveal(x, y, [s_x], [s_y], [no_animate]) ⇒ Promise.<boolean> Reveals a tile **Kind**: inner method of [GameLogic](#module_GameLogic) **Returns**: Promise.<boolean> - - Resolves to whether the reveal caused more than one tile to be revealed | Param | Type | Default | Description | | --- | --- | --- | --- | | x | number | | X-coordinate of tile | | y | number | | Y-coordinate of tile | | [s_x] | number | | X-coordinate of sector if `x` is relative | | [s_y] | number | | Y-coordinate of sector if `y` is relative | | [no_animate] | boolean | false | If true, no animation will be played | ### GameLogic~flag(x, y, [s_x], [s_y]) Flags a tile **Kind**: inner method of [GameLogic](#module_GameLogic) | Param | Type | Description | | --- | --- | --- | | x | number | X-coordinate of tile | | y | number | Y-coordinate of tile | | [s_x] | number | X-coordinate of sector if `x` is relative | | [s_y] | number | Y-coordinate of sector if `y` is relative | ### GameLogic~isClickable(x, y, [s_x], [s_y]) ⇒ boolean Checks if a tile is clickable **Kind**: inner method of [GameLogic](#module_GameLogic) **Returns**: boolean - - True if tile is clickable, false otherwise | Param | Type | Description | | --- | --- | --- | | x | number | X-coordinate of tile | | y | number | Y-coordinate of tile | | [s_x] | number | X-coordinate of sector if `x` is relative | | [s_y] | number | Y-coordinate of sector if `y` is relative | ### GameLogic~isFlagged(x, y, [s_x], [s_y]) ⇒ boolean Checks if a tile is flagged **Kind**: inner method of [GameLogic](#module_GameLogic) **Returns**: boolean - - True if tile is flagged, false otherwise | Param | Type | Description | | --- | --- | --- | | x | number | X-coordinate of tile | | y | number | Y-coordinate of tile | | [s_x] | number | X-coordinate of sector if `x` is relative | | [s_y] | number | Y-coordinate of sector if `y` is relative | ### GameLogic~isRevealed(x, y, [s_x], [s_y]) ⇒ boolean Checks if a tile is revealed **Kind**: inner method of [GameLogic](#module_GameLogic) **Returns**: boolean - - True if tile is revealed, false otherwise | Param | Type | Description | | --- | --- | --- | | x | number | X-coordinate of tile | | y | number | Y-coordinate of tile | | [s_x] | number | X-coordinate of sector if `x` is relative | | [s_y] | number | Y-coordinate of sector if `y` is relative | ### GameLogic~isSectorSolved(sector_key) ⇒ boolean Checks if a sector is solved **Kind**: inner method of [GameLogic](#module_GameLogic) **Returns**: boolean - - True if sector is solved, false otherwise | Param | Type | Description | | --- | --- | --- | | sector_key | string | Key of sector | ### GameLogic~collectStats(s_x, s_y) Collects statistics about a solved sector into the stats object **Kind**: inner method of [GameLogic](#module_GameLogic) | Param | Type | Description | | --- | --- | --- | | s_x | number | X-coordinate of sector | | s_y | number | Y-coordinate of sector | ### GameLogic~flagCount(x, y, [s_x], [s_y]) ⇒ number Counts the number of flags adjacent to a tile **Kind**: inner method of [GameLogic](#module_GameLogic) **Returns**: number - - The number of flags adjacent to the tile | Param | Type | Description | | --- | --- | --- | | x | number | X-coordinate of tile | | y | number | Y-coordinate of tile | | [s_x] | number | X-coordinate of sector if `x` is relative | | [s_y] | number | Y-coordinate of sector if `y` is relative | ### GameLogic~mineCount(x, y, [s_x], [s_y], [force]) ⇒ number Counts the number of mines adjacent to a tile **Kind**: inner method of [GameLogic](#module_GameLogic) **Returns**: number - - The number of mines adjacent to the tile | Param | Type | Default | Description | | --- | --- | --- | --- | | x | number | | X-coordinate of tile | | y | number | | Y-coordinate of tile | | [s_x] | number | | X-coordinate of sector if `x` is relative | | [s_y] | number | | Y-coordinate of sector if `y` is relative | | [force] | boolean | false | Force count even if tile is revealed | ### GameLogic~buildSector(s_x, s_y) ⇒ Array.<Array.<Array.<number>>> Builds a new sector **Kind**: inner method of [GameLogic](#module_GameLogic) **Returns**: Array.<Array.<Array.<number>>> - - The sector | Param | Type | Description | | --- | --- | --- | | s_x | number | X-coordinate of sector | | s_y | number | Y-coordinate of sector | ### GameLogic~buildSectorCache(s_x, s_y) ⇒ Array.<Array.<Array.<number>>> \| false Builds a sector cache **Kind**: inner method of [GameLogic](#module_GameLogic) **Returns**: Array.<Array.<Array.<number>>> \| false - - The cached sector | Param | Type | Description | | --- | --- | --- | | s_x | number | X-coordinate of sector | | s_y | number | Y-coordinate of sector | ### GameLogic~cleanSectorCache() Cleans the sector cache **Kind**: inner method of [GameLogic](#module_GameLogic) **Emits**: EventBus#event:sector\_bounds ### GameLogic~animate(key, type, is_tile, [duration]) Animate a tile or sector **Kind**: inner method of [GameLogic](#module_GameLogic) | Param | Type | Default | Description | | --- | --- | --- | --- | | key | string | | Key to use for hashing | | type | string | | Type of animation | | is_tile | boolean | | Whether the animation is for a tile | | [duration] | number | ANIMATION_SPEED_BASE | Duration of the animation if it is a tile (in ms). | ## GameRenderer **Access**: public * [GameRenderer](#module_GameRenderer) * _instance_ * [.canvas](#module_GameRenderer+canvas) : HTMLCanvasElement * [.ctx](#module_GameRenderer+ctx) : CanvasRenderingContext2D * _inner_ * [~constructor(img, game_pos, key, bus)](#module_GameRenderer..constructor) * [~getViewPos()](#module_GameRenderer..getViewPos) ⇒ Object * [~setViewPos(view_pos)](#module_GameRenderer..setViewPos) * [~draw()](#module_GameRenderer..draw) * [~drawBuyButtons(s_x, s_y)](#module_GameRenderer..drawBuyButtons) * [~drawRoundedRect(x, y, width, height, radius)](#module_GameRenderer..drawRoundedRect) * [~drawStaticTiles(sector, s_x, s_y, x, y)](#module_GameRenderer..drawStaticTiles) * [~drawAnimatedTiles(sector, s_x, s_y, x, y)](#module_GameRenderer..drawAnimatedTiles) * [~drawParticles(tile_x, tile_y, frame_time, [color])](#module_GameRenderer..drawParticles) * [~drawSectorBorders(start_x, start_y)](#module_GameRenderer..drawSectorBorders) * [~drawSectorOverlays(s_x, s_y)](#module_GameRenderer..drawSectorOverlays) * [~drawSolvedAnimations(s_x, s_y)](#module_GameRenderer..drawSolvedAnimations) * [~drawSolvedParticles(sector_x_pos, sector_y_pos, frame_time)](#module_GameRenderer..drawSolvedParticles) * [~drawLostAnimations(s_x, s_y)](#module_GameRenderer..drawLostAnimations) ### gameRenderer.canvas : HTMLCanvasElement **Kind**: instance property of [GameRenderer](#module_GameRenderer) ### gameRenderer.ctx : CanvasRenderingContext2D **Kind**: instance property of [GameRenderer](#module_GameRenderer) ### GameRenderer~constructor(img, game_pos, key, bus) Initializes the game renderer **Kind**: inner method of [GameRenderer](#module_GameRenderer) | Param | Type | | --- | --- | | img | Image | | game_pos | Object | | key | Uint32Array | | bus | EventBus | ### GameRenderer~getViewPos() ⇒ Object Returns the current view position (for saving) **Kind**: inner method of [GameRenderer](#module_GameRenderer) **Returns**: Object - - The view position (offset, tile_size) ### GameRenderer~setViewPos(view_pos) Sets the view position (from saved data) **Kind**: inner method of [GameRenderer](#module_GameRenderer) **Emits**: EventBus#event:disable\_click - optionally | Param | Type | Description | | --- | --- | --- | | view_pos | Object | The view position (offset, tile_size) | ### GameRenderer~draw() Draws the main game frame **Kind**: inner method of [GameRenderer](#module_GameRenderer) ### GameRenderer~drawBuyButtons(s_x, s_y) Draws the buy buttons for a sector **Kind**: inner method of [GameRenderer](#module_GameRenderer) | Param | Type | Description | | --- | --- | --- | | s_x | number | X-coordinate of sector | | s_y | number | Y-coordinate of sector | ### GameRenderer~drawRoundedRect(x, y, width, height, radius) Draws a rounded rectangle **Kind**: inner method of [GameRenderer](#module_GameRenderer) | Param | Type | Description | | --- | --- | --- | | x | number | X-coordinate of top-left corner | | y | number | Y-coordinate of top-left corner | | width | number | Width of rectangle | | height | number | Height of rectangle | | radius | number | Radius of rounded corners | ### GameRenderer~drawStaticTiles(sector, s_x, s_y, x, y) Draws a static tile **Kind**: inner method of [GameRenderer](#module_GameRenderer) | Param | Type | Description | | --- | --- | --- | | sector | Array.<Array.<Array.<number>>> \| false | | | s_x | number | X-coordinate of sector | | s_y | number | Y-coordinate of sector | | x | number | X-coordinate of tile | | y | number | Y-coordinate of tile | ### GameRenderer~drawAnimatedTiles(sector, s_x, s_y, x, y) Draws an animated tile **Kind**: inner method of [GameRenderer](#module_GameRenderer) | Param | Type | Description | | --- | --- | --- | | sector | Array.<Array.<Array.<number>>> \| false | | | s_x | number | X-coordinate of sector | | s_y | number | Y-coordinate of sector | | x | number | X-coordinate of tile | | y | number | Y-coordinate of tile | ### GameRenderer~drawParticles(tile_x, tile_y, frame_time, [color]) Draws particles **Kind**: inner method of [GameRenderer](#module_GameRenderer) | Param | Type | Default | Description | | --- | --- | --- | --- | | tile_x | number | | X-coordinate of top-left corner of tile | | tile_y | number | | Y-coordinate of top-left corner of tile | | frame_time | number | | Time since animation start (0-1) | | [color] | string | "COLORS.FLAG_PARTICLE_COLOR" | Color of particle | ### GameRenderer~drawSectorBorders(start_x, start_y) Draws sector borders **Kind**: inner method of [GameRenderer](#module_GameRenderer) | Param | Type | Description | | --- | --- | --- | | start_x | number | X-coordinate of top-left corner of sector | | start_y | number | Y-coordinate of top-left corner of sector | ### GameRenderer~drawSectorOverlays(s_x, s_y) Draws sector overlays **Kind**: inner method of [GameRenderer](#module_GameRenderer) | Param | Type | Description | | --- | --- | --- | | s_x | number | X-coordinate of sector | | s_y | number | Y-coordinate of sector | ### GameRenderer~drawSolvedAnimations(s_x, s_y) Draws solved sector animations **Kind**: inner method of [GameRenderer](#module_GameRenderer) | Param | Type | Description | | --- | --- | --- | | s_x | number | X-coordinate of sector | | s_y | number | Y-coordinate of sector | ### GameRenderer~drawSolvedParticles(sector_x_pos, sector_y_pos, frame_time) Draws solved sector particles **Kind**: inner method of [GameRenderer](#module_GameRenderer) | Param | Type | Description | | --- | --- | --- | | sector_x_pos | number | X-coordinate of sector | | sector_y_pos | number | Y-coordinate of sector | | frame_time | number | Current frame time (0-1) | ### GameRenderer~drawLostAnimations(s_x, s_y) Draws lost sector animations **Kind**: inner method of [GameRenderer](#module_GameRenderer) | Param | Type | Description | | --- | --- | --- | | s_x | number | X-coordinate of sector | | s_y | number | Y-coordinate of sector | ## Saver **Access**: public * [Saver](#module_Saver) * _instance_ * [.save_interval_id](#module_Saver+save_interval_id) : number * _inner_ * [~constructor(game, bus)](#module_Saver..constructor) * [~startAutosaver()](#module_Saver..startAutosaver) * [~stopAutosaver()](#module_Saver..stopAutosaver) * [~isSaved()](#module_Saver..isSaved) ⇒ boolean * [~save()](#module_Saver..save) ⇒ string * [~load([compressed])](#module_Saver..load) * [~saveToFile()](#module_Saver..saveToFile) * [~deleteSave()](#module_Saver..deleteSave) * [~loadFromFile()](#module_Saver..loadFromFile) ### saver.save\_interval\_id : number - ID of the autosave interval **Kind**: instance property of [Saver](#module_Saver) ### Saver~constructor(game, bus) Initializes the game saver **Kind**: inner method of [Saver](#module_Saver) | Param | Type | | --- | --- | | game | GameController | | bus | EventBus | ### Saver~startAutosaver() Starts the autosave feature **Kind**: inner method of [Saver](#module_Saver) ### Saver~stopAutosaver() Stops the autosave feature **Kind**: inner method of [Saver](#module_Saver) ### Saver~isSaved() ⇒ boolean Checks if a save exists **Kind**: inner method of [Saver](#module_Saver) **Returns**: boolean - - Whether a save exists or not ### Saver~save() ⇒ string Saves the game data **Kind**: inner method of [Saver](#module_Saver) **Returns**: string - - Compressed game data **Emits**: EventBus#event:view\_pos, EventBus#event:time\_and\_stats ### Saver~load([compressed]) Loads the game data **Kind**: inner method of [Saver](#module_Saver) **Emits**: EventBus#event:set\_stats, EventBus#event:set\_view\_pos, EventBus#event:update\_key, EventBus#event:reset | Param | Type | Description | | --- | --- | --- | | [compressed] | string | Compressed game data | ### Saver~saveToFile() Saves the game data to a file **Kind**: inner method of [Saver](#module_Saver) ### Saver~deleteSave() Deletes the save **Kind**: inner method of [Saver](#module_Saver) ### Saver~loadFromFile() Loads the game data from a file **Kind**: inner method of [Saver](#module_Saver) ## SipHash **Access**: package **Important**: - Siphash implementation taken from https://github.com/jedisct1/siphash-js (minified browser version) **Author**: Frank Denis ## LZW **Access**: package ## UIRenderer ⇐ GameRenderer **Extends**: GameRenderer **Access**: public * [UIRenderer](#module_UIRenderer) ⇐ GameRenderer * _instance_ * [.loop](#module_UIRenderer+loop) : function * [.frame_id](#module_UIRenderer+frame_id) : number * _inner_ * [~constructor(img, game_pos, key, bus)](#module_UIRenderer..constructor) * [~loop()](#module_UIRenderer..loop) * [~drag(x, y)](#module_UIRenderer..drag) * [~resize()](#module_UIRenderer..resize) * [~updateKey(key)](#module_UIRenderer..updateKey) * [~zoom(x, y, is_zoom_in)](#module_UIRenderer..zoom) ⇒ boolean * [~isBuyButton(x, y)](#module_UIRenderer..isBuyButton) ⇒ boolean * [~sectorBounds()](#module_UIRenderer..sectorBounds) ⇒ Array * [~clickConvert(x, y)](#module_UIRenderer..clickConvert) ⇒ Array ### uiRenderer.loop : function - Bound `loop` function so `requestAnimationFrame` keeps `this` context **Kind**: instance property of [UIRenderer](#module_UIRenderer) ### uiRenderer.frame\_id : number - ID of the animation frame **Kind**: instance property of [UIRenderer](#module_UIRenderer) ### UIRenderer~constructor(img, game_pos, key, bus) Initializes the renderer **Kind**: inner method of [UIRenderer](#module_UIRenderer) | Param | Type | | --- | --- | | img | Image | | game_pos | Object | | key | Uint32Array | | bus | EventBus | ### UIRenderer~loop() Loops the animation frame and calls `draw` **Kind**: inner method of [UIRenderer](#module_UIRenderer) ### UIRenderer~drag(x, y) Updates the offset **Kind**: inner method of [UIRenderer](#module_UIRenderer) | Param | Type | Description | | --- | --- | --- | | x | number | X-offset | | y | number | Y-offset | ### UIRenderer~resize() Resizes the canvas **Kind**: inner method of [UIRenderer](#module_UIRenderer) ### UIRenderer~updateKey(key) Updates the key **Kind**: inner method of [UIRenderer](#module_UIRenderer) | Param | Type | | --- | --- | | key | Uint32Array | ### UIRenderer~zoom(x, y, is_zoom_in) ⇒ boolean Zooms in or out **Kind**: inner method of [UIRenderer](#module_UIRenderer) **Returns**: boolean - - True if details are hidden, false otherwise | Param | Type | Description | | --- | --- | --- | | x | number | X-coordinate of center of zoom | | y | number | Y-coordinate of center of zoom | | is_zoom_in | boolean | True if zooming in, false if zooming out | ### UIRenderer~isBuyButton(x, y) ⇒ boolean Checks if the tile is a buy button **Kind**: inner method of [UIRenderer](#module_UIRenderer) **Returns**: boolean - True if the tile is a buy button, false otherwise | Param | Type | Description | | --- | --- | --- | | x | number | X-coordinate of the tile | | y | number | Y-coordinate of the tile | ### UIRenderer~sectorBounds() ⇒ Array Returns the sector bounds **Kind**: inner method of [UIRenderer](#module_UIRenderer) **Returns**: Array - - Array of [start_x, start_y, end_x, end_y] ### UIRenderer~clickConvert(x, y) ⇒ Array Converts raw click coords to sector adjusted coords **Kind**: inner method of [UIRenderer](#module_UIRenderer) **Returns**: Array - - Array of [x, y] | Param | Type | Description | | --- | --- | --- | | x | number | X-coordinate of the click | | y | number | Y-coordinate of the click | ## DataHasher : object An object with methods `hash` and `generate_key` such that `hash(key, data)` returns a number between 0 and 1 (deterministically), and `generate_key(seed)` returns an approprite key for `hash` **Access**: public **Properties** | Name | Type | | --- | --- | | generate_key | function | | hash | function | * [DataHasher](#module_DataHasher) : object * [~generate_key(seed)](#module_DataHasher..generate_key) ⇒ Uint32Array * [~hash(key, data)](#module_DataHasher..hash) ⇒ number ### DataHasher~generate\_key(seed) ⇒ Uint32Array Generates a key **Kind**: inner method of [DataHasher](#module_DataHasher) **Returns**: Uint32Array - - Generated key It can be the input itself for hashing functions that dont require keys. | Param | Type | Description | | --- | --- | --- | | seed | string | Seed for the hash function | ### DataHasher~hash(key, data) ⇒ number Hashes data **Kind**: inner method of [DataHasher](#module_DataHasher) **Returns**: number - - Psudo-random number between 0 and 1 | Param | Type | Description | | --- | --- | --- | | key | Uint32Array | Key for the hash function For hashing functions that dont require keys it can be concatenated to the data | | data | string | Data to hash | ## DataCompressor : object An object with methods `zip` and `unzip` that accept/return strings and are reversable **Access**: public **Properties** | Name | Type | | --- | --- | | zip | function | | unzip | function | * [DataCompressor](#module_DataCompressor) : object * [~zip(data)](#module_DataCompressor..zip) ⇒ string * [~unzip(data)](#module_DataCompressor..unzip) ⇒ string ### DataCompressor~zip(data) ⇒ string Compresses data **Kind**: inner method of [DataCompressor](#module_DataCompressor) **Returns**: string - - Compressed data | Param | Type | Description | | --- | --- | --- | | data | string | Uncompressed data | ### DataCompressor~unzip(data) ⇒ string Uncompresses data **Kind**: inner method of [DataCompressor](#module_DataCompressor) **Returns**: string - - Uncompressed data **Throws**: - Error - If the compressed data is invalid | Param | Type | Description | | --- | --- | --- | | data | string | Compressed data | ## LOOPS : object An object with common loops used in game. **Access**: public **Properties** | Name | Type | | --- | --- | | overAdjacent | function | | overAdjacentSum | function | | anyAdjacent | function | | overOnScreenSectors | function | | overTilesInSector | function | | anyTilesInSector | function | | overTilesInSectorSum | function | * [LOOPS](#module_LOOPS) : object * [~overAdjacent(f, x, y, [s_x], [s_y])](#module_LOOPS..overAdjacent) * [~overAdjacentSum(condition, x, y, [s_x], [s_y])](#module_LOOPS..overAdjacentSum) ⇒ number * [~anyAdjacent(condition, x, y, [s_x], [s_y])](#module_LOOPS..anyAdjacent) ⇒ boolean * [~overOnScreenSectors(f, start_x, start_y, sector_size_in_px, canvas)](#module_LOOPS..overOnScreenSectors) * [~overTilesInSector(f)](#module_LOOPS..overTilesInSector) * [~anyTilesInSector(condition)](#module_LOOPS..anyTilesInSector) ⇒ boolean * [~overTilesInSectorSum(condition)](#module_LOOPS..overTilesInSectorSum) ⇒ number ### LOOPS~overAdjacent(f, x, y, [s_x], [s_y]) Loops over adjacent tiles and calls a function **Kind**: inner method of [LOOPS](#module_LOOPS) | Param | Type | Description | | --- | --- | --- | | f | function | Function to call on each tile | | x | number | X-coordinate of tile | | y | number | Y-coordinate of tile | | [s_x] | number | X-coordinate of sector if `x` is relative | | [s_y] | number | Y-coordinate of sector if `y` is relative | ### LOOPS~overAdjacentSum(condition, x, y, [s_x], [s_y]) ⇒ number Loops over adjacent tiles and checks if they satisfy a condition **Kind**: inner method of [LOOPS](#module_LOOPS) **Returns**: number - - Number of adjacent tiles that satisfy the condition | Param | Type | Description | | --- | --- | --- | | condition | function | The condition to check | | x | number | X-coordinate of tile | | y | number | Y-coordinate of tile | | [s_x] | number | X-coordinate of sector if `x` is relative | | [s_y] | number | Y-coordinate of sector if `y` is relative | ### LOOPS~anyAdjacent(condition, x, y, [s_x], [s_y]) ⇒ boolean Loops over adjacent tiles and checks if they satisfy a condition **Kind**: inner method of [LOOPS](#module_LOOPS) **Returns**: boolean - - Whether any adjacent tile satisfies the condition or not | Param | Type | Description | | --- | --- | --- | | condition | function | The condition to check | | x | number | X-coordinate of tile | | y | number | Y-coordinate of tile | | [s_x] | number | X-coordinate of sector if `x` is relative | | [s_y] | number | Y-coordinate of sector if `y` is relative | ### LOOPS~overOnScreenSectors(f, start_x, start_y, sector_size_in_px, canvas) Loops over all sectors in view **Kind**: inner method of [LOOPS](#module_LOOPS) | Param | Type | Description | | --- | --- | --- | | f | function | Function to call on each sector | | start_x | number | X-coordinate of starting sector | | start_y | number | Y-coordinate of starting sector | | sector_size_in_px | number | Size of sector in pixels | | canvas | HTMLCanvasElement | Canvas element | ### LOOPS~overTilesInSector(f) Loops over all tiles in a sector **Kind**: inner method of [LOOPS](#module_LOOPS) | Param | Type | Description | | --- | --- | --- | | f | function | Function to call on each tile | ### LOOPS~anyTilesInSector(condition) ⇒ boolean Checks if any tile in a sector satisfies a condition **Kind**: inner method of [LOOPS](#module_LOOPS) **Returns**: boolean - - Whether any tile satisfies the condition or not | Param | Type | Description | | --- | --- | --- | | condition | function | The condition to check | ### LOOPS~overTilesInSectorSum(condition) ⇒ number Checks if all tiles in a sector satisfy a condition **Kind**: inner method of [LOOPS](#module_LOOPS) **Returns**: number - - Number of tiles that satisfy the condition | Param | Type | Description | | --- | --- | --- | | condition | function | The condition to check | ## convert ⇒ Array.<number> Converts between tile and sector coordinates. **Returns**: Array.<number> - - An array containing resultant coords | Param | Type | Description | | --- | --- | --- | | to_local_coords | boolean | Whether to convert to local coordinates or not | | x | number | X-coordinate of tile | | y | number | Y-coordinate of tile | | [s_x] | number | X-coordinate of sector if `x` is relative | | [s_y] | number | Y-coordinate of sector if `y` is relative | ## isMine ⇒ boolean Get the type of a tile (mine or not) deterministically. **Returns**: boolean - - Whether the tile is a mine or not | Param | Type | Description | | --- | --- | --- | | key | string | Key to use for hashing | | x | number | X-coordinate of the tile | | y | number | Y-coordinate of the tile | | [s_x] | number | X-coordinate of sector if `x` is relative | | [s_y] | number | Y-coordinate of sector if `y` is relative | ## game : GameController The game controller instance. **Kind**: global variable **Access**: public ## "DOMContentLoaded" **Kind**: event emitted