game-village-politics-frontend/app/components/map/VillageMarker.vue

130 lines
5.0 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script setup lang="ts">
import type { MarkerRelation } from '~/utils/relations'
const props = defineProps<{ tier: 1 | 2 | 3 | 4 | 5; relation: MarkerRelation; crown?: boolean }>()
// Low-poly settlements in a 100 × 100 box that grow with the village's points, like the
// five village sizes on the Die Stämme map: a hut, a hamlet, a village with a tower, a
// town behind a palisade, and a stone keep behind walls. Each block has two lit wall
// faces and a two-facet roof, so it reads as 3D like the village diorama.
const tones = computed(() =>
props.relation === 'barbarian'
? { wallLight: '#aaa498', wallDark: '#827d74', roofLight: '#6e685f', roofDark: '#524c45' }
: { wallLight: '#b5a486', wallDark: '#8b7c62', roofLight: '#7f4430', roofDark: '#5a3020' },
)
const STONE = { wallLight: '#9d988f', wallDark: '#77736c', roofLight: '#5a5f66', roofDark: '#45494f' }
const flag = computed(() => RELATION_COLOURS[props.relation])
interface Block {
cx: number
cy: number
w: number
d: number
h: number
roof: number
stone?: boolean
}
const blocks = computed<Block[]>(() => {
switch (props.tier) {
case 1:
return [{ cx: 50, cy: 66, w: 18, d: 10, h: 14, roof: 14 }]
case 2:
return [
{ cx: 36, cy: 60, w: 15, d: 8, h: 12, roof: 12 },
{ cx: 62, cy: 70, w: 18, d: 10, h: 14, roof: 14 },
]
case 3:
return [
{ cx: 50, cy: 52, w: 10, d: 6, h: 30, roof: 13 },
{ cx: 30, cy: 66, w: 15, d: 8, h: 13, roof: 12 },
{ cx: 70, cy: 70, w: 16, d: 9, h: 14, roof: 13 },
]
case 4:
return [
{ cx: 50, cy: 46, w: 11, d: 6, h: 34, roof: 14 },
{ cx: 28, cy: 58, w: 14, d: 8, h: 13, roof: 12 },
{ cx: 72, cy: 60, w: 15, d: 8, h: 14, roof: 12 },
{ cx: 48, cy: 70, w: 16, d: 8, h: 12, roof: 11 },
]
default:
return [
{ cx: 50, cy: 50, w: 17, d: 10, h: 38, roof: 16, stone: true },
{ cx: 26, cy: 58, w: 13, d: 7, h: 12, roof: 11 },
{ cx: 74, cy: 60, w: 13, d: 7, h: 12, roof: 11 },
]
}
})
const pts = (...p: number[]) => {
const out: string[] = []
for (let i = 0; i < p.length; i += 2) out.push(`${p[i]},${p[i + 1]}`)
return out.join(' ')
}
function faces(b: Block) {
const { cx, cy, w, d } = b
const top = cy - b.h
const apex = top - b.roof
return {
left: pts(cx - w, cy, cx, cy + d, cx, cy + d - b.h, cx - w, top),
right: pts(cx, cy + d, cx + w, cy, cx + w, top, cx, cy + d - b.h),
roofLeft: pts(cx - w - 2, top + 1, cx, cy + d - b.h + 2, cx, apex),
roofRight: pts(cx, cy + d - b.h + 2, cx + w + 2, top + 1, cx, apex),
colors: b.stone ? STONE : tones.value,
}
}
/** Points along the front half of the ring a palisade or wall stands on. */
const ring = computed(() =>
Array.from({ length: 15 }, (_, i) => {
const a = Math.PI * (0.02 + (i / 14) * 0.96)
return { x: 50 + Math.cos(a) * 44, y: 66 + Math.sin(a) * 19 }
}),
)
const pole = computed(() => {
const first = blocks.value[0]!
return { x: first.cx, y: first.cy - first.h - first.roof }
})
</script>
<template>
<g>
<ellipse cx="50" cy="72" rx="42" ry="18" fill="#5f5640" />
<!-- The relation colour rings the village, so it reads at a glance. -->
<ellipse cx="50" cy="72" rx="44" ry="20" fill="none" :stroke="flag" stroke-width="6" />
<g v-for="(b, i) in blocks" :key="i">
<polygon :points="faces(b).left" :fill="faces(b).colors.wallDark" />
<polygon :points="faces(b).right" :fill="faces(b).colors.wallLight" />
<polygon :points="faces(b).roofLeft" :fill="faces(b).colors.roofDark" />
<polygon :points="faces(b).roofRight" :fill="faces(b).colors.roofLight" />
</g>
<!-- A town's palisade or a keep's stone wall along the front of the ring. -->
<g v-if="tier === 4">
<rect v-for="(p, i) in ring" :key="i" :x="p.x - 2" :y="p.y - 9" width="4" height="10" :fill="i % 2 ? '#574536' : '#7a6249'" />
</g>
<g v-else-if="tier === 5">
<polygon
v-for="(p, i) in ring.slice(0, -1)"
:key="i"
:points="pts(p.x, p.y, ring[i + 1]!.x, ring[i + 1]!.y, ring[i + 1]!.x, ring[i + 1]!.y - 10, p.x, p.y - 10)"
:fill="i % 2 ? '#77736c' : '#928d84'"
/>
<rect v-for="i in [0, 7, 14]" :key="`t${i}`" :x="ring[i]!.x - 4" :y="ring[i]!.y - 16" width="8" height="16" fill="#74716a" />
</g>
<line :x1="pole.x" :y1="pole.y" :x2="pole.x" :y2="pole.y - 20" stroke="#4a3b2e" stroke-width="2" />
<polygon :points="pts(pole.x, pole.y - 20, pole.x + 15, pole.y - 15, pole.x, pole.y - 10)" :fill="flag" stroke="#2b2118" stroke-width="0.8" />
<!-- A crown fort of the season wears a gold crown over its flag. -->
<g v-if="crown">
<polygon
:points="pts(pole.x - 12, pole.y - 22, pole.x - 12, pole.y - 36, pole.x - 6, pole.y - 29, pole.x, pole.y - 40, pole.x + 6, pole.y - 29, pole.x + 12, pole.y - 36, pole.x + 12, pole.y - 22)"
fill="#d9b44a"
stroke="#6b4f16"
stroke-width="1.2"
/>
<rect :x="pole.x - 12" :y="pole.y - 26" width="24" height="4" fill="#a8842e" />
</g>
</g>
</template>