refactor: clean up fixture generation

This commit is contained in:
cha0s 2019-05-21 03:10:07 -05:00
parent c80ce9e8f7
commit 81c91f3b40
18 changed files with 569 additions and 581 deletions

View File

@ -1 +1 @@
{"traits":{"animated":{"params":{"animations":{"idle":{"jitter":0.1,"offset":[0,0],"uri":"/blue-fire.animation.json"}}}},"audible":{"params":{"sounds":{"fire":{"uri":"/blue-fire.sound.json"}}}},"collider":{"params":{"isSensor":true}},"damaging":{"params":{"damagingSound":"fire","damageSpecs":[{"affinity":1,"lock":0.45,"power":-15,"variance":0.25}]}},"darkened":{"params":{"isDarkened":false}},"existent":{"state":{"name":"Blue fire"}},"layered":{},"listed":{},"physical":{},"positioned":{"state":{"x":0,"y":0}},"roomed":{},"shaped":{"params":{"shape":{"type":"rectangle","position":[0,0],"size":[16,16]}}},"visible":{"params":{"filter":"bloom"}}}} {"traits":{"animated":{"params":{"animations":{"idle":{"jitter":0.1,"offset":[0,0],"uri":"/blue-fire.animation.json"}}}},"audible":{"params":{"sounds":{"fire":{"uri":"/blue-fire.sound.json"}}}},"collider":{"params":{"isSensor":true}},"damaging":{"params":{"damagingSound":"fire","damageSpecs":[{"affinity":1,"lock":0.45,"power":-15,"variance":0.25}]}},"darkened":{"params":{"isDarkened":false}},"existent":{"state":{"name":"Blue fire"}},"layered":{},"listed":{},"physical":{},"positioned":{},"roomed":{},"shaped":{"params":{"shape":{"type":"rectangle","position":[0,0],"size":[16,16]}}},"visible":{"params":{"filter":"bloom"}}}}

View File

@ -1 +1 @@
{"traits":{"animated":{"params":{"animations":{"idle":{"jitter":0.1,"offset":[0,0],"uri":"/fire.animation.json"}}}},"audible":{"params":{"sounds":{"fire":{"uri":"/fire.sound.json"}}}},"collider":{"params":{"isSensor":true}},"damaging":{"params":{"damagingSound":"fire","damageSpecs":[{"affinity":1,"lock":0.45,"power":15,"variance":0.25}]}},"darkened":{"params":{"isDarkened":false}},"existent":{"state":{"name":"Fire"}},"layered":{},"listed":{},"physical":{},"positioned":{"state":{"x":0,"y":0}},"roomed":{},"shaped":{"params":{"shape":{"type":"rectangle","position":[0,0],"size":[16,16]}}},"visible":{"params":{"filter":"bloom"}}}} {"traits":{"animated":{"params":{"animations":{"idle":{"jitter":0.1,"offset":[0,0],"uri":"/fire.animation.json"}}}},"audible":{"params":{"sounds":{"fire":{"uri":"/fire.sound.json"}}}},"collider":{"params":{"isSensor":true}},"damaging":{"params":{"damagingSound":"fire","damageSpecs":[{"affinity":1,"lock":0.45,"power":15,"variance":0.25}]}},"darkened":{"params":{"isDarkened":false}},"existent":{"state":{"name":"Fire"}},"layered":{},"listed":{},"physical":{},"positioned":{},"roomed":{},"shaped":{"params":{"shape":{"type":"rectangle","position":[0,0],"size":[16,16]}}},"visible":{"params":{"filter":"bloom"}}}}

View File

@ -1 +1 @@
{"traits":{"alive":{"state":{"maxLife":1000,"life":1000}},"collider":{},"emitter":{},"existent":{"state":{"name":"Flower Barrel"}},"layered":{},"listed":{},"physical":{},"pictured":{"params":{"images":{"initial":{"offset":[0,-8],"size":[32,32],"uri":"/flower-barrel.png"}}}},"positioned":{"state":{"x":0,"y":0}},"roomed":{},"shaped":{"params":{"shape":{"type":"rectangle","position":[0,0],"size":[20,10]}}},"visible":{},"vulnerable":{}}} {"traits":{"alive":{"state":{"maxLife":1000,"life":1000}},"collider":{},"emitter":{},"existent":{"state":{"name":"Flower Barrel"}},"layered":{},"listed":{},"physical":{},"pictured":{"params":{"images":{"initial":{"offset":[0,-8],"size":[32,32],"uri":"/flower-barrel.png"}}}},"positioned":{},"roomed":{},"shaped":{"params":{"shape":{"type":"rectangle","position":[0,0],"size":[20,10]}}},"visible":{},"vulnerable":{}}}

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
{"traits":{"alive":{},"animated":{"params":{"animations":{"idle":{"offset":[0,-3],"uri":"/kitty.animation.json"}}}},"audible":{"params":{"sounds":{"deathSound":{"uri":"/ded.sound.json"}}}},"behaved":{"params":{"routines":{"type":"routines","routines":{"initial":{"type":"routine","routine":{"type":"actions","traversals":[{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"moveFor"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":0.25},{"type":"literal","value":2.5},{"type":"literal","value":false}]}]}]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"isAnimating"}],"value":{"type":"literal","value":false}},{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"wait"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":1},{"type":"literal","value":4},{"type":"literal","value":false}]}]}]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"direction"}],"value":{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":0},{"type":"literal","value":3}]}]}},{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"wait"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":0.5},{"type":"literal","value":3},{"type":"literal","value":false}]}]}]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"isAnimating"}],"value":{"type":"literal","value":true}}]}}}}}},"collider":{},"directional":{"params":{"directionCount":4},"state":{"direction":2}},"emitter":{},"existent":{"state":{"name":"Kitty"}},"visible":{"state":{"visibleScale":[1,1]}},"layered":{},"listed":{},"mobile":{"state":{"speed":40}},"physical":{},"positioned":{"state":{"x":0,"y":0}},"roomed":{},"shaped":{"params":{"shape":{"type":"rectangle","position":[0,0],"size":[8,4]}}},"vulnerable":{}}} {"traits":{"alive":{},"animated":{"params":{"animations":{"idle":{"offset":[0,-3],"uri":"/kitty.animation.json"}}}},"audible":{"params":{"sounds":{"deathSound":{"uri":"/ded.sound.json"}}}},"behaved":{"params":{"routines":{"type":"routines","routines":{"initial":{"type":"routine","routine":{"type":"actions","traversals":[{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"moveFor"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":0.25},{"type":"literal","value":2.5},{"type":"literal","value":false}]}]}]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"isAnimating"}],"value":{"type":"literal","value":false}},{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"wait"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":1},{"type":"literal","value":4},{"type":"literal","value":false}]}]}]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"direction"}],"value":{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":0},{"type":"literal","value":3}]}]}},{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"wait"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":0.5},{"type":"literal","value":3},{"type":"literal","value":false}]}]}]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"isAnimating"}],"value":{"type":"literal","value":true}}]}}}}}},"collider":{},"directional":{"params":{"directionCount":4},"state":{"direction":2}},"emitter":{},"existent":{"state":{"name":"Kitty"}},"visible":{"state":{"visibleScale":[1,1]}},"layered":{},"listed":{},"mobile":{"state":{"speed":40}},"physical":{},"positioned":{},"roomed":{},"shaped":{"params":{"shape":{"type":"rectangle","position":[0,0],"size":[8,4]}}},"vulnerable":{}}}

View File

@ -1 +1 @@
{"traits":{"behaved":{"params":{"routines":{"type":"routines","routines":{"initial":{"type":"routine","routine":{"type":"actions","traversals":[{"type":"traversal","steps":[{"type":"key","key":"context"},{"type":"key","key":"json"}],"value":{"type":"literal","value":{"traits":{"positioned":{"state":{}}}}}},{"type":"traversal","steps":[{"type":"key","key":"context"},{"type":"key","key":"json"},{"type":"key","key":"traits"},{"type":"key","key":"positioned"},{"type":"key","key":"state"},{"type":"key","key":"x"}],"value":{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"multiply"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":100},{"type":"literal","value":284}]}]},{"type":"literal","value":4}]}]}},{"type":"traversal","steps":[{"type":"key","key":"context"},{"type":"key","key":"json"},{"type":"key","key":"traits"},{"type":"key","key":"positioned"},{"type":"key","key":"state"},{"type":"key","key":"y"}],"value":{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"multiply"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":100},{"type":"literal","value":284}]}]},{"type":"literal","value":4}]}]}},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"spawn"},{"type":"invoke","args":[{"type":"literal","value":"mama"},{"type":"traversal","steps":[{"type":"key","key":"context"},{"type":"key","key":"json"}]}]}]}]}}}}}},"existent":{"state":{"name":"Mama spawner"}},"layered":{},"listed":{},"roomed":{},"spawner":{"params":{"spawns":{"mama":{"uri":"/mama-kitty.entity.json"}}},"state":{"maxSpawns":2}}}} {"traits":{"behaved":{"params":{"routines":{"type":"routines","routines":{"initial":{"type":"routine","routine":{"type":"actions","traversals":[{"type":"traversal","steps":[{"type":"key","key":"context"},{"type":"key","key":"json"}],"value":{"type":"literal","value":{"traits":{"positioned":{"state":{}}}}}},{"type":"traversal","steps":[{"type":"key","key":"context"},{"type":"key","key":"json"},{"type":"key","key":"traits"},{"type":"key","key":"positioned"},{"type":"key","key":"state"},{"type":"key","key":"x"}],"value":{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"multiply"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":100},{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"sub"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"room"},{"type":"key","key":"width"}]},{"type":"literal","value":100}]}]}]}]},{"type":"literal","value":4}]}]}},{"type":"traversal","steps":[{"type":"key","key":"context"},{"type":"key","key":"json"},{"type":"key","key":"traits"},{"type":"key","key":"positioned"},{"type":"key","key":"state"},{"type":"key","key":"y"}],"value":{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"multiply"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":100},{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"sub"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"room"},{"type":"key","key":"height"}]},{"type":"literal","value":100}]}]}]}]},{"type":"literal","value":4}]}]}},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"spawn"},{"type":"invoke","args":[{"type":"literal","value":"mama"},{"type":"traversal","steps":[{"type":"key","key":"context"},{"type":"key","key":"json"}]}]}]}]}}}}}},"existent":{"state":{"name":"Mama spawner"}},"layered":{},"listed":{},"roomed":{},"spawner":{"params":{"spawns":{"mama":{"uri":"/mama-kitty.entity.json"}}},"state":{"maxSpawns":2}}}}

View File

@ -1 +1 @@
{"traits":{"alive":{"params":{"deathActions":{"type":"actions","traversals":[{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"playSound"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"deathSound"}]}]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"killAllChildren"},{"type":"invoke","args":[]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"transition"},{"type":"invoke","args":[{"type":"literal","value":{"opacity":0,"visibleScaleX":0.3,"visibleScaleY":3}},{"type":"literal","value":0.2}]}]}]}},"state":{"life":500,"maxLife":500}},"animated":{"params":{"animations":{"idle":{"offset":[0,-8],"uri":"/kitty.animation.json"}}}},"audible":{"params":{"sounds":{"deathSound":{"uri":"/ded.sound.json"}}}},"behaved":{"params":{"routines":{"type":"routines","routines":{"initial":{"type":"routine","routine":{"type":"actions","traversals":[{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"moveFor"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":0.25},{"type":"literal","value":2.5},{"type":"literal","value":false}]}]}]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"isAnimating"}],"value":{"type":"literal","value":false}},{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"wait"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":1},{"type":"literal","value":4},{"type":"literal","value":false}]}]}]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"direction"}],"value":{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":0},{"type":"literal","value":3}]}]}},{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"wait"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":0.5},{"type":"literal","value":3},{"type":"literal","value":false}]}]}]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"isAnimating"}],"value":{"type":"literal","value":true}},{"type":"traversal","steps":[{"type":"key","key":"context"},{"type":"key","key":"json"}],"value":{"type":"literal","value":{"traits":{"positioned":{"state":{}}}}}},{"type":"traversal","steps":[{"type":"key","key":"context"},{"type":"key","key":"json"},{"type":"key","key":"traits"},{"type":"key","key":"positioned"},{"type":"key","key":"state"},{"type":"key","key":"x"}],"value":{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"multiply"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"x"}]},{"type":"literal","value":4}]}]}},{"type":"traversal","steps":[{"type":"key","key":"context"},{"type":"key","key":"json"},{"type":"key","key":"traits"},{"type":"key","key":"positioned"},{"type":"key","key":"state"},{"type":"key","key":"y"}],"value":{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"multiply"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"y"}]},{"type":"literal","value":4}]}]}},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"spawn"},{"type":"invoke","args":[{"type":"literal","value":"kitteh"},{"type":"traversal","steps":[{"type":"key","key":"context"},{"type":"key","key":"json"}]}]}]}]}}}}}},"collider":{},"directional":{"params":{"directionCount":4},"state":{"direction":2}},"emitter":{},"existent":{"state":{"name":"Mama Kitty"}},"visible":{"state":{"visibleScale":[2,2]}},"layered":{},"listed":{},"mobile":{"state":{"speed":40}},"physical":{},"positioned":{"state":{"x":0,"y":0}},"roomed":{},"shaped":{"params":{"shape":{"type":"rectangle","position":[0,0],"size":[16,8]}}},"vulnerable":{},"spawner":{"params":{"spawns":{"kitteh":{"uri":"/kitty.entity.json"}}},"state":{"maxSpawns":10}}}} {"traits":{"alive":{"params":{"deathActions":{"type":"actions","traversals":[{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"playSound"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"deathSound"}]}]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"killAllChildren"},{"type":"invoke","args":[]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"transition"},{"type":"invoke","args":[{"type":"literal","value":{"opacity":0,"visibleScaleX":0.3,"visibleScaleY":3}},{"type":"literal","value":0.2}]}]}]}},"state":{"life":500,"maxLife":500}},"animated":{"params":{"animations":{"idle":{"offset":[0,-8],"uri":"/kitty.animation.json"}}}},"audible":{"params":{"sounds":{"deathSound":{"uri":"/ded.sound.json"}}}},"behaved":{"params":{"routines":{"type":"routines","routines":{"initial":{"type":"routine","routine":{"type":"actions","traversals":[{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"moveFor"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":0.25},{"type":"literal","value":2.5},{"type":"literal","value":false}]}]}]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"isAnimating"}],"value":{"type":"literal","value":false}},{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"wait"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":1},{"type":"literal","value":4},{"type":"literal","value":false}]}]}]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"direction"}],"value":{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":0},{"type":"literal","value":3}]}]}},{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"wait"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":0.5},{"type":"literal","value":3},{"type":"literal","value":false}]}]}]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"isAnimating"}],"value":{"type":"literal","value":true}},{"type":"traversal","steps":[{"type":"key","key":"context"},{"type":"key","key":"json"}],"value":{"type":"literal","value":{"traits":{"positioned":{"state":{}}}}}},{"type":"traversal","steps":[{"type":"key","key":"context"},{"type":"key","key":"json"},{"type":"key","key":"traits"},{"type":"key","key":"positioned"},{"type":"key","key":"state"},{"type":"key","key":"x"}],"value":{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"multiply"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"x"}]},{"type":"literal","value":4}]}]}},{"type":"traversal","steps":[{"type":"key","key":"context"},{"type":"key","key":"json"},{"type":"key","key":"traits"},{"type":"key","key":"positioned"},{"type":"key","key":"state"},{"type":"key","key":"y"}],"value":{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"multiply"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"y"}]},{"type":"literal","value":4}]}]}},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"spawn"},{"type":"invoke","args":[{"type":"literal","value":"kitteh"},{"type":"traversal","steps":[{"type":"key","key":"context"},{"type":"key","key":"json"}]}]}]}]}}}}}},"collider":{},"directional":{"params":{"directionCount":4},"state":{"direction":2}},"emitter":{},"existent":{"state":{"name":"Mama Kitty"}},"visible":{"state":{"visibleScale":[2,2]}},"layered":{},"listed":{},"mobile":{"state":{"speed":40}},"physical":{},"positioned":{},"roomed":{},"shaped":{"params":{"shape":{"type":"rectangle","position":[0,0],"size":[16,8]}}},"vulnerable":{},"spawner":{"params":{"spawns":{"kitteh":{"uri":"/kitty.entity.json"}}},"state":{"maxSpawns":10}}}}

View File

@ -26,7 +26,11 @@ export function createEntityForConnection(socket) {
} }
}, },
}, },
collider: {}, collider: {
params: {
collisionGroup: 'player',
},
},
controllable: {}, controllable: {},
directional: { directional: {
params: { params: {

25
server/create-fixtures.js Normal file
View File

@ -0,0 +1,25 @@
import fs from 'fs';
import path from 'path';
const RESOURCE_PATH = path.resolve(process.cwd(), 'resource');
function writeFixture(uri, json) {
fs.writeFileSync(path.join(RESOURCE_PATH, uri), JSON.stringify(json));
}
// Write all our dudes.
import {blueFireJSON} from './fixtures/blue-fire.entity';
writeFixture('blue-fire.entity.json', blueFireJSON());
import {fireJSON} from './fixtures/fire.entity';
writeFixture('fire.entity.json', fireJSON());
import {flowerBarrelJSON} from './fixtures/flower-barrel.entity';
writeFixture('flower-barrel.entity.json', flowerBarrelJSON());
import {kittyJSON} from './fixtures/kitty.entity';
writeFixture('kitty.entity.json', kittyJSON());
import {mamaKittySpawnerJSON} from './fixtures/mama-kitty-spawner.entity';
writeFixture('mama-kitty-spawner.entity.json', mamaKittySpawnerJSON());
import {mamaKittyJSON} from './fixtures/mama-kitty.entity';
writeFixture('mama-kitty.entity.json', mamaKittyJSON());
// Write rooms.
import {kittyFireJSON} from './fixtures/kitty-fire.room';
writeFixture('kitty-fire.room.json', kittyFireJSON());

View File

@ -1,563 +0,0 @@
import fs from 'fs';
import path from 'path';
import {buildInvoke, buildTraversal} from '@avocado/behavior';
import {Vector} from '@avocado/math';
import {World} from '@avocado/physics/matter/world';
import {Room} from '@avocado/topdown';
import {AFFINITY_FIRE} from '../common/combat/constants';
// Behaviors!
const move = buildInvoke(['entity', 'moveFor'], [
buildInvoke(['global', 'randomNumber'], [0.25, 2.5, false])
]);
const stopAnimating = buildTraversal(
['entity', 'isAnimating'],
false
);
const firstWait = buildInvoke(['global', 'wait'], [
buildInvoke(['global', 'randomNumber'], [1, 4, false])
]);
const turn = buildTraversal(
['entity', 'direction'],
buildInvoke(['global', 'randomNumber'], [0, 3])
);
const secondWait = buildInvoke(['global', 'wait'], [
buildInvoke(['global', 'randomNumber'], [0.5, 3, false])
]);
const startAnimating = buildTraversal(
['entity', 'isAnimating'],
true
);
// A fire.
function fireJSON(position) {
return {
traits: {
animated: {
params: {
animations: {
idle: {
jitter: 0.1,
offset: [0, 0],
uri: '/fire.animation.json',
},
}
},
},
audible: {
params: {
sounds: {
fire: {
uri: '/fire.sound.json',
},
}
}
},
collider: {
params: {
isSensor: true,
},
},
damaging: {
params: {
damagingSound: 'fire',
damageSpecs: [
{
affinity: AFFINITY_FIRE,
lock: 0.45,
power: 15,
variance: 0.25,
},
],
},
},
darkened: {
params: {
isDarkened: false,
},
},
existent: {
state: {
name: 'Fire',
},
},
layered: {},
listed: {},
physical: {},
positioned: {
state: {
x: position[0],
y: position[1],
},
},
roomed: {},
shaped: {
params: {
shape: {
type: 'rectangle',
position: [0, 0],
size: [16, 16],
},
},
},
visible: {
params: {
filter: 'bloom',
},
},
},
};
}
// Healing fire!
function blueFireJSON(position) {
const json = fireJSON(position);
json.traits.animated.params.animations.idle.uri = '/blue-fire.animation.json';
json.traits.existent.state.name = 'Blue fire';
json.traits.damaging.params.damageSpecs[0].power = -15;
json.traits.audible.params.sounds.fire.uri = '/blue-fire.sound.json';
return json;
}
// A flower barrel.
export function flowerBarrelJSON(position) {
return {
traits: {
alive: {
state: {
maxLife: 1000,
life: 1000,
},
},
collider: {},
emitter: {},
existent: {
state: {
name: 'Flower Barrel',
},
},
layered: {},
listed: {},
physical: {},
pictured: {
params: {
images: {
initial: {
offset: [0, -8],
size: [32, 32], // Derive?
uri: '/flower-barrel.png',
},
}
},
},
positioned: {
state: {
x: position[0],
y: position[1],
},
},
roomed: {},
shaped: {
params: {
shape: {
type: 'rectangle',
position: [0, 0],
size: [20, 10],
},
},
},
visible: {},
vulnerable: {},
},
};
}
// A kitteh.
function kittyJSON(position) {
return {
traits: {
alive: {},
animated: {
params: {
animations: {
idle: {
offset: [0, -3],
uri: '/kitty.animation.json',
},
}
},
},
audible: {
params: {
sounds: {
deathSound: {
uri: '/ded.sound.json',
},
}
}
},
behaved: {
params: {
routines: {
type: 'routines',
routines: {
initial: {
type: 'routine',
routine: {
type: 'actions',
traversals: [
move,
stopAnimating,
firstWait,
turn,
secondWait,
startAnimating,
],
}
},
},
},
},
},
collider: {},
directional: {
params: {
directionCount: 4,
},
state: {
direction: 2,
},
},
emitter: {},
existent: {
state: {
name: 'Kitty',
},
},
visible: {
state: {
visibleScale: [1, 1],
}
},
layered: {},
listed: {},
mobile: {
state: {
speed: 40,
},
},
physical: {},
positioned: {
state: {
x: position[0],
y: position[1],
},
},
roomed: {},
shaped: {
params: {
shape: {
type: 'rectangle',
position: [0, 0],
size: [8, 4],
},
},
},
vulnerable: {},
},
};
}
// A MAMA kitteh.
function mamaKittyJSON(position) {
const storeJSON = buildTraversal(
['context', 'json'],
{
traits: {
positioned: {
state: {},
},
},
},
);
const setJSONX = buildTraversal(
['context', 'json', 'traits', 'positioned', 'state', 'x'],
buildInvoke(['global', 'multiply'], [
buildTraversal(['entity', 'x']), 4
]),
);
const setJSONY = buildTraversal(
['context', 'json', 'traits', 'positioned', 'state', 'y'],
buildInvoke(['global', 'multiply'], [
buildTraversal(['entity', 'y']), 4
]),
);
const spawn = buildInvoke(['entity', 'spawn'], [
'kitteh',
buildTraversal(['context', 'json']),
]);
const playDeathSound = buildInvoke(['entity', 'playSound'], [
buildTraversal(['entity', 'deathSound']),
]);
const squeeze = buildInvoke(['entity', 'transition'], [
{
opacity: 0,
visibleScaleX: .3,
visibleScaleY: 3,
},
0.2,
]);
const murderKitties = buildInvoke(['entity', 'killAllChildren']);
const json = JSON.parse(JSON.stringify(kittyJSON(position)));
const {traits} = json;
traits.alive.params = {
deathActions: {
type: 'actions',
traversals: [
playDeathSound,
murderKitties,
squeeze,
],
},
};
traits.alive.state = {
life: 500,
maxLife: 500,
};
traits.animated.params.animations.idle.offset = [0, -8];
traits.behaved.params.routines.routines.initial.routine.traversals.push(...[
storeJSON,
setJSONX,
setJSONY,
spawn,
]);
traits.existent.state.name = 'Mama Kitty';
traits.visible.state.visibleScale = [2, 2];
traits.shaped.params.shape.size = [16, 8];
traits.spawner = {
params: {
spawns: {
kitteh: {
uri: '/kitty.entity.json',
},
},
},
state: {
maxSpawns: 10,
},
};
return json;
}
// Mama kitty spawner.
function mamaKittySpawnerJSON() {
const storeJSON = buildTraversal(
['context', 'json'],
{
traits: {
positioned: {
state: {},
},
},
},
);
const setJSONX = buildTraversal(
['context', 'json', 'traits', 'positioned', 'state', 'x'],
buildInvoke(['global', 'multiply'], [
buildInvoke(['global', 'randomNumber'], [100, roomSize[0] - 100]), 4
]),
);
const setJSONY = buildTraversal(
['context', 'json', 'traits', 'positioned', 'state', 'y'],
buildInvoke(['global', 'multiply'], [
buildInvoke(['global', 'randomNumber'], [100, roomSize[1] - 100]), 4
]),
);
const spawn = buildInvoke(['entity', 'spawn'], [
'mama',
buildTraversal(['context', 'json']),
]);
return {
traits: {
behaved: {
params: {
routines: {
type: 'routines',
routines: {
initial: {
type: 'routine',
routine: {
type: 'actions',
traversals: [
storeJSON,
setJSONX,
setJSONY,
spawn,
],
}
},
},
},
},
},
existent: {
state: {
name: 'Mama spawner',
},
},
layered: {},
listed: {},
roomed: {},
spawner: {
params: {
spawns: {
mama: {
uri: '/mama-kitty.entity.json',
},
},
},
state: {
maxSpawns: 2,
},
},
},
};
}
// Room.
const roomTileSize = [24, 24];
const roomSize = Vector.mul([16, 16], roomTileSize);
const roomJSON = {
size: roomSize,
layers: [
{
entities: [],
tiles: {
size: roomTileSize,
data: [
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
],
},
tilesetUri: '/tileset.json',
},
],
};
const RESOURCE_PATH = path.resolve(process.cwd(), 'resource');
fs.writeFileSync(
path.join(RESOURCE_PATH, 'flower-barrel.entity.json'),
JSON.stringify(flowerBarrelJSON([0, 0]))
);
fs.writeFileSync(
path.join(RESOURCE_PATH, 'kitty.entity.json'),
JSON.stringify(kittyJSON([0, 0]))
);
fs.writeFileSync(
path.join(RESOURCE_PATH, 'mama-kitty.entity.json'),
JSON.stringify(mamaKittyJSON([0, 0]))
);
fs.writeFileSync(
path.join(RESOURCE_PATH, 'mama-kitty-spawner.entity.json'),
JSON.stringify(mamaKittySpawnerJSON([0, 0]))
);
fs.writeFileSync(
path.join(RESOURCE_PATH, 'fire.entity.json'),
JSON.stringify(fireJSON([0, 0]))
);
fs.writeFileSync(
path.join(RESOURCE_PATH, 'blue-fire.entity.json'),
JSON.stringify(blueFireJSON([0, 0]))
);
function positionedEntityJSON(uri, position) {
return {
uri,
traits: {
positioned: {
state: {
x: position[0] * 4,
y: position[1] * 4,
},
},
},
};
}
function randomPosition() {
return [
Math.floor(Math.random() * (roomSize[0] - 100)) + 50,
Math.floor(Math.random() * (roomSize[1] - 100)) + 50,
];
}
function addEntityWithRandomPosition(uri) {
const position = randomPosition();
roomJSON.layers[0].entities.push(positionedEntityJSON(uri, position));
}
for (let i = 0; i < 50; ++i) {
addEntityWithRandomPosition('/flower-barrel.entity.json');
}
for (let i = 0; i < 5; ++i) {
addEntityWithRandomPosition('/mama-kitty-spawner.entity.json');
}
for (let i = 0; i < 60; ++i) {
addEntityWithRandomPosition('/fire.entity.json');
}
for (let i = 0; i < 5; ++i) {
addEntityWithRandomPosition('/blue-fire.entity.json');
}
export function createRoom() {
const room = new Room(roomJSON);
room.world = new World();
return room;
}

View File

@ -0,0 +1,13 @@
import {buildInvoke, buildTraversal} from '@avocado/behavior';
import {fireJSON} from './fire.entity';
// Healing fire!
export function blueFireJSON() {
const json = fireJSON();
json.traits.animated.params.animations.idle.uri = '/blue-fire.animation.json';
json.traits.existent.state.name = 'Blue fire';
json.traits.damaging.params.damageSpecs[0].power = -15;
json.traits.audible.params.sounds.fire.uri = '/blue-fire.sound.json';
return json;
}

View File

@ -0,0 +1,78 @@
import {buildInvoke, buildTraversal} from '@avocado/behavior';
import {AFFINITY_FIRE} from '../../common/combat/constants';
// A fire.
export function fireJSON(position) {
return {
traits: {
animated: {
params: {
animations: {
idle: {
jitter: 0.1,
offset: [0, 0],
uri: '/fire.animation.json',
},
}
},
},
audible: {
params: {
sounds: {
fire: {
uri: '/fire.sound.json',
},
}
}
},
collider: {
params: {
isSensor: true,
},
},
damaging: {
params: {
damagingSound: 'fire',
damageSpecs: [
{
affinity: AFFINITY_FIRE,
lock: 0.45,
power: 15,
variance: 0.25,
},
],
},
},
darkened: {
params: {
isDarkened: false,
},
},
existent: {
state: {
name: 'Fire',
},
},
layered: {},
listed: {},
physical: {},
positioned: {},
roomed: {},
shaped: {
params: {
shape: {
type: 'rectangle',
position: [0, 0],
size: [16, 16],
},
},
},
visible: {
params: {
filter: 'bloom',
},
},
},
};
}

View File

@ -0,0 +1,49 @@
import {buildInvoke, buildTraversal} from '@avocado/behavior';
// A flower barrel.
export function flowerBarrelJSON() {
return {
traits: {
alive: {
state: {
maxLife: 1000,
life: 1000,
},
},
collider: {},
emitter: {},
existent: {
state: {
name: 'Flower Barrel',
},
},
layered: {},
listed: {},
physical: {},
pictured: {
params: {
images: {
initial: {
offset: [0, -8],
size: [32, 32], // Derive?
uri: '/flower-barrel.png',
},
}
},
},
positioned: {},
roomed: {},
shaped: {
params: {
shape: {
type: 'rectangle',
position: [0, 0],
size: [20, 10],
},
},
},
visible: {},
vulnerable: {},
},
};
}

View File

@ -0,0 +1,92 @@
import {Vector} from '@avocado/math';
// Room.
export function kittyFireJSON() {
const roomTileSize = [24, 24];
const roomSize = Vector.mul([16, 16], roomTileSize);
const roomJSON = {
size: roomSize,
layers: [
{
entities: [],
tiles: {
size: roomTileSize,
data: [
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
],
},
tilesetUri: '/tileset.json',
},
],
};
function positionedEntityJSON(uri, position) {
return {
uri,
traits: {
positioned: {
state: {
x: position[0] * 4,
y: position[1] * 4,
},
},
},
};
}
function randomPosition() {
return [
Math.floor(Math.random() * (roomSize[0] - 100)) + 50,
Math.floor(Math.random() * (roomSize[1] - 100)) + 50,
];
}
function addEntityWithRandomPosition(uri) {
const position = randomPosition();
roomJSON.layers[0].entities.push(positionedEntityJSON(uri, position));
}
for (let i = 0; i < 50; ++i) {
addEntityWithRandomPosition('/flower-barrel.entity.json');
}
for (let i = 0; i < 5; ++i) {
addEntityWithRandomPosition('/mama-kitty-spawner.entity.json');
}
for (let i = 0; i < 60; ++i) {
addEntityWithRandomPosition('/fire.entity.json');
}
for (let i = 0; i < 5; ++i) {
addEntityWithRandomPosition('/blue-fire.entity.json');
}
return roomJSON;
}

View File

@ -0,0 +1,119 @@
import {buildInvoke, buildTraversal} from '@avocado/behavior';
// A kitteh.
export function kittyJSON() {
const move = buildInvoke(['entity', 'moveFor'], [
buildInvoke(['global', 'randomNumber'], [0.25, 2.5, false])
]);
const stopAnimating = buildTraversal(
['entity', 'isAnimating'],
false
);
const firstWait = buildInvoke(['global', 'wait'], [
buildInvoke(['global', 'randomNumber'], [1, 4, false])
]);
const turn = buildTraversal(
['entity', 'direction'],
buildInvoke(['global', 'randomNumber'], [0, 3])
);
const secondWait = buildInvoke(['global', 'wait'], [
buildInvoke(['global', 'randomNumber'], [0.5, 3, false])
]);
const startAnimating = buildTraversal(
['entity', 'isAnimating'],
true
);
return {
traits: {
alive: {},
animated: {
params: {
animations: {
idle: {
offset: [0, -3],
uri: '/kitty.animation.json',
},
}
},
},
audible: {
params: {
sounds: {
deathSound: {
uri: '/ded.sound.json',
},
}
}
},
behaved: {
params: {
routines: {
type: 'routines',
routines: {
initial: {
type: 'routine',
routine: {
type: 'actions',
traversals: [
move,
stopAnimating,
firstWait,
turn,
secondWait,
startAnimating,
],
}
},
},
},
},
},
collider: {},
directional: {
params: {
directionCount: 4,
},
state: {
direction: 2,
},
},
emitter: {},
existent: {
state: {
name: 'Kitty',
},
},
visible: {
state: {
visibleScale: [1, 1],
}
},
layered: {},
listed: {},
mobile: {
state: {
speed: 40,
},
},
physical: {},
positioned: {},
roomed: {},
shaped: {
params: {
shape: {
type: 'rectangle',
position: [0, 0],
size: [8, 4],
},
},
},
vulnerable: {},
},
};
}

View File

@ -0,0 +1,89 @@
import {buildInvoke, buildTraversal} from '@avocado/behavior';
// Mama kitty spawner.
export function mamaKittySpawnerJSON() {
const storeJSON = buildTraversal(
['context', 'json'],
{
traits: {
positioned: {
state: {},
},
},
},
);
function setAxeFromRoom(roomAxe, entityAxe) {
return buildTraversal(
['context', 'json', 'traits', 'positioned', 'state', entityAxe],
buildInvoke(['global', 'multiply'], [
buildInvoke(
['global', 'randomNumber'],
[
100,
buildInvoke(
['global', 'sub'],
[
buildTraversal(['entity', 'room', roomAxe]),
100,
],
)
],
),
4,
]),
);
}
const spawn = buildInvoke(['entity', 'spawn'], [
'mama',
buildTraversal(['context', 'json']),
]);
return {
traits: {
behaved: {
params: {
routines: {
type: 'routines',
routines: {
initial: {
type: 'routine',
routine: {
type: 'actions',
traversals: [
storeJSON,
setAxeFromRoom('width', 'x'),
setAxeFromRoom('height', 'y'),
spawn,
],
}
},
},
},
},
},
existent: {
state: {
name: 'Mama spawner',
},
},
layered: {},
listed: {},
roomed: {},
spawner: {
params: {
spawns: {
mama: {
uri: '/mama-kitty.entity.json',
},
},
},
state: {
maxSpawns: 2,
},
},
},
};
}

View File

@ -0,0 +1,90 @@
import {buildInvoke, buildTraversal} from '@avocado/behavior';
import {kittyJSON} from './kitty.entity';
// A MAMA kitteh.
export function mamaKittyJSON() {
const storeJSON = buildTraversal(
['context', 'json'],
{
traits: {
positioned: {
state: {},
},
},
},
);
const setJSONX = buildTraversal(
['context', 'json', 'traits', 'positioned', 'state', 'x'],
buildInvoke(['global', 'multiply'], [
buildTraversal(['entity', 'x']), 4
]),
);
const setJSONY = buildTraversal(
['context', 'json', 'traits', 'positioned', 'state', 'y'],
buildInvoke(['global', 'multiply'], [
buildTraversal(['entity', 'y']), 4
]),
);
const spawn = buildInvoke(['entity', 'spawn'], [
'kitteh',
buildTraversal(['context', 'json']),
]);
const playDeathSound = buildInvoke(['entity', 'playSound'], [
buildTraversal(['entity', 'deathSound']),
]);
const squeeze = buildInvoke(['entity', 'transition'], [
{
opacity: 0,
visibleScaleX: .3,
visibleScaleY: 3,
},
0.2,
]);
const murderKitties = buildInvoke(['entity', 'killAllChildren']);
const json = JSON.parse(JSON.stringify(kittyJSON()));
const {traits} = json;
traits.alive.params = {
deathActions: {
type: 'actions',
traversals: [
playDeathSound,
murderKitties,
squeeze,
],
},
};
traits.alive.state = {
life: 500,
maxLife: 500,
};
traits.animated.params.animations.idle.offset = [0, -8];
traits.behaved.params.routines.routines.initial.routine.traversals.push(...[
storeJSON,
setJSONX,
setJSONY,
spawn,
]);
traits.existent.state.name = 'Mama Kitty';
traits.visible.state.visibleScale = [2, 2];
traits.shaped.params.shape.size = [16, 8];
traits.spawner = {
params: {
spawns: {
kitteh: {
uri: '/kitty.entity.json',
},
},
},
state: {
maxSpawns: 10,
},
};
return json;
}

View File

@ -4,6 +4,8 @@ import http from 'http';
import {SocketServer} from '@avocado/net/server/socket'; import {SocketServer} from '@avocado/net/server/socket';
// Import directly for HMR hierarchy. // Import directly for HMR hierarchy.
import 'register-traits'; import 'register-traits';
// Create fixtures.
import './create-fixtures';
// Start game server. // Start game server.
import Game from './game'; import Game from './game';
const socketServer = new SocketServer(); const socketServer = new SocketServer();
@ -13,22 +15,11 @@ let httpServer;
import repl from 'repl'; import repl from 'repl';
import {Entity} from '@avocado/entity';
import {flowerBarrelJSON} from './create-server-room';
const instance = repl.start({ const instance = repl.start({
prompt: 'humus> ', prompt: 'humus> ',
input: process.stdin, input: process.stdin,
output: process.stdout output: process.stdout
}); });
instance.context.createBarrel = () => {
return (new Entity()).fromJSON(flowerBarrelJSON([400, 400]));
};
instance.context.addEntityToRoom = (entity) => {
game.room.addEntityToLayer(entity, 'everything');
};
instance.context.ab = () => {
instance.context.addEntityToRoom(instance.context.createBarrel());
}
function createGame() { function createGame() {
game = new Game(); game = new Game();