feat: loaded entities for list
This commit is contained in:
parent
85f52d5c57
commit
009e69ffd6
2
TODO.md
2
TODO.md
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user