chore: descriptions

This commit is contained in:
cha0s 2020-06-19 15:31:35 -05:00
parent 42fe27f0a3
commit 983db36bab
16 changed files with 368 additions and 11 deletions

View File

@ -1,3 +1,5 @@
import {Context} from './context';
class Flow { class Flow {
static conditional(condition, actions, context) { static conditional(condition, actions, context) {
@ -6,6 +8,44 @@ class Flow {
} }
}; };
static contextDescription() {
return {
type: 'object',
children: {
conditional: {
type: 'ticking-promise',
label: 'If $1 then run $2.',
args: [
['condition', {
type: 'condition',
}],
['actions', {
type: 'actions',
}],
],
},
parallel: {
type: 'ticking-promise',
label: 'Run $1 in parallel.',
args: [
['actions', {
type: 'actions',
}],
],
},
serial: {
type: 'ticking-promise',
label: 'Run $1 serially.',
args: [
['actions', {
type: 'actions',
}],
],
},
}
};
}
static parallel(actions, context) { static parallel(actions, context) {
return actions.parallel(context); return actions.parallel(context);
} }

View File

@ -2,6 +2,23 @@ import {TickingPromise} from '@avocado/core';
class Timing { class Timing {
static contextDescription() {
return {
type: 'object',
children: {
wait: {
type: 'ticking-promise',
label: 'Wait for $1 seconds.',
args: [
['duration', {
type: 'number',
}],
],
},
},
};
}
static wait (duration) { static wait (duration) {
return new TickingPromise( return new TickingPromise(
() => {}, () => {},

View File

@ -26,6 +26,15 @@ export default class Behaved extends decorate(Trait) {
} }
} }
static describeParams() {
return {
routines: {
type: 'routines',
label: 'Routines',
},
}
}
static describeState() { static describeState() {
return { return {
isBehaving: { isBehaving: {

View File

@ -227,6 +227,20 @@ export default class Entity extends decorate(Resource) {
this._fastDirtyCheck = false; this._fastDirtyCheck = false;
} }
contextDescription() {
return {
type: 'entity',
children: this._traitsFlat.reduce(
(r, trait) => ({
...r,
...trait.constructor.contextDescription(),
...trait.constructor.describeParams(),
...trait.constructor.describeState(),
}), {},
),
};
}
fromJSON(json) { fromJSON(json) {
super.fromJSON(json); super.fromJSON(json);
if (json.instanceUuid) { if (json.instanceUuid) {

View File

@ -38,7 +38,7 @@ export class Trait extends decorate(class {}) {
this._fastDirtyCheck = false; this._fastDirtyCheck = false;
} }
static contextType() { static contextDescription() {
return {}; return {};
} }

View File

@ -25,6 +25,15 @@ const decorate = compose(
export default class Alive extends decorate(Trait) { export default class Alive extends decorate(Trait) {
static contextDescription() {
return {
forceDeath: {
type: 'void',
label: 'Force death',
},
};
}
static defaultParams() { static defaultParams() {
const playDeathSound = buildInvoke(['entity', 'playSound'], [ const playDeathSound = buildInvoke(['entity', 'playSound'], [
buildTraversal(['entity', 'deathSound']), buildTraversal(['entity', 'deathSound']),

View File

@ -10,6 +10,26 @@ const decorate = compose(
export default class Existent extends decorate(Trait) { export default class Existent extends decorate(Trait) {
static contextDescription() {
return {
transition: {
type: 'ticking-promise',
label: 'Transition $1 for $2 seconds using $3.',
args: [
['props', {
type: 'object',
}],
['duration', {
type: 'number',
}],
['easing', {
type: 'string',
}],
],
},
};
}
static defaultState() { static defaultState() {
return { return {
isTicking: true, isTicking: true,

View File

@ -4,6 +4,24 @@ import {Trait} from '../trait';
export default class Listed extends Trait { export default class Listed extends Trait {
static contextDescription() {
return {
detachFromList: {
type: 'void',
label: 'Detach from list.',
},
attachToList: {
type: 'void',
label: 'Attach to $1.',
args: [
['list', {
type: 'entity-list',
}],
],
},
};
}
static type() { static type() {
return 'listed'; return 'listed';
} }

View File

@ -10,6 +10,50 @@ const decorate = compose(
export default class Mobile extends decorate(Trait) { export default class Mobile extends decorate(Trait) {
static contextDescription() {
return {
moveFor: {
type: 'void',
label: 'Move toward $1 for $2 seconds.',
args: [
['movement', {
type: 'vector',
}],
['duration', {
type: 'number',
}],
],
},
applyMovement: {
type: 'void',
label: 'Apply movement of $1.',
args: [
['movement', {
type: 'vector',
}],
],
},
forceMovement: {
type: 'void',
label: 'Force movement of $1.',
args: [
['movement', {
type: 'vector',
}],
],
},
requestMovement: {
type: 'void',
label: 'Request movement of $1.',
args: [
['movement', {
type: 'vector',
}],
],
},
};
}
static defaultState() { static defaultState() {
return { return {
isMobile: true, isMobile: true,

View File

@ -17,6 +17,20 @@ const decorate = compose(
// < 16768 will pack into 1 short per axe and give +/- 0.25 precision. // < 16768 will pack into 1 short per axe and give +/- 0.25 precision.
export default class Positioned extends decorate(Trait) { export default class Positioned extends decorate(Trait) {
static contextDescription() {
return {
setPosition: {
type: 'void',
label: 'Set position to $1.',
args: [
['position', {
type: 'vector',
}],
],
},
};
}
static defaultState() { static defaultState() {
return { return {
x: 0, x: 0,

View File

@ -13,6 +13,59 @@ const decorate = compose(
export default class Spawner extends decorate(Trait) { export default class Spawner extends decorate(Trait) {
static contextDescription() {
return {
spawn: {
type: 'entity',
label: 'Spawn $1 with $2 extensions.',
args: [
['key', {
type: 'string',
}],
['json', {
type: 'object',
}],
],
},
spawnAt: {
type: 'entity',
label: 'Spawn $1 as $2 with $3 extensions.',
args: [
['key', {
type: 'string',
}],
['position', {
type: 'vector',
}],
['json', {
type: 'object',
}],
],
},
spawnRaw: {
type: 'entity',
label: 'Spawn $1.',
args: [
['json', {
type: 'object',
}],
]
},
spawnRawAt: {
type: 'entity',
label: 'Spawn $1 at $2.',
args: [
['position', {
type: 'vector',
}],
['json', {
type: 'object',
}],
]
},
};
}
static defaultParams() { static defaultParams() {
return { return {
spawns: {}, spawns: {},

View File

@ -30,6 +30,16 @@ const decorate = compose(
export default class Visible extends decorate(Trait) { export default class Visible extends decorate(Trait) {
static contextDescription() {
return {
updateVisibleBoundingBox: {
advanced: true,
type: 'void',
label: 'Update the visible bounding box.',
},
};
}
static defaultParams() { static defaultParams() {
return { return {
filter: undefined, filter: undefined,

View File

@ -1,5 +1,37 @@
import * as MathExt from '.'; import * as MathExt from '.';
MathExt.contextDescription = () => {
return {
type: 'module',
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',
},
},
};
};
export function behaviorContextGlobals() { export function behaviorContextGlobals() {
return { return {
Math: MathExt, Math: MathExt,

View File

@ -408,3 +408,21 @@ export class Range extends MathRange {
} }
} }
export function contextDescription() {
return {
type: 'Vector',
children: {
fromDirection: {
type: 'vector',
label: 'Vector from direction $1.',
args: [
['direction', {
type: 'number',
}],
],
},
},
};
}

View File

@ -10,6 +10,51 @@ const decorate = compose(
export default class Collider extends decorate(Trait) { export default class Collider extends decorate(Trait) {
static contextDescription() {
return {
collidesWith: {
advanced: true,
type: 'bool',
label: 'I would collide with $1.',
args: [
['other', {
type: 'entity',
}],
],
},
doesNotCollideWith: {
advanced: true,
type: 'bool',
label: 'I would not collide with $1.',
args: [
['other', {
type: 'entity',
}],
],
},
setDoesCollideWith: {
advanced: true,
type: 'void',
label: 'Set $1 as colliding with myself.',
args: [
['other', {
type: 'entity',
}],
],
},
setDoesNotCollideWith: {
advanced: true,
type: 'void',
label: 'Set $1 as not colliding with myself.',
args: [
['other', {
type: 'entity',
}],
],
},
};
}
static defaultParams() { static defaultParams() {
return { return {
activeCollision: false, activeCollision: false,
@ -68,7 +113,7 @@ export default class Collider extends decorate(Trait) {
} }
destroy() { destroy() {
this.entity.releaseAllCollisions(); this.releaseAllCollisions();
} }
checkActiveCollision() { checkActiveCollision() {
@ -144,6 +189,14 @@ export default class Collider extends decorate(Trait) {
this._collisionTickingPromises.push(tickingPromise); this._collisionTickingPromises.push(tickingPromise);
} }
releaseAllCollisions() {
for (let i = 0; i < this._isCollidingWith.length; i++) {
const entity = this._isCollidingWith[i];
entity.emit('collisionEnd', this.entity);
}
this._isCollidingWith = [];
}
listeners() { listeners() {
return { return {
@ -174,7 +227,7 @@ export default class Collider extends decorate(Trait) {
}, },
removedFromRoom: () => { removedFromRoom: () => {
this.entity.releaseAllCollisions(); this.releaseAllCollisions();
}, },
}; };
@ -198,14 +251,6 @@ export default class Collider extends decorate(Trait) {
return !this.entity.collidesWith(entity); return !this.entity.collidesWith(entity);
}, },
releaseAllCollisions: () => {
for (let i = 0; i < this._isCollidingWith.length; i++) {
const entity = this._isCollidingWith[i];
entity.emit('collisionEnd', this.entity);
}
this._isCollidingWith = [];
},
setDoesCollideWith: (entity) => { setDoesCollideWith: (entity) => {
const index = this._doesNotCollideWith.indexOf(entity); const index = this._doesNotCollideWith.indexOf(entity);
if (-1 !== index) { if (-1 !== index) {

View File

@ -4,6 +4,20 @@ import {Sound} from '..';
export default class Audible extends Trait { export default class Audible extends Trait {
static contextDescription() {
return {
playSound: {
type: 'void',
label: 'Play the $1 sound.',
args: [
['key', {
type: 'string',
}],
],
},
};
}
static defaultParams() { static defaultParams() {
return { return {
sounds: {}, sounds: {},