diff --git a/app/ecs/component.js b/app/ecs/component.js index 0f00cc0..e6f9926 100644 --- a/app/ecs/component.js +++ b/app/ecs/component.js @@ -149,9 +149,12 @@ export default class Component { } } destroy() {} - toJSON() { + toNet() { return Component.constructor.filterDefaults(this); } + toJSON() { + return this.toNet(); + } }; const properties = {}; properties.entity = { diff --git a/app/ecs/entity-factory.js b/app/ecs/entity-factory.js index 243b421..007cf1d 100644 --- a/app/ecs/entity-factory.js +++ b/app/ecs/entity-factory.js @@ -48,6 +48,11 @@ export default class EntityFactory { ${sorted.map((type) => `${type}: this.${type}.toJSON()`).join(', ')} }; `); + Entity.prototype.toNet = new Function('', ` + return { + ${sorted.map((type) => `${type}: this.${type}.toNet()`).join(', ')} + }; + `); walk.class = Entity; } return walk.class; diff --git a/app/engine.js b/app/engine.js index 59268b8..bb825af 100644 --- a/app/engine.js +++ b/app/engine.js @@ -389,7 +389,7 @@ export default class Engine { const {id} = entity; lastNearby.delete(id); if (!memory.nearby.has(id)) { - update[id] = entity.toJSON(); + update[id] = entity.toNet(); if (mainEntityId === id) { update[id].MainEntity = {}; }