refactor: explicit routine context
This commit is contained in:
parent
4f6869863c
commit
0a3e1848f4
|
@ -7,14 +7,9 @@ export class Routine {
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._context = undefined;
|
|
||||||
this.actions = new Actions();
|
this.actions = new Actions();
|
||||||
}
|
}
|
||||||
|
|
||||||
set context(context) {
|
|
||||||
this._context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
clone(other) {
|
clone(other) {
|
||||||
this.actions = other.actions.clone();
|
this.actions = other.actions.clone();
|
||||||
}
|
}
|
||||||
|
@ -24,8 +19,8 @@ export class Routine {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
tick(elapsed) {
|
tick(context, elapsed) {
|
||||||
this.actions.tick(this._context, elapsed);
|
this.actions.tick(context, elapsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
|
|
|
@ -7,7 +7,6 @@ export class Routines {
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._context = undefined;
|
|
||||||
this.routines = {};
|
this.routines = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,13 +17,6 @@ export class Routines {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
set context(context) {
|
|
||||||
this._context = context;
|
|
||||||
for (const routine of this) {
|
|
||||||
routine.context = context;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
clone(other) {
|
clone(other) {
|
||||||
for (const i in other.routines) {
|
for (const i in other.routines) {
|
||||||
const routine = other.routines[i];
|
const routine = other.routines[i];
|
||||||
|
|
|
@ -38,7 +38,6 @@ export class Behaved extends decorate(Trait) {
|
||||||
this._currentRoutine = undefined;
|
this._currentRoutine = undefined;
|
||||||
const routinesJSON = this.params.routines;
|
const routinesJSON = this.params.routines;
|
||||||
this._routines = (new Routines()).fromJSON(routinesJSON);
|
this._routines = (new Routines()).fromJSON(routinesJSON);
|
||||||
this._routines.context = this._context;
|
|
||||||
this.updateCurrentRoutine(this.state.currentRoutine);
|
this.updateCurrentRoutine(this.state.currentRoutine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +72,7 @@ export class Behaved extends decorate(Trait) {
|
||||||
tick(elapsed) {
|
tick(elapsed) {
|
||||||
if (AVOCADO_SERVER) {
|
if (AVOCADO_SERVER) {
|
||||||
if (this._currentRoutine && this.entity.isBehaving) {
|
if (this._currentRoutine && this.entity.isBehaving) {
|
||||||
this._currentRoutine.tick(elapsed);
|
this._currentRoutine.tick(this._context, elapsed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user