refactor: Routine(s) hold context
This commit is contained in:
parent
da728200c5
commit
f09d03a30a
|
@ -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() {
|
||||
|
|
|
@ -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]);
|
||||
|
|
Loading…
Reference in New Issue
Block a user