refactor: toNet

This commit is contained in:
cha0s 2024-07-13 00:33:41 -05:00
parent 5365608f9f
commit 03035ec8b6
3 changed files with 10 additions and 2 deletions

View File

@ -149,9 +149,12 @@ export default class Component {
}
}
destroy() {}
toJSON() {
toNet() {
return Component.constructor.filterDefaults(this);
}
toJSON() {
return this.toNet();
}
};
const properties = {};
properties.entity = {

View File

@ -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;

View File

@ -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 = {};
}