chore: descriptions

This commit is contained in:
cha0s 2020-06-19 22:01:45 -05:00
parent b63f25d5bb
commit 83498542e5
20 changed files with 392 additions and 13 deletions

View File

@ -1,15 +1,29 @@
export function behaviorContextTypes() {
return {
entity: (entity) => (
Object.values(entity.allTraitInstances())
.reduce(
(r, {constructor: {behaviorContextTypes, describeParams, describeState}}) => ({
...r,
...behaviorContextTypes(),
...describeParams(),
...describeState(),
}), {},
)
),
entity: (entity) => {
const traitTypes = !entity
? {}
: Object.values(entity.allTraitInstances())
.reduce(
(r, {constructor: {behaviorContextTypes, describeParams, describeState}}) => ({
...r,
...behaviorContextTypes(),
...describeParams(),
...describeState(),
}), {},
);
return {
...traitTypes,
invokeHook: {
type: 'object',
label: 'Invoke hook.',
args: [
['hook', {
type: 'string',
}],
],
},
};
},
};
}

View File

@ -12,8 +12,16 @@ export default class Existent extends decorate(Trait) {
static behaviorContextTypes() {
return {
destroy: {
type: 'void',
label: 'Destroy',
},
destroyGently: {
type: 'void',
label: 'Kill? Then destroy',
},
transition: {
type: 'ticking-promise',
type: 'void',
label: 'Transition $1 for $2 seconds using $3.',
args: [
['props', {

View File

@ -13,6 +13,15 @@ export default class Perishable extends decorate(Trait) {
};
}
static describeParams() {
return {
ttl: {
type: 'number',
label: 'Time-to-live in seconds',
},
};
}
static type() {
return 'perishable';
}

View File

@ -19,6 +19,10 @@ export default class Positioned extends decorate(Trait) {
static behaviorContextTypes() {
return {
position: {
type: 'vector',
label: 'Position',
},
setPosition: {
type: 'void',
label: 'Set position to $1.',

View File

@ -15,6 +15,10 @@ export default class Spawner extends decorate(Trait) {
static behaviorContextTypes() {
return {
killAllChildren: {
type: 'void',
label: 'Kill all spawned children',
},
spawn: {
type: 'entity',
label: 'Spawn $1 with $2 extensions.',
@ -72,6 +76,15 @@ export default class Spawner extends decorate(Trait) {
};
}
static describeParams() {
return {
spawns: {
type: 'object',
label: 'Entities that may be spawned',
},
};
}
static defaultState() {
return {
isSpawning: true,
@ -79,6 +92,19 @@ export default class Spawner extends decorate(Trait) {
};
}
static describeState() {
return {
isSpawning: {
type: 'bool',
label: 'Is spawning',
},
maxSpawns: {
type: 'number',
label: 'Maximum concurrent spawns',
},
};
}
static type() {
return 'spawner';
}

View File

@ -25,6 +25,24 @@ export default class Pictured extends decorate(Trait) {
};
}
static describeParams() {
return {
images: {
type: 'object',
label: 'Images',
},
};
}
static describeState() {
return {
currentImage: {
type: 'string',
label: 'Current image',
},
};
}
static type() {
return 'pictured';
}

View File

@ -13,6 +13,15 @@ export default class Primitive extends decorate(Trait) {
};
}
static describeParams() {
return {
primitives: {
type: 'object',
label: 'Primitives',
},
};
}
static type() {
return 'primitive';
}

View File

@ -17,6 +17,19 @@ export default class Textual extends decorate(Trait) {
};
}
static describeState() {
return {
text: {
type: 'string',
label: 'Text',
},
textStyle: {
type: 'object',
label: 'Text style',
},
};
}
static type() {
return 'textual';
}

View File

@ -57,6 +57,44 @@ export default class Visible extends decorate(Trait) {
};
}
static describeParams() {
return {
filter: {
type: 'object',
label: 'Filter',
},
trackPosition: {
type: 'bool',
label: 'Track position',
},
};
}
static describeState() {
return {
isVisible: {
type: 'bool',
label: 'Is visible',
},
opacity: {
type: 'number',
label: 'Opacity',
},
rotation: {
type: 'number',
label: 'Rotation',
},
visibleScale: {
type: 'vector',
label: 'Scale',
},
zIndex: {
type: 'number',
label: 'Z index',
},
};
}
static type() {
return 'visible';
}

View File

@ -75,6 +75,35 @@ export default class Collider extends decorate(Trait) {
}
}
static describeParams() {
return {
activeCollision: {
type: 'bool',
label: 'Actively check collisions',
},
collidesWithGroups: {
type: 'object',
label: 'Collides with groups',
},
collisionEndActions: {
type: 'actions',
label: 'Collision ending actions',
},
collisionStartActions: {
type: 'actions',
label: 'Collision starting actions',
},
collisionGroup: {
type: 'string',
label: 'Collision group',
},
isSensor: {
type: 'bool',
label: 'Is sensor',
},
};
}
static describeState() {
return {
isCheckingCollisions: {
@ -83,7 +112,7 @@ export default class Collider extends decorate(Trait) {
},
isColliding: {
type: 'bool',
label: 'Is colliding',
label: 'Is able to collide',
},
}
}

View File

@ -8,6 +8,15 @@ const decorate = compose(
export default class Emitted extends decorate(Trait) {
static behaviorContextTypes() {
return {
particle: {
type: 'particle',
label: 'Create particle.',
},
};
}
static defaultParams() {
return {
alpha: {
@ -35,6 +44,51 @@ export default class Emitted extends decorate(Trait) {
};
}
static describeParams() {
return {
alpha: {
type: 'object',
label: 'Alpha',
},
force: {
type: 'vector',
label: 'Force',
},
listed: {
type: 'bool',
label: 'Is listed',
},
mass: {
type: 'number',
label: 'Mass',
},
position: {
type: 'vector',
label: 'Position',
},
rotation: {
type: 'object',
label: 'Rotation',
},
scale: {
type: 'object',
label: 'Scale',
},
transient: {
type: 'bool',
label: 'Is transient',
},
ttl: {
type: 'number',
label: 'Time to live in seconds',
},
velocity: {
type: 'object',
label: 'Velocity',
},
};
}
static type() {
return 'emitted';
}

View File

@ -14,12 +14,56 @@ const decorate = compose(
export default class Emitter extends decorate(Trait) {
static behaviorContextTypes() {
return {
emitParticleEntity: {
type: 'entity',
label: 'Create particle.',
args: [
['entity', {
type: 'entity',
}],
],
},
emitParticleJson: {
type: 'stream',
label: 'Create particle.',
args: [
['json', {
type: 'object',
}],
],
},
emitParticle: {
type: 'stream',
label: 'Create particle.',
args: [
['key', {
type: 'string',
}],
['json', {
type: 'object',
}],
],
},
};
}
static defaultParams() {
return {
particles: {},
};
}
static describeParams() {
return {
particles: {
type: 'object',
label: 'Particles',
},
};
}
static type() {
return 'emitter';
}

View File

@ -12,6 +12,29 @@ const decorate = compose(
export default class Physical extends decorate(Trait) {
static behaviorContextTypes() {
return {
applyForce: {
type: 'void',
label: 'Apply force.',
args: [
['force', {
type: 'vector',
}],
],
},
applyImpulse: {
type: 'void',
label: 'Apply impulse.',
args: [
['impulse', {
type: 'vector',
}],
],
},
};
}
static defaultState() {
return {
addedToPhysics: true,

View File

@ -15,6 +15,15 @@ export default class Shaped extends decorate(Trait) {
};
}
static describeParams() {
return {
shape: {
type: 'object',
label: 'Shape',
},
};
}
static type() {
return 'shaped';
}

View File

@ -6,6 +6,15 @@ export default class Audible extends Trait {
static behaviorContextTypes() {
return {
hasSound: {
type: 'bool',
label: 'Has $1 sound',
args: [
['key', {
type: 'string',
}],
],
},
playSound: {
type: 'void',
label: 'Play the $1 sound.',
@ -24,6 +33,15 @@ export default class Audible extends Trait {
};
}
static describeParams() {
return {
sounds: {
type: 'object',
label: 'Sounds',
},
};
}
static type() {
return 'audible';
}

View File

@ -30,6 +30,15 @@ export default class Animated extends decorate(Trait) {
};
}
static describeParams() {
return {
animations: {
type: 'object',
label: 'Animations',
},
};
}
static describeState() {
return {
isAnimating: {

View File

@ -10,6 +10,15 @@ export default class Followed extends Trait {
}
}
static describeParams() {
return {
viewSize: {
type: 'vector',
label: 'View size',
},
};
}
static type() {
return 'followed';
}

View File

@ -3,6 +3,24 @@ import {Vector} from '@avocado/math';
export default class Layered extends Trait {
static behaviorContextTypes() {
return {
removeFromLayer: {
type: 'void',
label: 'Remove from layer.',
},
setIntoLayer: {
type: 'void',
label: 'Set into layer $1.',
args: [
['layer', {
type: 'layer',
}],
],
},
};
}
static type() {
return 'layered';
}

View File

@ -2,6 +2,24 @@ import {Trait} from '@avocado/entity';
export default class Roomed extends Trait {
static behaviorContextTypes() {
return {
detachFromRoom: {
type: 'void',
label: 'Remove from room.',
},
attachToRoom: {
type: 'void',
label: 'Set into room $1.',
args: [
['room', {
type: 'room',
}],
],
},
};
}
static type() {
return 'roomed';
}

View File

@ -16,6 +16,15 @@ export default class TileEntity extends decorate(Trait) {
};
}
static describeState() {
return {
tileIndex: {
type: 'number',
label: 'Tile index',
},
};
}
static type() {
return 'tile-entity';
}