refactor: explicit routine context

This commit is contained in:
cha0s 2019-09-08 08:18:16 -05:00
parent 4f6869863c
commit 0a3e1848f4
3 changed files with 3 additions and 17 deletions

View File

@ -7,14 +7,9 @@ export class Routine {
}
constructor() {
this._context = undefined;
this.actions = new Actions();
}
set context(context) {
this._context = context;
}
clone(other) {
this.actions = other.actions.clone();
}
@ -24,8 +19,8 @@ export class Routine {
return this;
}
tick(elapsed) {
this.actions.tick(this._context, elapsed);
tick(context, elapsed) {
this.actions.tick(context, elapsed);
}
toJSON() {

View File

@ -7,7 +7,6 @@ export class Routines {
}
constructor() {
this._context = undefined;
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) {
for (const i in other.routines) {
const routine = other.routines[i];

View File

@ -38,7 +38,6 @@ export class Behaved extends decorate(Trait) {
this._currentRoutine = undefined;
const routinesJSON = this.params.routines;
this._routines = (new Routines()).fromJSON(routinesJSON);
this._routines.context = this._context;
this.updateCurrentRoutine(this.state.currentRoutine);
}
@ -73,7 +72,7 @@ export class Behaved extends decorate(Trait) {
tick(elapsed) {
if (AVOCADO_SERVER) {
if (this._currentRoutine && this.entity.isBehaving) {
this._currentRoutine.tick(elapsed);
this._currentRoutine.tick(this._context, elapsed);
}
}
}