flow: track current routine, isBehaving property, only behave on server
This commit is contained in:
parent
da941e0e39
commit
8aa6631b03
|
@ -5,7 +5,10 @@ import {createContext} from '../context';
|
||||||
import {Routines} from '../item/routines';
|
import {Routines} from '../item/routines';
|
||||||
|
|
||||||
const decorate = compose(
|
const decorate = compose(
|
||||||
StateProperty('currentRoutine'),
|
StateProperty('currentRoutine', {
|
||||||
|
track: true,
|
||||||
|
}),
|
||||||
|
StateProperty('isBehaving'),
|
||||||
);
|
);
|
||||||
|
|
||||||
export class Behaved extends decorate(Trait) {
|
export class Behaved extends decorate(Trait) {
|
||||||
|
@ -19,6 +22,7 @@ export class Behaved extends decorate(Trait) {
|
||||||
static defaultState() {
|
static defaultState() {
|
||||||
return {
|
return {
|
||||||
currentRoutine: 'initial',
|
currentRoutine: 'initial',
|
||||||
|
isBehaving: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +35,6 @@ export class Behaved extends decorate(Trait) {
|
||||||
this._context = createContext();
|
this._context = createContext();
|
||||||
this._context.add('entity', this.entity);
|
this._context.add('entity', this.entity);
|
||||||
this._currentRoutine = undefined;
|
this._currentRoutine = undefined;
|
||||||
this._isBehaving = true;
|
|
||||||
const routinesJSON = this.params.routines;
|
const routinesJSON = this.params.routines;
|
||||||
this._routines = (new Routines()).fromJSON(routinesJSON);
|
this._routines = (new Routines()).fromJSON(routinesJSON);
|
||||||
this._routines.context = this._context;
|
this._routines.context = this._context;
|
||||||
|
@ -48,10 +51,6 @@ export class Behaved extends decorate(Trait) {
|
||||||
return this._context;
|
return this._context;
|
||||||
}
|
}
|
||||||
|
|
||||||
set isBehaving(isBehaving) {
|
|
||||||
this._isBehaving = isBehaving;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateCurrentRoutine(currentRoutine) {
|
updateCurrentRoutine(currentRoutine) {
|
||||||
this._currentRoutine = this._routines.routine(currentRoutine);
|
this._currentRoutine = this._routines.routine(currentRoutine);
|
||||||
}
|
}
|
||||||
|
@ -64,15 +63,17 @@ export class Behaved extends decorate(Trait) {
|
||||||
},
|
},
|
||||||
|
|
||||||
dying: () => {
|
dying: () => {
|
||||||
this._isBehaving = false;
|
this.entity.isBehaving = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
tick(elapsed) {
|
tick(elapsed) {
|
||||||
if (this._currentRoutine && this._isBehaving) {
|
if (AVOCADO_SERVER) {
|
||||||
this._currentRoutine.tick(elapsed);
|
if (this._currentRoutine && this.entity.isBehaving) {
|
||||||
|
this._currentRoutine.tick(elapsed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user