refactor: entity updates
This commit is contained in:
parent
70edcc04de
commit
a0f6ca9056
|
@ -12,22 +12,22 @@ export default function Entities({camera, scale}) {
|
|||
if (!ecs) {
|
||||
return;
|
||||
}
|
||||
const updatedEntities = {...entities};
|
||||
const deleting = {};
|
||||
const updating = {};
|
||||
for (const id in payload) {
|
||||
if ('1' === id) {
|
||||
continue;
|
||||
}
|
||||
const update = payload[id];
|
||||
if (false === update) {
|
||||
delete updatedEntities[id];
|
||||
deleting[id] = true;
|
||||
continue;
|
||||
}
|
||||
updatedEntities[id] = ecs.get(id);
|
||||
updating[id] = ecs.get(id);
|
||||
const {dialogue} = update.Interlocutor || {};
|
||||
if (dialogue) {
|
||||
const {dialogues} = updatedEntities[id].Interlocutor;
|
||||
const {dialogues} = updating[id].Interlocutor;
|
||||
for (const key in dialogue) {
|
||||
updatedEntities[id] = ecs.rebuild(id);
|
||||
dialogues[key] = dialogue[key];
|
||||
dialogues[key].letters = parseLetters(dialogues[key].body);
|
||||
dialogues[key].onClose = () => {
|
||||
|
@ -40,8 +40,16 @@ export default function Entities({camera, scale}) {
|
|||
}
|
||||
}
|
||||
}
|
||||
setEntities(updatedEntities);
|
||||
}, [ecs, entities]);
|
||||
setEntities((entities) => {
|
||||
for (const id in deleting) {
|
||||
delete entities[id];
|
||||
}
|
||||
return {
|
||||
...entities,
|
||||
...updating,
|
||||
};
|
||||
});
|
||||
}, [ecs]);
|
||||
const renderables = [];
|
||||
for (const id in entities) {
|
||||
renderables.push(
|
||||
|
|
|
@ -26,31 +26,44 @@ export default function Entities({filters}) {
|
|||
if (!ecs) {
|
||||
return;
|
||||
}
|
||||
const updatedEntities = {...entities};
|
||||
const deleting = {};
|
||||
const updating = {};
|
||||
for (const id in payload) {
|
||||
if ('1' === id) {
|
||||
continue;
|
||||
}
|
||||
const update = payload[id];
|
||||
if (false === update) {
|
||||
delete updatedEntities[id];
|
||||
deleting[id] = true;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
updatedEntities[id] = ecs.get(id);
|
||||
if (update.Emitter?.emit) {
|
||||
updatedEntities[id].Emitter.emitting = {
|
||||
...updatedEntities[id].Emitter.emitting,
|
||||
...update.Emitter.emit,
|
||||
};
|
||||
}
|
||||
updating[id] = ecs.get(id);
|
||||
if (update.Emitter?.emit) {
|
||||
updating[id].Emitter.emitting = {
|
||||
...updating[id].Emitter.emitting,
|
||||
...update.Emitter.emit,
|
||||
};
|
||||
}
|
||||
}
|
||||
setEntities(updatedEntities);
|
||||
setEntities((entities) => {
|
||||
for (const id in deleting) {
|
||||
delete entities[id];
|
||||
}
|
||||
return {
|
||||
...entities,
|
||||
...updating,
|
||||
};
|
||||
});
|
||||
}, [ecs]);
|
||||
useEcsTick(() => {
|
||||
if (!ecs) {
|
||||
return;
|
||||
}
|
||||
const main = ecs.get(mainEntity);
|
||||
if (main) {
|
||||
setWillInteractWith(main.Interacts.willInteractWith);
|
||||
}
|
||||
}, [ecs, entities, mainEntity]);
|
||||
}, [ecs, mainEntity]);
|
||||
useEffect(() => {
|
||||
setRadians(0);
|
||||
const handle = setInterval(() => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user