refactor: use spawnAt

This commit is contained in:
cha0s 2019-05-30 09:11:44 -05:00
parent ea1473d3af
commit 46c74c01d0
2 changed files with 36 additions and 53 deletions

View File

@ -14,32 +14,36 @@ export function mamaKittySpawnerJSON() {
}, },
); );
function setAxeFromRoom(roomAxe, entityAxe) { function roomAxeValue(roomAxe) {
return buildTraversal( return buildInvoke(
['context', 'json', 'traits', 'positioned', 'state', entityAxe], ['global', 'randomNumber'],
buildInvoke(['global', 'multiply'], [ [
100,
buildInvoke( buildInvoke(
['global', 'randomNumber'], ['global', 'sub'],
[ [
buildTraversal(['entity', 'room', roomAxe]),
100, 100,
buildInvoke(
['global', 'sub'],
[
buildTraversal(['entity', 'room', roomAxe]),
100,
],
)
], ],
), )
4, ],
]),
); );
} }
const spawn = buildInvoke(['entity', 'spawn'], [ const spawn = buildInvoke(
'mama', ['entity', 'spawnAt'],
buildTraversal(['context', 'json']), [
]); 'mama',
buildInvoke(
['global', 'makeArray'],
[
roomAxeValue('width'),
roomAxeValue('height'),
],
),
buildTraversal(['context', 'json']),
],
);
return { return {
traits: { traits: {
@ -53,9 +57,6 @@ export function mamaKittySpawnerJSON() {
routine: { routine: {
type: 'actions', type: 'actions',
traversals: [ traversals: [
storeJSON,
setAxeFromRoom('width', 'x'),
setAxeFromRoom('height', 'y'),
spawn, spawn,
], ],
} }

View File

@ -5,36 +5,21 @@ import {kittyJSON} from './kitty.entity';
// A MAMA kitteh. // A MAMA kitteh.
export function mamaKittyJSON() { export function mamaKittyJSON() {
const storeJSON = buildTraversal( const spawn = buildInvoke(
['context', 'json'], ['entity', 'spawnAt'],
{ [
traits: { 'kitteh',
positioned: { buildInvoke(
state: {}, ['global', 'makeArray'],
}, [
}, buildTraversal(['entity', 'x']),
}, buildTraversal(['entity', 'y']),
],
),
buildTraversal(['context', 'json']),
],
); );
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'], [ const playDeathSound = buildInvoke(['entity', 'playSound'], [
buildTraversal(['entity', 'deathSound']), buildTraversal(['entity', 'deathSound']),
]); ]);
@ -66,9 +51,6 @@ export function mamaKittyJSON() {
}; };
traits.animated.params.animations.idle.offset = [0, -8]; traits.animated.params.animations.idle.offset = [0, -8];
traits.behaved.params.routines.routines.initial.routine.traversals.push(...[ traits.behaved.params.routines.routines.initial.routine.traversals.push(...[
storeJSON,
setJSONX,
setJSONY,
spawn, spawn,
]); ]);
traits.existent.state.name = 'Mama Kitty'; traits.existent.state.name = 'Mama Kitty';