feat: layer & layerView
This commit is contained in:
parent
af143670cc
commit
750730eda6
|
@ -1,3 +1,5 @@
|
|||
export {Layer} from './layer';
|
||||
export {LayerView} from './layer-view';
|
||||
export {TilesRenderer} from './tiles-renderer';
|
||||
export {Tiles} from './tiles';
|
||||
export {Tileset} from './tileset';
|
||||
|
|
30
packages/topdown/layer-view.js
Normal file
30
packages/topdown/layer-view.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
import {Container, Renderable, Sprite} from '@avocado/graphics';
|
||||
import {Layer, Tileset, TilesRenderer} from '@avocado/topdown';
|
||||
|
||||
export class LayerView extends Renderable {
|
||||
|
||||
constructor(layer, renderer) {
|
||||
super();
|
||||
this.container = new Container();
|
||||
this.layer = layer;
|
||||
this._renderer = renderer;
|
||||
this._tileset = undefined;
|
||||
Tileset.load(layer.tilesetUri).then((tileset) => {
|
||||
this.tileset = tileset;
|
||||
});
|
||||
}
|
||||
|
||||
get internal() {
|
||||
return this.container.internal;
|
||||
}
|
||||
|
||||
set tileset(tileset) {
|
||||
this._tileset = tileset;
|
||||
const tilesRenderer = new TilesRenderer(this.layer.tiles, tileset);
|
||||
const chunk = tilesRenderer.renderChunk(this._renderer);
|
||||
const tilesSprite = new Sprite(chunk);
|
||||
this.container.removeAllChildren();
|
||||
this.container.addChild(tilesSprite);
|
||||
}
|
||||
|
||||
}
|
21
packages/topdown/layer.js
Normal file
21
packages/topdown/layer.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
import {Tiles} from '@avocado/topdown';
|
||||
|
||||
export class Layer {
|
||||
|
||||
constructor() {
|
||||
this.tiles = undefined;
|
||||
this.tilesetUri = undefined;
|
||||
this.entityList = undefined;
|
||||
}
|
||||
|
||||
fromJSON(json) {
|
||||
if (json.tiles) {
|
||||
this.tiles = (new Tiles()).fromJSON(json.tiles)
|
||||
}
|
||||
if (json.tilesetUri) {
|
||||
this.tilesetUri = json.tilesetUri;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user