feat: hook type hints

This commit is contained in:
cha0s 2020-06-22 04:25:58 -05:00
parent de5957fd05
commit 3db24756d3

View File

@ -1,4 +1,4 @@
import {compose} from '@avocado/core'; import {compose, flatten} from '@avocado/core';
import {StateProperty, Trait} from '@avocado/entity'; import {StateProperty, Trait} from '@avocado/entity';
import {Context} from '../context'; import {Context} from '../context';
@ -24,7 +24,6 @@ export default class Behaved extends decorate(Trait) {
static defaultParams() { static defaultParams() {
return { return {
contextTypeHints: {},
routines: {}, routines: {},
}; };
} }
@ -38,10 +37,6 @@ export default class Behaved extends decorate(Trait) {
static describeParams() { static describeParams() {
return { return {
contextTypeHints: {
type: 'object',
label: 'Context type hints',
},
routines: { routines: {
type: 'routines', type: 'routines',
label: 'Routines', label: 'Routines',
@ -71,8 +66,6 @@ export default class Behaved extends decorate(Trait) {
this._context = new Context({ this._context = new Context({
entity: [this.entity, 'entity'], entity: [this.entity, 'entity'],
}); });
Object.entries(this.params.contextTypeHints)
.forEach(([key, type]) => this._context.add(key, undefined, type));
this._currentRoutine = undefined; this._currentRoutine = undefined;
this._routines = (new Routines()).fromJSON(this.params.routines); this._routines = (new Routines()).fromJSON(this.params.routines);
this.updateCurrentRoutine(this.state.currentRoutine); this.updateCurrentRoutine(this.state.currentRoutine);
@ -103,6 +96,12 @@ export default class Behaved extends decorate(Trait) {
this.entity.isBehaving = !isDying; this.entity.isBehaving = !isDying;
}, },
traitAdded: (type) => {
console.log(flatten(this.entity.invokeHookFlat('contextTypeHints')))
flatten(this.entity.invokeHookFlat('contextTypeHints'))
.forEach(([key, type]) => this._context.add(key, undefined, type));
},
}; };
} }