diff --git a/packages/topdown/index.js b/packages/topdown/index.js index f69c664..c1df9e8 100644 --- a/packages/topdown/index.js +++ b/packages/topdown/index.js @@ -1,5 +1,7 @@ export {Layer} from './layer'; export {LayerView} from './layer-view'; +export {Room} from './room'; +export {RoomView} from './room-view'; export {TilesRenderer} from './tiles-renderer'; export {Tiles} from './tiles'; export {Tileset} from './tileset'; diff --git a/packages/topdown/room-view.js b/packages/topdown/room-view.js new file mode 100644 index 0000000..f3fc4a4 --- /dev/null +++ b/packages/topdown/room-view.js @@ -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; + } + +} + diff --git a/packages/topdown/room.js b/packages/topdown/room.js new file mode 100644 index 0000000..33949d9 --- /dev/null +++ b/packages/topdown/room.js @@ -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); + } + +} \ No newline at end of file