fix: previous optimizations broke entity remembering
This commit is contained in:
parent
773fd2a519
commit
9dc58f78f1
|
@ -49,34 +49,35 @@ export class Informed extends decorate(Trait) {
|
|||
});
|
||||
}
|
||||
|
||||
entityStepFilter(op) {
|
||||
entityStepFilter(op, invert) {
|
||||
return (step) => {
|
||||
if (op !== step.get('op')) {
|
||||
return;
|
||||
return invert;
|
||||
}
|
||||
const parts = step.get('parts');
|
||||
if (6 !== parts.length) {
|
||||
return false;
|
||||
return invert;
|
||||
}
|
||||
if ('room' !== parts[1]) {
|
||||
return false;
|
||||
return invert;
|
||||
}
|
||||
if ('layers' !== parts[2]) {
|
||||
return false;
|
||||
return invert;
|
||||
}
|
||||
if ('entityList' !== parts[4]) {
|
||||
return false;
|
||||
return invert;
|
||||
}
|
||||
return true;
|
||||
return !invert;
|
||||
};
|
||||
}
|
||||
|
||||
rewriteEntityAdds(state, steps) {
|
||||
return steps.withMutations((steps) => {
|
||||
const filter = this.entityStepFilter('add');
|
||||
const adds = steps.map((step) => {
|
||||
return step.set('parts', step.get('path').split('/'));
|
||||
}).filter(filter);
|
||||
steps = steps.map((step) => {
|
||||
return step.set('parts', step.get('path').split('/'));
|
||||
});
|
||||
const isAdd = this.entityStepFilter('add', false);
|
||||
const adds = steps.filter(isAdd);
|
||||
steps = steps.withMutations((steps) => {
|
||||
const iterator = adds.values();
|
||||
for (const add of iterator) {
|
||||
// Remember the entity.
|
||||
|
@ -87,7 +88,6 @@ export class Informed extends decorate(Trait) {
|
|||
continue;
|
||||
}
|
||||
const rememberedEntity = this._rememberedEntities[uuid];
|
||||
delete this._rememberedEntities[uuid];
|
||||
// Take a diff from what the client remembers to now.
|
||||
const currentState = state.getIn(
|
||||
['room', 'layers', layerId, 'entityList', uuid]
|
||||
|
@ -99,25 +99,41 @@ export class Informed extends decorate(Trait) {
|
|||
});
|
||||
steps.concat(fullAddSteps);
|
||||
// Add overrides.
|
||||
steps.concat(this.entityOverrides(add.get('path'), (path) => {
|
||||
return rememberedEntity.getIn(path);
|
||||
}));
|
||||
}
|
||||
for (const add of iterator) {
|
||||
// Remove adds.
|
||||
steps.splice(steps.indexOf(add), 1);
|
||||
const overrides = this.entityOverrides(
|
||||
add.get('path'),
|
||||
(path) => rememberedEntity.getIn(path),
|
||||
);
|
||||
for (let i = 0; i < overrides.size; ++i) {
|
||||
steps.push(overrides.get(i));
|
||||
}
|
||||
}
|
||||
});
|
||||
// Filter adds for remembered entities.
|
||||
steps = steps.filter((step) => {
|
||||
if (!isAdd(step)) {
|
||||
return true;
|
||||
}
|
||||
const parts = step.get('parts');
|
||||
const uuid = parts[5];
|
||||
return !(uuid in this._rememberedEntities);
|
||||
});
|
||||
// Forget all remembered entities.
|
||||
adds.forEach((step) => {
|
||||
const parts = step.get('parts');
|
||||
const uuid = parts[5];
|
||||
delete this._rememberedEntities[uuid];
|
||||
});
|
||||
return steps;
|
||||
}
|
||||
|
||||
rewriteEntityRemovals(state, steps) {
|
||||
return steps.withMutations((steps) => {
|
||||
const filter = this.entityStepFilter('remove');
|
||||
const removals = steps.map((step) => {
|
||||
return step.set('parts', step.get('path').split('/'));
|
||||
}).filter(filter);
|
||||
const iterator = removals.values();
|
||||
for (const removal of iterator) {
|
||||
steps = steps.map((step) => {
|
||||
return step.set('parts', step.get('path').split('/'));
|
||||
});
|
||||
const isRemove = this.entityStepFilter('remove', false);
|
||||
const removals = steps.filter(isRemove);
|
||||
steps = steps.withMutations((steps) => {
|
||||
for (const removal of removals.values()) {
|
||||
// Remember the entity.
|
||||
const parts = removal.get('parts');
|
||||
const layerId = parts[3];
|
||||
|
@ -126,13 +142,19 @@ export class Informed extends decorate(Trait) {
|
|||
['room', 'layers', layerId, 'entityList', uuid]
|
||||
);
|
||||
// Add overrides.
|
||||
steps.concat(this.entityOverrides(removal.get('path'), () => false));
|
||||
}
|
||||
for (const removal of iterator) {
|
||||
// Remove removals.
|
||||
steps.splice(steps.indexOf(removal), 1);
|
||||
const overrides = this.entityOverrides(
|
||||
removal.get('path'),
|
||||
() => false
|
||||
);
|
||||
for (let i = 0; i < overrides.size; ++i) {
|
||||
steps.push(overrides.get(i));
|
||||
}
|
||||
}
|
||||
});
|
||||
// Remove all removes.
|
||||
return steps.filter((step) => {
|
||||
return !isRemove(step);
|
||||
});
|
||||
}
|
||||
|
||||
reduceState(state) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user