feat: tiles.state

This commit is contained in:
cha0s 2019-03-27 01:05:29 -05:00
parent 5616f3275b
commit 55652c5d8f

View File

@ -1,3 +1,5 @@
import * as I from 'immutable';
import {compose} from '@avocado/core'; import {compose} from '@avocado/core';
import {Rectangle, Vector} from '@avocado/math'; import {Rectangle, Vector} from '@avocado/math';
@ -9,6 +11,20 @@ const decorate = compose(
class TilesBase { 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) { fromJSON(json) {
if (json.size) { if (json.size) {
this.size = json.size; this.size = json.size;
@ -59,6 +75,17 @@ class TilesBase {
return slice; 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) { tileAt(x, y) {
return this.data[y * this.width + x]; return this.data[y * this.width + x];
} }