refactor: explicit routine context
This commit is contained in:
parent
4f6869863c
commit
0a3e1848f4
|
@ -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() {
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user