game-village-politics-frontend/app/components/village/Worker.vue

48 lines
1.5 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import { type Tool, workCycle } from '~/diorama/life'
const props = defineProps<{
/** Screen path from home to where the work is. */
d: string
/** Seconds one way, and seconds of work at the far end (0: just turns round). */
walk: number
work: number
shirt: string
carry?: string | null
tool?: Tool | null
size: number
/** Seconds into its cycle, so workers on one road don't move in lockstep. */
begin: number
/** Seconds at home between trips (default 1.2). */
rest?: number
/** Home is a building: out of sight while resting there. */
indoors?: boolean
soldier?: boolean
}>()
/** Faces right when the way out leads right on screen. */
const facing = computed<1 | -1>(() => {
const nums = props.d.match(/-?\d+(\.\d+)?/g)?.map(Number) ?? []
return nums.length >= 4 && nums[nums.length - 2]! < nums[0]! ? -1 : 1
})
const cycle = computed(() => workCycle(props.walk, props.work, props.rest ?? 1.2, facing.value, props.indoors))
</script>
<!-- A villager going out to work, working, and bringing the load home, round and round. -->
<template>
<g>
<g :transform="`scale(${size})`">
<VillageWalker :shirt="shirt" :carry="carry" :tool="tool" :cycle="cycle" :begin="begin" :soldier="soldier" />
</g>
<animateMotion
:dur="`${cycle.dur}s`"
:begin="`${begin}s`"
repeatCount="indefinite"
calcMode="linear"
:keyPoints="cycle.motion.keyPoints"
:keyTimes="cycle.motion.keyTimes"
:path="d"
/>
</g>
</template>