feat: loaded entities for list

This commit is contained in:
cha0s 2019-05-16 23:01:57 -05:00
parent 85f52d5c57
commit 009e69ffd6
3 changed files with 18 additions and 4 deletions

View File

@ -17,7 +17,7 @@
- ✔ EventEmitter::emit is too hot
- ✔ Entity packets
- ✔ Decouple input normalization from action registry
- entityList.fromJSON()
- entityList.fromJSON()
- ❌ Socket WebWorker can't connect in Firefox
- ✔ Don't run emitter destruction tickers on server
- ✔ Investigate unrolling equalsClose

View File

@ -1,3 +1,5 @@
import merge from 'lodash.merge';
import {compose, EventEmitter} from '@avocado/core';
import {QuadTree, Rectangle, Vector} from '@avocado/math';
import {Synchronized} from '@avocado/state';
@ -75,6 +77,20 @@ export class EntityList extends decorate(class {}) {
}
}
fromJSON(json) {
for (let i = 0; i < json.length; i++) {
const entityJSON = json[i];
if ('undefined' !== entityJSON.uri) {
Entity.read(entityJSON.uri).then((readJSON) => {
this.addEntity(new Entity(merge(readJSON, entityJSON)));
});
}
else {
this.addEntity(new Entity(json[i]));
}
}
}
packetsForUpdate(force = false) {
const packets = [];
if (!force) {

View File

@ -104,9 +104,7 @@ export class Layer extends decorate(class {}) {
fromJSON(json) {
if (json.entities) {
for (let i = 0; i < json.entities.length; i++) {
this.entityList.addEntity(new Entity(json.entities[i]));
}
this.entityList.fromJSON(json.entities);
}
if (json.tiles) {
this.tiles.fromJSON(json.tiles)