From 0a3e1848f4121d82d34faf650cab31a0bde7a3f8 Mon Sep 17 00:00:00 2001 From: cha0s Date: Sun, 8 Sep 2019 08:18:16 -0500 Subject: [PATCH] refactor: explicit routine context --- packages/behavior/item/routine.js | 9 ++------- packages/behavior/item/routines.js | 8 -------- packages/behavior/traits/behaved.trait.js | 3 +-- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/packages/behavior/item/routine.js b/packages/behavior/item/routine.js index 9fcb675..a9f9b73 100644 --- a/packages/behavior/item/routine.js +++ b/packages/behavior/item/routine.js @@ -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() { diff --git a/packages/behavior/item/routines.js b/packages/behavior/item/routines.js index 5f04bae..8337926 100644 --- a/packages/behavior/item/routines.js +++ b/packages/behavior/item/routines.js @@ -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]; diff --git a/packages/behavior/traits/behaved.trait.js b/packages/behavior/traits/behaved.trait.js index 3ce5f30..679407f 100644 --- a/packages/behavior/traits/behaved.trait.js +++ b/packages/behavior/traits/behaved.trait.js @@ -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); } } }