43 lines
1.3 KiB
Vue
43 lines
1.3 KiB
Vue
<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
|
|
}>()
|
|
|
|
/** 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, 1.2, facing.value))
|
|
</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" />
|
|
</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>
|