103 lines
4.3 KiB
Vue
103 lines
4.3 KiB
Vue
<script setup lang="ts">
|
|
import { scale } from '~/diorama/iso'
|
|
import type { Cycle, Tool } from '~/diorama/life'
|
|
|
|
const props = defineProps<{
|
|
shirt: string
|
|
/** What the villager brings home on the shoulder, as a colour. */
|
|
carry?: string | null
|
|
tool?: Tool | null
|
|
/** A work cycle to run (steps, swing, load, turning); without one the figure stands. */
|
|
cycle?: Cycle | null
|
|
/** Swinging the tool on the spot for good, e.g. a builder. */
|
|
swing?: { dur: number; values: string; keyTimes: string } | null
|
|
/** Seconds offset shared with the figure's motion. */
|
|
begin?: number
|
|
/** Which way it faces while standing: 1 right, -1 left. */
|
|
facing?: 1 | -1
|
|
}>()
|
|
|
|
const shirtShade = computed(() => scale(props.shirt, 0.72))
|
|
const carryTop = computed(() => (props.carry ? scale(props.carry, 1.15) : ''))
|
|
const carryShade = computed(() => (props.carry ? scale(props.carry, 0.7) : ''))
|
|
const begin = computed(() => `${props.begin ?? 0}s`)
|
|
const toolSwing = computed(() => props.cycle?.swing ?? props.swing ?? null)
|
|
const toolDur = computed(() => `${props.cycle?.dur ?? props.swing?.dur ?? 1}s`)
|
|
/** Rotation values about the shoulder, where the hand holds the tool. */
|
|
const swingValues = computed(() => toolSwing.value?.values.split(';').map((a) => `${a} 1.1 -6.4`).join(';') ?? '')
|
|
|
|
const METAL = '#8b9094'
|
|
const HANDLE = '#6a4526'
|
|
const HEADS: Record<Tool, string> = {
|
|
axe: 'M3.3 -11.4L5.5 -10.5L5 -9.3L3.6 -10.1z',
|
|
pick: 'M2.1 -11.7L5.7 -10.1L5.4 -9.7L3.8 -10.5L2.3 -11.1z',
|
|
shovel: 'M3.3 -10.5L4.8 -12L5.7 -11.1L4.2 -9.7z',
|
|
sickle: 'M3.6 -10.9Q6.6 -12.3 5.7 -9.1Q5.3 -10.8 3.9 -10.4z',
|
|
hammer: 'M2.9 -11.2L4.6 -10.3L4.1 -9.3L2.4 -10.1z',
|
|
spear: 'M1.2 -15.6L1.8 -13.6L0.6 -13.6z',
|
|
}
|
|
</script>
|
|
|
|
<!--
|
|
A villager in a few flat, shaded panels: legs that step while walking, a two-tone
|
|
shirt, head and hair, a tool that swings while working, and the load on the way home.
|
|
-->
|
|
<template>
|
|
<g :transform="`scale(${facing ?? 1} 1)`">
|
|
<animate
|
|
v-if="cycle?.presence"
|
|
attributeName="visibility"
|
|
calcMode="discrete"
|
|
:values="cycle.presence.values"
|
|
:keyTimes="cycle.presence.keyTimes"
|
|
:dur="`${cycle.dur}s`"
|
|
:begin="begin"
|
|
repeatCount="indefinite"
|
|
/>
|
|
<animateTransform
|
|
v-if="cycle"
|
|
attributeName="transform"
|
|
type="scale"
|
|
calcMode="discrete"
|
|
:values="cycle.face.values"
|
|
:keyTimes="cycle.face.keyTimes"
|
|
:dur="`${cycle.dur}s`"
|
|
:begin="begin"
|
|
repeatCount="indefinite"
|
|
/>
|
|
<rect x="-1.5" y="-2.4" width="1.2" height="2.4" fill="#3a2a1c">
|
|
<animateTransform v-if="cycle" attributeName="transform" type="translate" :values="cycle.step.values" :keyTimes="cycle.step.keyTimes" :dur="`${cycle.dur}s`" :begin="begin" repeatCount="indefinite" />
|
|
</rect>
|
|
<rect x="0.3" y="-2.4" width="1.2" height="2.4" fill="#2f2219">
|
|
<animateTransform v-if="cycle" attributeName="transform" type="translate" :values="cycle.step.mirrored" :keyTimes="cycle.step.keyTimes" :dur="`${cycle.dur}s`" :begin="begin" repeatCount="indefinite" />
|
|
</rect>
|
|
<path d="M-1.9 -6.9L0 -7.3V-2.2H-1.7z" :fill="shirt" />
|
|
<path d="M0 -7.3L1.9 -6.9L1.7 -2.2H0z" :fill="shirtShade" />
|
|
<circle cy="-8.9" r="1.65" fill="#d8a982" />
|
|
<path d="M-1.7 -9.1Q0 -11.5 1.7 -9.1Q0 -9.9 -1.7 -9.1z" fill="#4a3220" />
|
|
|
|
<g v-if="tool">
|
|
<animateTransform
|
|
v-if="toolSwing && (tool !== 'spear' || swing)"
|
|
attributeName="transform"
|
|
type="rotate"
|
|
:values="swingValues"
|
|
:keyTimes="toolSwing.keyTimes"
|
|
:dur="toolDur"
|
|
:begin="begin"
|
|
repeatCount="indefinite"
|
|
/>
|
|
<path v-if="tool === 'spear'" d="M0.95 -0.6H1.45V-13.8H0.95z" :fill="HANDLE" />
|
|
<path v-else d="M0.85 -6.6L1.35 -6.2L4.15 -10.7L3.65 -11.1z" :fill="HANDLE" />
|
|
<path :d="HEADS[tool]" :fill="METAL" />
|
|
</g>
|
|
|
|
<g v-if="carry" :visibility="cycle ? 'hidden' : 'visible'">
|
|
<animate v-if="cycle" attributeName="visibility" calcMode="discrete" :values="cycle.load.values" :keyTimes="cycle.load.keyTimes" :dur="`${cycle.dur}s`" :begin="begin" repeatCount="indefinite" />
|
|
<path d="M-0.6 -9.3L2.2 -9.8L3.8 -9L1 -8.5z" :fill="carryTop" />
|
|
<path d="M-0.6 -9.3L1 -8.5V-6.9L-0.6 -7.7z" :fill="carry" />
|
|
<path d="M1 -8.5L3.8 -9V-7.4L1 -6.9z" :fill="carryShade" />
|
|
</g>
|
|
</g>
|
|
</template>
|