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

View File

@ -5,36 +5,21 @@ import {kittyJSON} from './kitty.entity';
// A MAMA kitteh.
export function mamaKittyJSON() {
const storeJSON = buildTraversal(
['context', 'json'],
{
traits: {
positioned: {
state: {},
},
},
},
const spawn = buildInvoke(
['entity', 'spawnAt'],
[
'kitteh',
buildInvoke(
['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'], [
buildTraversal(['entity', 'deathSound']),
]);
@ -66,9 +51,6 @@ export function mamaKittyJSON() {
};
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';