Simplify entity list
This commit is contained in:
parent
f569eb788f
commit
a09b58b54c
3 changed files with 5 additions and 13 deletions
|
@ -15,7 +15,7 @@ import MapView from '../view/MapView';
|
||||||
export default class MapContext {
|
export default class MapContext {
|
||||||
view: MapView;
|
view: MapView;
|
||||||
|
|
||||||
entities: {[key: string]: EntityPosition} = {};
|
entities: EntityPosition[] = [];
|
||||||
playerEntity: EntityPosition;
|
playerEntity: EntityPosition;
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ export default class MapContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
private addEntity(entity: EntityPosition) {
|
private addEntity(entity: EntityPosition) {
|
||||||
this.entities[entity.position.asString()] = entity;
|
this.entities.push(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private addTransition(entity: EntityPosition, dest: Position, start: number, dur: number) {
|
private addTransition(entity: EntityPosition, dest: Position, start: number, dur: number) {
|
||||||
|
|
|
@ -29,8 +29,4 @@ export default class Position {
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
asString(): string {
|
|
||||||
return `${this.x},${this.y}`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ export default class MapView {
|
||||||
private entitySprites: {[key: string]: HTMLImageElement};
|
private entitySprites: {[key: string]: HTMLImageElement};
|
||||||
|
|
||||||
constructor(private map: MapData,
|
constructor(private map: MapData,
|
||||||
private entities: {[key: string]: EntityPosition},
|
private entities: EntityPosition[],
|
||||||
private origin: EntityPosition,
|
private origin: EntityPosition,
|
||||||
private updateState: (time: number) => void) {
|
private updateState: (time: number) => void) {
|
||||||
this.canvas = document.createElement('canvas');
|
this.canvas = document.createElement('canvas');
|
||||||
|
@ -91,7 +91,7 @@ export default class MapView {
|
||||||
this.tiles = tiles;
|
this.tiles = tiles;
|
||||||
});
|
});
|
||||||
|
|
||||||
var entitiesReady = loadEntities(this.getEntities()).then((entities) => {
|
var entitiesReady = loadEntities(this.entities).then((entities) => {
|
||||||
this.entitySprites = entities;
|
this.entitySprites = entities;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -100,10 +100,6 @@ export default class MapView {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private getEntities(): EntityPosition[] {
|
|
||||||
return _.values<EntityPosition>(this.entities);
|
|
||||||
}
|
|
||||||
|
|
||||||
private setSize() {
|
private setSize() {
|
||||||
var e = document.documentElement;
|
var e = document.documentElement;
|
||||||
var w = window.innerWidth || e.clientWidth || body.clientWidth;
|
var w = window.innerWidth || e.clientWidth || body.clientWidth;
|
||||||
|
@ -197,7 +193,7 @@ export default class MapView {
|
||||||
|
|
||||||
var animate = false;
|
var animate = false;
|
||||||
|
|
||||||
this.getEntities().forEach(e => {
|
this.entities.forEach(e => {
|
||||||
if (this.drawEntity(e, time))
|
if (this.drawEntity(e, time))
|
||||||
animate = true;
|
animate = true;
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue