feat: tiles.state
This commit is contained in:
parent
5616f3275b
commit
55652c5d8f
|
@ -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];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user