From 55652c5d8f4ee59697a20c58150539f78e864647 Mon Sep 17 00:00:00 2001 From: cha0s Date: Wed, 27 Mar 2019 01:05:29 -0500 Subject: [PATCH] feat: tiles.state --- packages/topdown/tiles.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/topdown/tiles.js b/packages/topdown/tiles.js index f8e13c2..556f3cc 100644 --- a/packages/topdown/tiles.js +++ b/packages/topdown/tiles.js @@ -1,3 +1,5 @@ +import * as I from 'immutable'; + import {compose} from '@avocado/core'; import {Rectangle, Vector} from '@avocado/math'; @@ -9,6 +11,20 @@ const decorate = compose( class TilesBase { + constructor() { + this._sizeState = I.List(); + this._state = I.Map(); + } + + acceptStateChange(change) { + if (change.size) { + this.size = change.size; + } + if (change.data) { + this.data = change.data; + } + } + fromJSON(json) { if (json.size) { this.size = json.size; @@ -59,6 +75,17 @@ class TilesBase { return slice; } + get state() { + return this._state; + } + + tick(elapsed) { + this._sizeState = this._sizeState.set(0, this.width); + this._sizeState = this._sizeState.set(1, this.height); + this._state = this._state.set('size', this._sizeState); + this._state = this._state.set('data', this.data); + } + tileAt(x, y) { return this.data[y * this.width + x]; }