refactor: Routine(s) hold context

This commit is contained in:
cha0s 2019-04-08 18:42:14 -04:00
parent da728200c5
commit f09d03a30a
2 changed files with 22 additions and 2 deletions

View File

@ -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() {

View File

@ -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]);