diff --git a/packages/behavior/item/routine.js b/packages/behavior/item/routine.js index 3cbe91d..48bff42 100644 --- a/packages/behavior/item/routine.js +++ b/packages/behavior/item/routine.js @@ -7,16 +7,21 @@ export class Routine { } constructor() { + this._context = undefined; this.actions = new Actions(); } + set context(context) { + this._context = context; + } + fromJSON(json) { this.actions.fromObject(json.actions); return this; } - tick(context, elapsed) { - this.actions.tick(context, elapsed); + tick(elapsed) { + this.actions.tick(this._context, elapsed); } toJSON() { diff --git a/packages/behavior/item/routines.js b/packages/behavior/item/routines.js index 236f283..eab4f87 100644 --- a/packages/behavior/item/routines.js +++ b/packages/behavior/item/routines.js @@ -7,9 +7,24 @@ export class Routines { } constructor() { + this._context = undefined; this.routines = {}; } + *[Symbol.iterator]() { + for (const index in this.routines) { + const routine = this.routines[index]; + yield routine; + } + } + + set context(context) { + this._context = context; + for (const routine of this) { + routine.context = context; + } + } + fromJSON(json) { for (const i in json.routines) { this.routines[i] = (new Routine()).fromJSON(json.routines[i]);