feat: Room

This commit is contained in:
cha0s 2019-03-26 17:04:52 -05:00
parent 90a5bed2a8
commit 43dec37764
3 changed files with 60 additions and 0 deletions

View File

@ -1,5 +1,7 @@
export {Layer} from './layer'; export {Layer} from './layer';
export {LayerView} from './layer-view'; export {LayerView} from './layer-view';
export {Room} from './room';
export {RoomView} from './room-view';
export {TilesRenderer} from './tiles-renderer'; export {TilesRenderer} from './tiles-renderer';
export {Tiles} from './tiles'; export {Tiles} from './tiles';
export {Tileset} from './tileset'; export {Tileset} from './tileset';

View File

@ -0,0 +1,23 @@
import {Container, Renderable} from '@avocado/graphics';
import {LayerView} from './layer-view';
export class RoomView extends Renderable {
constructor(room, renderer) {
super();
this.container = new Container();
this.room = room;
if (room.layers) {
room.layers.forEach((layer) => {
this.container.addChild(new LayerView(layer, renderer));
});
}
}
get internal() {
return this.container.internal;
}
}

35
packages/topdown/room.js Normal file
View File

@ -0,0 +1,35 @@
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);
}
}