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 {
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) {
return actions.parallel(context);
}

View File

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

View File

@ -227,6 +227,20 @@ export default class Entity extends decorate(Resource) {
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) {
super.fromJSON(json);
if (json.instanceUuid) {

View File

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

View File

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

View File

@ -10,6 +10,26 @@ const decorate = compose(
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() {
return {
isTicking: true,

View File

@ -4,6 +4,24 @@ import {Trait} from '../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() {
return 'listed';
}

View File

@ -10,6 +10,50 @@ const decorate = compose(
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() {
return {
isMobile: true,

View File

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

View File

@ -13,6 +13,59 @@ const decorate = compose(
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() {
return {
spawns: {},

View File

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

View File

@ -1,5 +1,37 @@
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() {
return {
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) {
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() {
return {
activeCollision: false,
@ -68,7 +113,7 @@ export default class Collider extends decorate(Trait) {
}
destroy() {
this.entity.releaseAllCollisions();
this.releaseAllCollisions();
}
checkActiveCollision() {
@ -144,6 +189,14 @@ export default class Collider extends decorate(Trait) {
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() {
return {
@ -174,7 +227,7 @@ export default class Collider extends decorate(Trait) {
},
removedFromRoom: () => {
this.entity.releaseAllCollisions();
this.releaseAllCollisions();
},
};
@ -198,14 +251,6 @@ export default class Collider extends decorate(Trait) {
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) => {
const index = this._doesNotCollideWith.indexOf(entity);
if (-1 !== index) {

View File

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