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; return false;
} }
setDirty() {
this._fastDirtyCheck = true;
this.entity._fastDirtyCheck = true;
}
stateDifferences() { stateDifferences() {
const differences = {}; const differences = {};
for (const key in this.state) { for (const key in this.state) {
@ -154,8 +159,7 @@ export function StateProperty(key, meta = {}) {
`); `);
meta.set = meta.set || new Function('value', ` meta.set = meta.set || new Function('value', `
if (value !== this.${transformedProperty}) { if (value !== this.${transformedProperty}) {
this._fastDirtyCheck = true; this.setDirty();
this.entity._fastDirtyCheck = true;
} }
this.${transformedProperty} = value; this.${transformedProperty} = value;
this.state['${key}'] = value; this.state['${key}'] = value;

View File

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