From a09b58b54c19673d3b699b069d0c7683053e27d3 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 7 Jan 2016 20:19:34 +0100 Subject: Simplify entity list --- src/control/MapContext.ts | 4 ++-- src/model/Position.ts | 4 ---- src/view/MapView.ts | 10 +++------- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/control/MapContext.ts b/src/control/MapContext.ts index ce82c5a..48e8b9e 100644 --- a/src/control/MapContext.ts +++ b/src/control/MapContext.ts @@ -15,7 +15,7 @@ import MapView from '../view/MapView'; export default class MapContext { view: MapView; - entities: {[key: string]: EntityPosition} = {}; + entities: EntityPosition[] = []; playerEntity: EntityPosition; @@ -42,7 +42,7 @@ export default class MapContext { } private addEntity(entity: EntityPosition) { - this.entities[entity.position.asString()] = entity; + this.entities.push(entity); } private addTransition(entity: EntityPosition, dest: Position, start: number, dur: number) { diff --git a/src/model/Position.ts b/src/model/Position.ts index 1f9b719..ebb3820 100644 --- a/src/model/Position.ts +++ b/src/model/Position.ts @@ -29,8 +29,4 @@ export default class Position { return p; } - - asString(): string { - return `${this.x},${this.y}`; - } } diff --git a/src/view/MapView.ts b/src/view/MapView.ts index 5523f81..230ecf3 100644 --- a/src/view/MapView.ts +++ b/src/view/MapView.ts @@ -75,7 +75,7 @@ export default class MapView { private entitySprites: {[key: string]: HTMLImageElement}; constructor(private map: MapData, - private entities: {[key: string]: EntityPosition}, + private entities: EntityPosition[], private origin: EntityPosition, private updateState: (time: number) => void) { this.canvas = document.createElement('canvas'); @@ -91,7 +91,7 @@ export default class MapView { this.tiles = tiles; }); - var entitiesReady = loadEntities(this.getEntities()).then((entities) => { + var entitiesReady = loadEntities(this.entities).then((entities) => { this.entitySprites = entities; }); @@ -100,10 +100,6 @@ export default class MapView { }); } - private getEntities(): EntityPosition[] { - return _.values(this.entities); - } - private setSize() { var e = document.documentElement; var w = window.innerWidth || e.clientWidth || body.clientWidth; @@ -197,7 +193,7 @@ export default class MapView { var animate = false; - this.getEntities().forEach(e => { + this.entities.forEach(e => { if (this.drawEntity(e, time)) animate = true; }); -- cgit v1.2.3