refactor: setDirty

This commit is contained in:
cha0s 2019-10-16 01:09:34 -05:00
parent 68d67e082d
commit ee7608c211
2 changed files with 7 additions and 4 deletions

View File

@ -108,6 +108,11 @@ export class Trait extends decorate(class {}) {
return false;
}
setDirty() {
this._fastDirtyCheck = true;
this.entity._fastDirtyCheck = true;
}
stateDifferences() {
const differences = {};
for (const key in this.state) {
@ -154,8 +159,7 @@ export function StateProperty(key, meta = {}) {
`);
meta.set = meta.set || new Function('value', `
if (value !== this.${transformedProperty}) {
this._fastDirtyCheck = true;
this.entity._fastDirtyCheck = true;
this.setDirty();
}
this.${transformedProperty} = value;
this.state['${key}'] = value;

View File

@ -62,8 +62,7 @@ export class Positioned extends decorate(Trait) {
if (AVOCADO_SERVER) {
this.state.x = newPosition[0];
this.state.y = newPosition[1];
this.entity._fastDirtyCheck = true;
this._fastDirtyCheck = true;
this.setDirty();
}
this.entity.emit('positionChanged', oldPosition, newPosition);
}