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

77 lines
2.6 KiB
Vue
Raw Normal View History

<script setup lang="ts">
export type MapRelation = 'own' | 'player' | 'barbarian'
const props = defineProps<{ tier: 1 | 2 | 3; relation: MapRelation }>()
// Low-poly huts in a 100 × 100 box: each is an isometric block with 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: '#d6cfc2', wallDark: '#a99f90', roofLight: '#8e857a', roofDark: '#6c6459' }
: { wallLight: '#e3cfa2', wallDark: '#b49870', roofLight: '#9c4a26', roofDark: '#73321a' },
)
const flag = computed(() => ({ own: '#d9b44a', player: '#962a1f', barbarian: '#8b9094' })[props.relation])
interface Hut {
cx: number
cy: number
w: number
d: number
h: number
roof: number
}
const huts = computed<Hut[]>(() => {
if (props.tier === 1) return [{ cx: 50, cy: 66, w: 20, d: 11, h: 16, roof: 16 }]
if (props.tier === 2)
return [
{ cx: 36, cy: 58, w: 16, d: 9, h: 13, roof: 13 },
{ cx: 62, cy: 70, w: 19, d: 10, h: 15, roof: 15 },
]
return [
{ cx: 50, cy: 50, w: 11, d: 6, h: 34, roof: 14 },
{ cx: 30, cy: 66, w: 15, d: 8, h: 13, roof: 12 },
{ cx: 70, cy: 70, w: 16, d: 9, h: 14, roof: 13 },
]
})
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(h: Hut) {
const { cx, cy, w, d } = h
const top = cy - h.h
const apex = top - h.roof
return {
left: pts(cx - w, cy, cx, cy + d, cx, cy + d - h.h, cx - w, top),
right: pts(cx, cy + d, cx + w, cy, cx + w, top, cx, cy + d - h.h),
roofLeft: pts(cx - w - 2, top + 1, cx, cy + d - h.h + 2, cx, apex),
roofRight: pts(cx, cy + d - h.h + 2, cx + w + 2, top + 1, cx, apex),
}
}
const pole = computed(() => {
const first = huts.value[0]!
const x = first.cx
const y = first.cy - first.h - first.roof
return { x, y }
})
</script>
<template>
<g>
<ellipse cx="50" cy="74" rx="40" ry="17" fill="#57391f" opacity="0.35" />
<g v-for="(hut, i) in huts" :key="i">
<polygon :points="faces(hut).left" :fill="tones.wallDark" />
<polygon :points="faces(hut).right" :fill="tones.wallLight" />
<polygon :points="faces(hut).roofLeft" :fill="tones.roofDark" />
<polygon :points="faces(hut).roofRight" :fill="tones.roofLight" />
</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" />
</g>
</template>