refactor: path overrides

This commit is contained in:
cha0s 2019-04-12 00:36:44 -05:00
parent 4755d78534
commit 07ef995e34

View File

@ -82,21 +82,18 @@ export class Informed extends decorate(Trait) {
// Swap out the removal op for replaces to hide the entity.
const index = steps.indexOf(entityRemoval);
steps.splice(index, 1);
steps.push({
op: 'replace',
path: entityRemoval.path + '/existent/state/isTicking',
value: false,
});
steps.push({
op: 'replace',
path: entityRemoval.path + '/physical/state/addedToPhysics',
value: false,
});
steps.push({
op: 'replace',
path: entityRemoval.path + '/graphical/state/isVisible',
value: false,
});
const pathOverrides = [
['existent', 'state', 'isTicking'],
['physical', 'state', 'addedToPhysics'],
['graphical', 'state', 'isVisible'],
]
for (const pathOverride of pathOverrides) {
steps.push({
op: 'replace',
path: entityRemoval.path + '/' + pathOverride.join('/'),
value: false,
});
}
}
// Rewrite entity adds.
const entityAdds = steps.filter((step) => {
@ -112,9 +109,10 @@ export class Informed extends decorate(Trait) {
if (!(uuid in this._rememberedEntities)) {
continue;
}
const rememberedEntity = this._rememberedEntities[uuid];
const currentState = state.getIn(parts);
const addSteps = immutablediff(
this._rememberedEntities[uuid],
rememberedEntity,
currentState,
).toJS();
const fullAddSteps = addSteps.map((addStep) => {
@ -128,21 +126,18 @@ export class Informed extends decorate(Trait) {
const index = steps.indexOf(entityAdd);
steps.splice(index, 1);
steps.push(...fullAddSteps);
steps.push({
op: 'replace',
path: entityAdd.path + '/existent/state/isTicking',
value: true,
});
steps.push({
op: 'replace',
path: entityAdd.path + '/physical/state/addedToPhysics',
value: true,
});
steps.push({
op: 'replace',
path: entityAdd.path + '/graphical/state/isVisible',
value: true,
});
const pathOverrides = [
['existent', 'state', 'isTicking'],
['physical', 'state', 'addedToPhysics'],
['graphical', 'state', 'isVisible'],
]
for (const pathOverride of pathOverrides) {
steps.push({
op: 'replace',
path: entityAdd.path + '/' + pathOverride.join('/'),
value: rememberedEntity.getIn(pathOverride),
});
}
delete this._rememberedEntities[uuid];
}
// Remember state.