35 lines
692 B
JavaScript
35 lines
692 B
JavaScript
|
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);
|
||
|
}
|
||
|
|
||
|
}
|