diff --git a/packages/behavior/context/context.hooks.js b/packages/behavior/context/context.hooks.js index 499a3e7..499d976 100644 --- a/packages/behavior/context/context.hooks.js +++ b/packages/behavior/context/context.hooks.js @@ -2,24 +2,32 @@ import {Context} from './context'; export function behaviorContextTypes() { return { - bool: {}, + bool: { + defaultLiteral: true, + }, context: { - add: { - type: 'void', - label: 'Add $2 as $1.', - args: [ - ['key', { - type: 'string', - }], - ['value', { - type: 'any', - }], - ], + children: { + add: { + type: 'void', + label: 'Add $2 as $1.', + args: [ + ['key', { + type: 'string', + }], + ['value', { + type: 'any', + }], + ], + }, }, }, - number: {}, + number: { + defaultLiteral: 0, + }, stream: {}, - string: {}, + string: { + defaultLiteral: '', + }, void: {}, }; } diff --git a/packages/behavior/context/context.js b/packages/behavior/context/context.js index 6dd24b2..e6533b1 100644 --- a/packages/behavior/context/context.js +++ b/packages/behavior/context/context.js @@ -60,7 +60,7 @@ export class Context { } const description = this.typeDescription(type, undefined); const subtypes = Object.keys( - Object.values(description) + Object.values(description.children) .reduce((r, spec) => ({...r, [spec.type]: true}), {}) ); subtypes.forEach((type) => marked[type] = true); @@ -78,15 +78,18 @@ export class Context { if (!types[type]) { return {}; } - if ('function' === typeof types[type]) { - return types[type](variable); - } - return types[type]; + return { + children: {}, + ...('function' === typeof types[type] ? types[type](variable) : types[type]) + }; } static types() { return invokeHookFlat('behaviorContextTypes') - .reduce((r, results) => ({...r, ...results}), {}); + .reduce((r, results) => ({ + ...r, + ...results, + }), {}); } add(key, value, type) { diff --git a/packages/behavior/context/flow.hooks.js b/packages/behavior/context/flow.hooks.js index 4abf8a3..0a407b9 100644 --- a/packages/behavior/context/flow.hooks.js +++ b/packages/behavior/context/flow.hooks.js @@ -27,35 +27,37 @@ export function behaviorContextGlobals() { export function behaviorContextTypes() { return { Flow: { - conditional: { - type: 'bool', - label: 'If $1 then run $2.', - args: [ - ['condition', { - type: 'condition', - }], - ['actions', { - type: 'actions', - }], - ], - }, - parallel: { - type: 'void', - label: 'Run $1 in parallel.', - args: [ - ['actions', { - type: 'actions', - }], - ], - }, - serial: { - type: 'void', - label: 'Run $1 serially.', - args: [ - ['actions', { - type: 'actions', - }], - ], + children: { + conditional: { + type: 'bool', + label: 'If $1 then run $2.', + args: [ + ['condition', { + type: 'condition', + }], + ['actions', { + type: 'actions', + }], + ], + }, + parallel: { + type: 'void', + label: 'Run $1 in parallel.', + args: [ + ['actions', { + type: 'actions', + }], + ], + }, + serial: { + type: 'void', + label: 'Run $1 serially.', + args: [ + ['actions', { + type: 'actions', + }], + ], + }, }, }, }; diff --git a/packages/behavior/context/timing.hooks.js b/packages/behavior/context/timing.hooks.js index fb4695f..41db66b 100644 --- a/packages/behavior/context/timing.hooks.js +++ b/packages/behavior/context/timing.hooks.js @@ -19,14 +19,16 @@ class Timing { export function behaviorContextTypes() { return { Timing: { - wait: { - type: 'void', - label: 'Wait for $1 seconds.', - args: [ - ['duration', { - type: 'number', - }], - ], + children: { + wait: { + type: 'void', + label: 'Wait for $1 seconds.', + args: [ + ['duration', { + type: 'number', + }], + ], + }, }, }, }; diff --git a/packages/behavior/context/utility.hooks.js b/packages/behavior/context/utility.hooks.js index 9f3a581..637687c 100644 --- a/packages/behavior/context/utility.hooks.js +++ b/packages/behavior/context/utility.hooks.js @@ -35,25 +35,27 @@ class Utility { export function behaviorContextTypes() { return { Utility: { - makeArray: { - type: 'array', - label: 'Make array.', - args: [], - }, - makeObject: { - type: 'object', - label: 'Make object.', - args: [], - }, - log: { - type: 'void', - label: 'Log.', - args: [], - }, - merge: { - type: 'object', - label: 'Merge objects.', - args: [], + children: { + makeArray: { + type: 'array', + label: 'Make array.', + args: [], + }, + makeObject: { + type: 'object', + label: 'Make object.', + args: [], + }, + log: { + type: 'void', + label: 'Log.', + args: [], + }, + merge: { + type: 'object', + label: 'Merge objects.', + args: [], + }, }, }, }; diff --git a/packages/entity/index.hooks.js b/packages/entity/index.hooks.js index 4b672d1..9be6490 100644 --- a/packages/entity/index.hooks.js +++ b/packages/entity/index.hooks.js @@ -5,24 +5,23 @@ export function behaviorContextTypes() { const Traits = entity ? Object.values(entity.allTraitInstances()).map((instance) => instance.constructor) : allTraits(); - const traitTypes = Traits - .reduce((r, {behaviorContextTypes, describeState}) => ({ - ...r, - ...behaviorContextTypes(), - ...describeState(), - }), {}); - return { - ...traitTypes, - invokeHook: { - type: 'object', - label: 'Invoke hook.', - args: [ - ['hook', { - type: 'string', - }], - ], - }, + const core = { + children: { + invokeHook: { + type: 'object', + label: 'Invoke hook.', + args: [ + ['hook', { + type: 'string', + }], + ], + }, + } }; + return Traits + .reduce((r, T) => ({ + ...r, children: {...r.children, ...T.behaviorContextTypes(), ...T.describeState()}, + }), core); }, }; } diff --git a/packages/math/index.hooks.js b/packages/math/index.hooks.js index 6b90766..594dd99 100644 --- a/packages/math/index.hooks.js +++ b/packages/math/index.hooks.js @@ -9,30 +9,32 @@ export function behaviorContextGlobals() { export function behaviorContextTypes() { return { Math: (Math) => ({ - floor: { - type: 'number', - label: 'Floor $1.', - args: [ - ['operand', { - type: 'number', - }], - ], - }, - randomNumber: { - type: 'number', - label: 'Random number between $1 and $2.', - args: [ - ['min', { - type: 'number', - }], - ['max', { - type: 'number', - }], - ], - }, - Vector: { - type: 'Vector', - }, + children: { + floor: { + type: 'number', + label: 'Floor $1.', + args: [ + ['operand', { + type: 'number', + }], + ], + }, + randomNumber: { + type: 'number', + label: 'Random number between $1 and $2.', + args: [ + ['min', { + type: 'number', + }], + ['max', { + type: 'number', + }], + ], + }, + Vector: { + type: 'Vector', + }, + } }), }; } diff --git a/packages/math/vector/index.hooks.js b/packages/math/vector/index.hooks.js index 60b29d7..1b7155e 100644 --- a/packages/math/vector/index.hooks.js +++ b/packages/math/vector/index.hooks.js @@ -1,35 +1,50 @@ export function behaviorContextTypes() { return { + vector: { + defaultLiteral: [0, 0], + children: { + x: { + type: 'number', + label: 'X', + }, + y: { + type: 'number', + label: 'Y', + }, + }, + }, Vector: (Math) => ({ - floor: { - type: 'vector', - label: 'Floor $1.', - args: [ - ['vector', { - type: 'vector', - }], - ], - }, - fromDirection: { - type: 'vector', - label: '$1 as a movement vector.', - args: [ - ['direction', { - type: 'number', - }], - ], - }, - sub: { - type: 'vector', - label: 'Subtract $2 from $1.', - args: [ - ['l', { - type: 'vector', - }], - ['r', { - type: 'vector', - }], - ], + children: { + floor: { + type: 'vector', + label: 'Floor $1.', + args: [ + ['vector', { + type: 'vector', + }], + ], + }, + fromDirection: { + type: 'vector', + label: '$1 as a movement vector.', + args: [ + ['direction', { + type: 'number', + }], + ], + }, + sub: { + type: 'vector', + label: 'Subtract $2 from $1.', + args: [ + ['l', { + type: 'vector', + }], + ['r', { + type: 'vector', + }], + ], + }, }, }), };