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; }