Logical grid data. GameGrid.setCell and GameGrid.setMatrix do not paint.
Call a View method when mounted nodes should catch up. GameGrid.getActiveCell /
GameGrid.getPreviousCell read matrix fields immediately and overlay current from refs.
Focus and history. Updates IState, fires callbacks and gridEventsEnum events, and highlights the active cell when rendered. Not a matrix write.
Mount, paint, and tear down markup. Optional — omit the constructor container and skip
GameGrid.render for headless use. GameGrid.refreshCells also writes the matrix
when cell is provided.
Authoritative IState. GameGrid.setStateSync runs middleware and does not emit
grid CustomEvents.
Runtime behaviour toggles. GameGrid.setOptions does not swap the matrix or re-render.
Viewport window and region tiles. Applying zoom rebuilds the visible window when mounted.
Cell at IState.activeCoords: matrix data (same source as GameGrid.getCell) plus mounted current / coords from refs when rendered.
After GameGrid.setCell, type and other data fields match the matrix immediately. The painted node on current stays stale until GameGrid.refreshCells / GameGrid.refresh.
Accumulate every ICell.type matching type scanning row-major from GameGrid.getMatrix.
Logical cell from GameGrid.getMatrix: matrix[coords[1]][coords[0]] — raw matrix lookup (bounds unchecked).
[x, y].
Logical matrix backing the grid (matrix[row][column] ⇒ matrix[y][x]).
Cell at IState.prevCoords: matrix data (same source as GameGrid.getCell) plus mounted current / coords from refs when rendered.
Replace the logical cell at coords (matrix[y][x]). Does not render, refresh, or patch DOM/refs.
[x, y].
Stored by reference, same as GameGrid.setMatrix.
Bounds unchecked, matching GameGrid.getCell. Data-only: does not patch DOM, refs, or emit events. Movement / blockOnType read the new cell immediately. Call GameGrid.refreshCells with { coords } (or { coords, cell } instead of this method) to update mounted nodes; use GameGrid.refresh / GameGrid.render when the grid shape changes.
Replace logical matrix reference; callers must GameGrid.refresh or GameGrid.render to reconcile DOM when mounted.
Headless grids also alias IRefsObject.cells to the new matrix so GameGrid.getActiveCell stays in sync.
Dispatches gridEventsEnum.MOVE_DOWN (with IMoveEventDetail) before GameGrid.setActiveCell.
Dispatches gridEventsEnum.MOVE_LEFT (with IMoveEventDetail) before GameGrid.setActiveCell.
Dispatches gridEventsEnum.MOVE_RIGHT (with IMoveEventDetail) before GameGrid.setActiveCell.
Walk to one cell, or along an explicit list of cells, through GameGrid.setActiveCell.
A single [x, y] or an array of [x, y] steps. Not pathfinding (no A*): gaps teleport.
Each step uses the existing block / collide / wrap / zoom-edge rules. Stops when a step does not land on the requested cell (blocked, finite-edge clamp, or wrap to a different cell). Skips steps that are already the active cell. Not rate-limited by IOptions.moveDebounce. Does not dispatch directional gridEventsEnum.MOVE_UP / MOVE_RIGHT / MOVE_DOWN / MOVE_LEFT (same as a cell click).
Directional move: invokes the onMove member of IOptions.callbacks → dispatches gridEventsEnum.MOVE_UP (with IMoveEventDetail) → GameGrid.setActiveCell.
Step back steps entries in IState.moves (default 1).
No-op when there is no earlier position, or steps is not a positive finite number.
Extra steps clamp to the oldest remaining entry. Not rate-limited by IOptions.moveDebounce.
Dispatches gridEventsEnum.REWIND (with detail.steps / detail.index plus IMoveEventDetail) then gridEventsEnum.MOVE_LAND.
Dropped coords are pushed onto IState.future so GameGrid.unrewind can replay them.
Jump to index in IState.moves (0 = oldest remaining).
No-op when index is not an integer in range, or it is already the current (last) entry.
Truncates history after the chosen index (later entries move to IState.future). Same events as GameGrid.rewind.
Move focus (x,y) when IOptions.blockOnType, IOptions.collideOnType, IOptions.moveOnType, and bounds/wrap rules allow.
Optionaldirection: stringDispatch order (subset may apply): gridEventsEnum.MOVE_BLOCKED if blocked; gridEventsEnum.MOVE_COLLISION when entering a collide-type cell; gridEventsEnum.MOVE_DETTACH when leaving a collide-type cell for a non-collide cell; ICell.eventTypes onExit then onEnter when the active cell changes; axis gridEventsEnum.WRAP_X / gridEventsEnum.WRAP_Y / gridEventsEnum.BOUNDARY_X / gridEventsEnum.BOUNDARY_Y; aggregate gridEventsEnum.WRAP / gridEventsEnum.BOUNDARY; finally gridEventsEnum.MOVE_LAND (pairs with the onLand member of IOptions.callbacks) only when the active cell actually changes. Move events carry IMoveEventDetail (from, to, direction, blocked). GameGrid.render does not call this method.
Replay steps entries from IState.future (default 1). Redo after GameGrid.rewind.
No-op when the forward stack is empty, or steps is not a positive finite number.
Extra steps clamp to the newest remaining future entry. Not rate-limited by IOptions.moveDebounce.
Dispatches gridEventsEnum.UNREWIND (with detail.steps / detail.index plus IMoveEventDetail) then gridEventsEnum.MOVE_LAND.
Jump forward to index in the combined trail (moves then future).
index is counted from the oldest remaining IState.moves entry (0), through the current cell, into IState.future.
No-op when index is not an integer strictly ahead of the current entry, or past the newest future coord.
Same events as GameGrid.unrewind.
After GameGrid.render, hydrated rows/cells and container. Headless grids mirror cells onto the logical matrix until mount.
Detach listeners when rendered and clear injected structure; resets rendered in state via GameGrid.setStateSync.
Idempotent-friendly: always dispatches gridEventsEnum.DESTROYED whether or not DOM was present. Middleware pre / post run for the rendered: false patch.
Tear down handlers, wipe container, rebuild rows/cells from GameGrid.getMatrix, reattach handlers.
Does not dispatch gridEventsEnum.RENDERED; that event is emitted from GameGrid.render. Honors IOptions.injectStyles the same way as GameGrid.render.
Write optional cell data and rebuild one or more cell nodes from the current matrix.
A single ICellRefresh or an array. cell is written with GameGrid.setCell when provided; omit it to re-render the existing matrix entry.
Flow: GameGrid.setCell is data-only (movement reads the new type immediately; DOM/refs stay stale). Call this afterward with { coords } to paint those tiles, or pass { coords, cell } to write and paint in one step. Headless grids update matrix data only. Off-screen cells under zoom stay current: null. Does not rebuild the whole grid — use GameGrid.refresh when dimensions or the zoom window change. Dispatches gridEventsEnum.CELLS_REFRESHED once with detail.cells.
Mount markup into container, wire keyboard/pointer handlers, and highlight the current active cell.
Clears/rebuilds refs for this mount. Prefer GameGrid.refresh after the first paint when rebuilding from the same host. Dispatches gridEventsEnum.RENDERED once the container is patched and listeners attach. Does not call GameGrid.setActiveCell — no move / collide / land / ICell.eventTypes events, and currentDirection is left as-is. Skips stylesheet injection when IOptions.injectStyles is false.
Apply partial state with MiddlewareFn pre (mutate patch) → merge → post.
Runtime toggles: input, collisions, middleware, callbacks, styling. Merged from ctor defaults and GameGrid.setOptions.
Snapshot merged IOptions — updates after GameGrid.setOptions.
Shallow-merge behaviours into IGameGrid.options without swapping the matrix snapshot or re-rendering.
Clear the zoom window. Dispatches gridEventsEnum.ZOOM_CLEARED.
Optionaloptions: IZoomOptionsIState.region or computed from the active cell when region tracking is enabled.
Compute zoom bounds for a fraction tile (divisions×divisions grid).
Compute zoom bounds for a quadrant (divisions === 2).
Region tile for coords; divisions defaults to IOptions.regionDivisions.
Optionaldivisions: numberCurrent zoom bounds or null when no zoom is active.
Compute zoom bounds around a center cell ± radii, clipped to the matrix.
OptionalradiusY: numberApply a zoom window in world coordinates.
Optionaloptions: IZoomOptionsClamps activeCoords into bounds when outside. Dispatches gridEventsEnum.ZOOM_SET.
Compute bounds then GameGrid.setZoom.
OptionalradiusY: numberOptionaloptions: IZoomOptionsCompute fraction bounds then GameGrid.setZoom.
Optionaloptions: IZoomOptionsCompute quadrant bounds then GameGrid.setZoom.
Optionaloptions: IZoomOptionsCopies matrix/config, merges IConfig.state, runs GameGrid.render when container is passed, then dispatches gridEventsEnum.CREATED.
Logical matrix plus optional IConfig.options / IConfig.state.
Optionalcontainer: HTMLElement
When provided, behaves like invoking GameGrid.render synchronously afterward.
Stateful 2‑D lattice with collision rules and optional HTMLElement projection.
Remarks
[x,y](matrix[y][x]).CustomEvents; IGameGridEventDetail describesdetail. Event names live on gridEventsEnum.Example: Render + keyboard handlers
Example: Headless state machine without calling render