avocado-old/packages/topdown/room.js

35 lines
692 B
JavaScript
Raw Normal View History

2019-03-26 17:04:52 -05:00
import * as I from 'immutable';
import {Layer} from './layer';
export class Room {
constructor() {
this.layers = [];
this._layersState = I.Map();
this._state = I.Map();
}
fromJSON(json) {
if (json.layers) {
this.layers = json.layers.map((layerJSON) => {
return (new Layer()).fromJSON(layerJSON);
});
}
return this;
}
get state() {
return this._state;
}
tick(elapsed) {
for (let i = 0; i < this.layers.length; ++i) {
const layer = this.layers[i];
layer.tick(elapsed);
this._layersState = this._layersState.set(i, layer.state);
}
this._state = this._state.set('layers', this._layersState);
}
}