refactor: children
This commit is contained in:
parent
a85a984374
commit
1650ccddcc
|
@ -2,24 +2,32 @@ import {Context} from './context';
|
||||||
|
|
||||||
export function behaviorContextTypes() {
|
export function behaviorContextTypes() {
|
||||||
return {
|
return {
|
||||||
bool: {},
|
bool: {
|
||||||
|
defaultLiteral: true,
|
||||||
|
},
|
||||||
context: {
|
context: {
|
||||||
add: {
|
children: {
|
||||||
type: 'void',
|
add: {
|
||||||
label: 'Add $2 as $1.',
|
type: 'void',
|
||||||
args: [
|
label: 'Add $2 as $1.',
|
||||||
['key', {
|
args: [
|
||||||
type: 'string',
|
['key', {
|
||||||
}],
|
type: 'string',
|
||||||
['value', {
|
}],
|
||||||
type: 'any',
|
['value', {
|
||||||
}],
|
type: 'any',
|
||||||
],
|
}],
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
number: {},
|
number: {
|
||||||
|
defaultLiteral: 0,
|
||||||
|
},
|
||||||
stream: {},
|
stream: {},
|
||||||
string: {},
|
string: {
|
||||||
|
defaultLiteral: '',
|
||||||
|
},
|
||||||
void: {},
|
void: {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ export class Context {
|
||||||
}
|
}
|
||||||
const description = this.typeDescription(type, undefined);
|
const description = this.typeDescription(type, undefined);
|
||||||
const subtypes = Object.keys(
|
const subtypes = Object.keys(
|
||||||
Object.values(description)
|
Object.values(description.children)
|
||||||
.reduce((r, spec) => ({...r, [spec.type]: true}), {})
|
.reduce((r, spec) => ({...r, [spec.type]: true}), {})
|
||||||
);
|
);
|
||||||
subtypes.forEach((type) => marked[type] = true);
|
subtypes.forEach((type) => marked[type] = true);
|
||||||
|
@ -78,15 +78,18 @@ export class Context {
|
||||||
if (!types[type]) {
|
if (!types[type]) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
if ('function' === typeof types[type]) {
|
return {
|
||||||
return types[type](variable);
|
children: {},
|
||||||
}
|
...('function' === typeof types[type] ? types[type](variable) : types[type])
|
||||||
return types[type];
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static types() {
|
static types() {
|
||||||
return invokeHookFlat('behaviorContextTypes')
|
return invokeHookFlat('behaviorContextTypes')
|
||||||
.reduce((r, results) => ({...r, ...results}), {});
|
.reduce((r, results) => ({
|
||||||
|
...r,
|
||||||
|
...results,
|
||||||
|
}), {});
|
||||||
}
|
}
|
||||||
|
|
||||||
add(key, value, type) {
|
add(key, value, type) {
|
||||||
|
|
|
@ -27,35 +27,37 @@ export function behaviorContextGlobals() {
|
||||||
export function behaviorContextTypes() {
|
export function behaviorContextTypes() {
|
||||||
return {
|
return {
|
||||||
Flow: {
|
Flow: {
|
||||||
conditional: {
|
children: {
|
||||||
type: 'bool',
|
conditional: {
|
||||||
label: 'If $1 then run $2.',
|
type: 'bool',
|
||||||
args: [
|
label: 'If $1 then run $2.',
|
||||||
['condition', {
|
args: [
|
||||||
type: 'condition',
|
['condition', {
|
||||||
}],
|
type: 'condition',
|
||||||
['actions', {
|
}],
|
||||||
type: 'actions',
|
['actions', {
|
||||||
}],
|
type: 'actions',
|
||||||
],
|
}],
|
||||||
},
|
],
|
||||||
parallel: {
|
},
|
||||||
type: 'void',
|
parallel: {
|
||||||
label: 'Run $1 in parallel.',
|
type: 'void',
|
||||||
args: [
|
label: 'Run $1 in parallel.',
|
||||||
['actions', {
|
args: [
|
||||||
type: 'actions',
|
['actions', {
|
||||||
}],
|
type: 'actions',
|
||||||
],
|
}],
|
||||||
},
|
],
|
||||||
serial: {
|
},
|
||||||
type: 'void',
|
serial: {
|
||||||
label: 'Run $1 serially.',
|
type: 'void',
|
||||||
args: [
|
label: 'Run $1 serially.',
|
||||||
['actions', {
|
args: [
|
||||||
type: 'actions',
|
['actions', {
|
||||||
}],
|
type: 'actions',
|
||||||
],
|
}],
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,14 +19,16 @@ class Timing {
|
||||||
export function behaviorContextTypes() {
|
export function behaviorContextTypes() {
|
||||||
return {
|
return {
|
||||||
Timing: {
|
Timing: {
|
||||||
wait: {
|
children: {
|
||||||
type: 'void',
|
wait: {
|
||||||
label: 'Wait for $1 seconds.',
|
type: 'void',
|
||||||
args: [
|
label: 'Wait for $1 seconds.',
|
||||||
['duration', {
|
args: [
|
||||||
type: 'number',
|
['duration', {
|
||||||
}],
|
type: 'number',
|
||||||
],
|
}],
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,25 +35,27 @@ class Utility {
|
||||||
export function behaviorContextTypes() {
|
export function behaviorContextTypes() {
|
||||||
return {
|
return {
|
||||||
Utility: {
|
Utility: {
|
||||||
makeArray: {
|
children: {
|
||||||
type: 'array',
|
makeArray: {
|
||||||
label: 'Make array.',
|
type: 'array',
|
||||||
args: [],
|
label: 'Make array.',
|
||||||
},
|
args: [],
|
||||||
makeObject: {
|
},
|
||||||
type: 'object',
|
makeObject: {
|
||||||
label: 'Make object.',
|
type: 'object',
|
||||||
args: [],
|
label: 'Make object.',
|
||||||
},
|
args: [],
|
||||||
log: {
|
},
|
||||||
type: 'void',
|
log: {
|
||||||
label: 'Log.',
|
type: 'void',
|
||||||
args: [],
|
label: 'Log.',
|
||||||
},
|
args: [],
|
||||||
merge: {
|
},
|
||||||
type: 'object',
|
merge: {
|
||||||
label: 'Merge objects.',
|
type: 'object',
|
||||||
args: [],
|
label: 'Merge objects.',
|
||||||
|
args: [],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,24 +5,23 @@ export function behaviorContextTypes() {
|
||||||
const Traits = entity
|
const Traits = entity
|
||||||
? Object.values(entity.allTraitInstances()).map((instance) => instance.constructor)
|
? Object.values(entity.allTraitInstances()).map((instance) => instance.constructor)
|
||||||
: allTraits();
|
: allTraits();
|
||||||
const traitTypes = Traits
|
const core = {
|
||||||
.reduce((r, {behaviorContextTypes, describeState}) => ({
|
children: {
|
||||||
...r,
|
invokeHook: {
|
||||||
...behaviorContextTypes(),
|
type: 'object',
|
||||||
...describeState(),
|
label: 'Invoke hook.',
|
||||||
}), {});
|
args: [
|
||||||
return {
|
['hook', {
|
||||||
...traitTypes,
|
type: 'string',
|
||||||
invokeHook: {
|
}],
|
||||||
type: 'object',
|
],
|
||||||
label: 'Invoke hook.',
|
},
|
||||||
args: [
|
}
|
||||||
['hook', {
|
|
||||||
type: 'string',
|
|
||||||
}],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
return Traits
|
||||||
|
.reduce((r, T) => ({
|
||||||
|
...r, children: {...r.children, ...T.behaviorContextTypes(), ...T.describeState()},
|
||||||
|
}), core);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,30 +9,32 @@ export function behaviorContextGlobals() {
|
||||||
export function behaviorContextTypes() {
|
export function behaviorContextTypes() {
|
||||||
return {
|
return {
|
||||||
Math: (Math) => ({
|
Math: (Math) => ({
|
||||||
floor: {
|
children: {
|
||||||
type: 'number',
|
floor: {
|
||||||
label: 'Floor $1.',
|
type: 'number',
|
||||||
args: [
|
label: 'Floor $1.',
|
||||||
['operand', {
|
args: [
|
||||||
type: 'number',
|
['operand', {
|
||||||
}],
|
type: 'number',
|
||||||
],
|
}],
|
||||||
},
|
],
|
||||||
randomNumber: {
|
},
|
||||||
type: 'number',
|
randomNumber: {
|
||||||
label: 'Random number between $1 and $2.',
|
type: 'number',
|
||||||
args: [
|
label: 'Random number between $1 and $2.',
|
||||||
['min', {
|
args: [
|
||||||
type: 'number',
|
['min', {
|
||||||
}],
|
type: 'number',
|
||||||
['max', {
|
}],
|
||||||
type: 'number',
|
['max', {
|
||||||
}],
|
type: 'number',
|
||||||
],
|
}],
|
||||||
},
|
],
|
||||||
Vector: {
|
},
|
||||||
type: 'Vector',
|
Vector: {
|
||||||
},
|
type: 'Vector',
|
||||||
|
},
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +1,50 @@
|
||||||
export function behaviorContextTypes() {
|
export function behaviorContextTypes() {
|
||||||
return {
|
return {
|
||||||
|
vector: {
|
||||||
|
defaultLiteral: [0, 0],
|
||||||
|
children: {
|
||||||
|
x: {
|
||||||
|
type: 'number',
|
||||||
|
label: 'X',
|
||||||
|
},
|
||||||
|
y: {
|
||||||
|
type: 'number',
|
||||||
|
label: 'Y',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
Vector: (Math) => ({
|
Vector: (Math) => ({
|
||||||
floor: {
|
children: {
|
||||||
type: 'vector',
|
floor: {
|
||||||
label: 'Floor $1.',
|
type: 'vector',
|
||||||
args: [
|
label: 'Floor $1.',
|
||||||
['vector', {
|
args: [
|
||||||
type: 'vector',
|
['vector', {
|
||||||
}],
|
type: 'vector',
|
||||||
],
|
}],
|
||||||
},
|
],
|
||||||
fromDirection: {
|
},
|
||||||
type: 'vector',
|
fromDirection: {
|
||||||
label: '$1 as a movement vector.',
|
type: 'vector',
|
||||||
args: [
|
label: '$1 as a movement vector.',
|
||||||
['direction', {
|
args: [
|
||||||
type: 'number',
|
['direction', {
|
||||||
}],
|
type: 'number',
|
||||||
],
|
}],
|
||||||
},
|
],
|
||||||
sub: {
|
},
|
||||||
type: 'vector',
|
sub: {
|
||||||
label: 'Subtract $2 from $1.',
|
type: 'vector',
|
||||||
args: [
|
label: 'Subtract $2 from $1.',
|
||||||
['l', {
|
args: [
|
||||||
type: 'vector',
|
['l', {
|
||||||
}],
|
type: 'vector',
|
||||||
['r', {
|
}],
|
||||||
type: 'vector',
|
['r', {
|
||||||
}],
|
type: 'vector',
|
||||||
],
|
}],
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user