feat: Die Stämme-style world map with coordinate rulers, continents and village info
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
6bc2d44419
commit
a4185b66a7
|
|
@ -0,0 +1,43 @@
|
|||
<script setup lang="ts">
|
||||
import type { MapVillage } from '~/types/map'
|
||||
|
||||
defineProps<{
|
||||
village: MapVillage | null
|
||||
at: { x: number; y: number } | null
|
||||
}>()
|
||||
const emit = defineEmits<{ center: [at: { x: number; y: number }] }>()
|
||||
|
||||
const continentOf = (x: number, y: number) => `K${Math.floor(y / 100)}${Math.floor(x / 100)}`
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="panel">
|
||||
<div class="panel-head">
|
||||
<h2 class="panel-title">{{ $t('map.info.title') }}</h2>
|
||||
</div>
|
||||
<div class="panel-body text-sm">
|
||||
<template v-if="village">
|
||||
<p class="font-display text-lg font-semibold">{{ village.name }}</p>
|
||||
<dl class="mt-3 grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5">
|
||||
<dt class="text-ink-500">{{ $t('map.info.coordinates') }}</dt>
|
||||
<dd class="font-semibold tabular-nums">{{ village.x }}|{{ village.y }} <span class="text-ink-500">{{ village.continent }}</span></dd>
|
||||
<dt class="text-ink-500">{{ $t('map.info.owner') }}</dt>
|
||||
<dd>{{ village.player?.name ?? $t('map.barbarian') }}</dd>
|
||||
<dt class="text-ink-500">{{ $t('map.info.points') }}</dt>
|
||||
<dd class="tabular-nums">{{ village.points }}</dd>
|
||||
</dl>
|
||||
<div class="mt-4 flex flex-wrap gap-2">
|
||||
<NuxtLink v-if="village.own" :to="`/village/${village.id}`" class="btn btn-primary">{{ $t('map.info.open') }}</NuxtLink>
|
||||
<button type="button" class="btn btn-outline" @click="emit('center', { x: village.x, y: village.y })">
|
||||
{{ $t('map.info.center') }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="at">
|
||||
<p class="text-ink-700">{{ $t('map.info.empty') }}</p>
|
||||
<p class="mt-1 font-semibold tabular-nums">{{ at.x }}|{{ at.y }} <span class="text-ink-500">{{ continentOf(at.x, at.y) }}</span></p>
|
||||
</template>
|
||||
<p v-else class="text-ink-500">{{ $t('map.info.hint') }}</p>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
<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: '#efdfbd', wallDark: '#c8ad84', roofLight: '#c2643a', roofDark: '#963f1d' },
|
||||
)
|
||||
const flag = computed(() => ({ own: '#f2b705', player: '#c0392b', barbarian: '#7d7d7d' })[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="#8a6a43" opacity="0.28" />
|
||||
<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>
|
||||
|
|
@ -0,0 +1,266 @@
|
|||
<script setup lang="ts">
|
||||
import type { MapVillage, MapView } from '~/types/map'
|
||||
|
||||
const props = defineProps<{
|
||||
view: MapView
|
||||
/** Field size in px. */
|
||||
field: number
|
||||
selected: { x: number; y: number } | null
|
||||
}>()
|
||||
const emit = defineEmits<{
|
||||
select: [at: { x: number; y: number }]
|
||||
hover: [village: MapVillage | null]
|
||||
/** Move the centre by whole fields (drag or arrow keys). */
|
||||
pan: [dx: number, dy: number]
|
||||
}>()
|
||||
const { t } = useI18n()
|
||||
|
||||
const RULER = 26
|
||||
|
||||
const villageAt = computed(() => new Map(props.view.villages.map((v) => [`${v.x}|${v.y}`, v])))
|
||||
|
||||
// Same field, same look: terrain comes from a hash of the coordinates.
|
||||
const hash = (x: number, y: number) => {
|
||||
let h = (x * 73856093) ^ (y * 19349663)
|
||||
h = Math.imul(h ^ (h >>> 13), 1274126177)
|
||||
return ((h ^ (h >>> 16)) >>> 0) / 4294967296
|
||||
}
|
||||
const GRASS = ['#b9d08f', '#b1ca87', '#c0d596', '#acc580']
|
||||
|
||||
interface Field {
|
||||
x: number
|
||||
y: number
|
||||
px: number
|
||||
py: number
|
||||
grass: string
|
||||
village: MapVillage | null
|
||||
forest: number[] | null
|
||||
}
|
||||
|
||||
const fields = computed<Field[]>(() => {
|
||||
const out: Field[] = []
|
||||
for (let row = 0; row < props.view.h; row++) {
|
||||
for (let col = 0; col < props.view.w; col++) {
|
||||
const x = props.view.x + col
|
||||
const y = props.view.y + row
|
||||
const r = hash(x, y)
|
||||
const village = villageAt.value.get(`${x}|${y}`) ?? null
|
||||
out.push({
|
||||
x,
|
||||
y,
|
||||
px: col * props.field,
|
||||
py: row * props.field,
|
||||
grass: GRASS[Math.floor(r * GRASS.length)]!,
|
||||
village,
|
||||
// About one empty field in five is forest: 2–3 trees at hashed spots.
|
||||
forest: !village && r < 0.2 ? [hash(x + 1, y), hash(x, y + 1), hash(x + 2, y + 3)] : null,
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
})
|
||||
|
||||
const villageFields = computed(() => fields.value.filter((f) => f.village))
|
||||
|
||||
const tier = (points: number): 1 | 2 | 3 => (points < 60 ? 1 : points < 200 ? 2 : 3)
|
||||
const relation = (v: MapVillage) => (v.own ? 'own' : v.player ? 'player' : 'barbarian')
|
||||
|
||||
const width = computed(() => RULER + props.view.w * props.field)
|
||||
const height = computed(() => RULER + props.view.h * props.field)
|
||||
|
||||
// Sector lines every 10 fields, continent borders every 100.
|
||||
const lines = computed(() => {
|
||||
const out: { x1: number; y1: number; x2: number; y2: number; kind: 'sector' | 'continent' }[] = []
|
||||
for (let col = 0; col <= props.view.w; col++) {
|
||||
const x = props.view.x + col
|
||||
if (x % 10 === 0) {
|
||||
out.push({ x1: col * props.field, y1: 0, x2: col * props.field, y2: props.view.h * props.field, kind: x % 100 === 0 ? 'continent' : 'sector' })
|
||||
}
|
||||
}
|
||||
for (let row = 0; row <= props.view.h; row++) {
|
||||
const y = props.view.y + row
|
||||
if (y % 10 === 0) {
|
||||
out.push({ x1: 0, y1: row * props.field, x2: props.view.w * props.field, y2: row * props.field, kind: y % 100 === 0 ? 'continent' : 'sector' })
|
||||
}
|
||||
}
|
||||
return out
|
||||
})
|
||||
|
||||
// One label per continent in view, in its top-left visible corner.
|
||||
const continents = computed(() => {
|
||||
const seen = new Map<string, { label: string; px: number; py: number }>()
|
||||
for (const f of fields.value) {
|
||||
const label = `K${Math.floor(f.y / 100)}${Math.floor(f.x / 100)}`
|
||||
if (!seen.has(label)) seen.set(label, { label, px: f.px, py: f.py })
|
||||
}
|
||||
return [...seen.values()]
|
||||
})
|
||||
|
||||
const rulerFont = computed(() => Math.max(9, Math.min(12, props.field / 4)))
|
||||
|
||||
// Dragging pans by whole fields when released; a click without movement selects.
|
||||
const drag = ref<{ startX: number; startY: number; dx: number; dy: number; moved: boolean } | null>(null)
|
||||
|
||||
function onPointerDown(e: PointerEvent) {
|
||||
if (e.button !== 0) return
|
||||
drag.value = { startX: e.clientX, startY: e.clientY, dx: 0, dy: 0, moved: false }
|
||||
;(e.currentTarget as Element).setPointerCapture(e.pointerId)
|
||||
}
|
||||
|
||||
function onPointerMove(e: PointerEvent) {
|
||||
if (!drag.value) return
|
||||
drag.value.dx = e.clientX - drag.value.startX
|
||||
drag.value.dy = e.clientY - drag.value.startY
|
||||
if (Math.abs(drag.value.dx) + Math.abs(drag.value.dy) > 5) drag.value.moved = true
|
||||
}
|
||||
|
||||
function onPointerUp(e: PointerEvent) {
|
||||
const d = drag.value
|
||||
drag.value = null
|
||||
if (!d) return
|
||||
if (d.moved) {
|
||||
const dx = -Math.round(d.dx / props.field)
|
||||
const dy = -Math.round(d.dy / props.field)
|
||||
if (dx || dy) emit('pan', dx, dy)
|
||||
return
|
||||
}
|
||||
const rect = (e.currentTarget as Element).getBoundingClientRect()
|
||||
const col = Math.floor((e.clientX - rect.left - RULER) / props.field)
|
||||
const row = Math.floor((e.clientY - rect.top - RULER) / props.field)
|
||||
if (col >= 0 && row >= 0 && col < props.view.w && row < props.view.h) {
|
||||
emit('select', { x: props.view.x + col, y: props.view.y + row })
|
||||
}
|
||||
}
|
||||
|
||||
function onKey(e: KeyboardEvent) {
|
||||
const step = e.shiftKey ? 5 : 1
|
||||
const moves: Record<string, [number, number]> = {
|
||||
ArrowLeft: [-step, 0],
|
||||
ArrowRight: [step, 0],
|
||||
ArrowUp: [0, -step],
|
||||
ArrowDown: [0, step],
|
||||
}
|
||||
const move = moves[e.key]
|
||||
if (!move) return
|
||||
e.preventDefault()
|
||||
emit('pan', move[0], move[1])
|
||||
}
|
||||
|
||||
const panOffset = computed(() => (drag.value?.moved ? `translate(${drag.value.dx} ${drag.value.dy})` : undefined))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<svg
|
||||
:width="width"
|
||||
:height="height"
|
||||
:viewBox="`0 0 ${width} ${height}`"
|
||||
class="block touch-none select-none outline-none focus-visible:ring-2 focus-visible:ring-amber-600"
|
||||
:class="drag?.moved ? 'cursor-grabbing' : 'cursor-grab'"
|
||||
role="application"
|
||||
tabindex="0"
|
||||
:aria-label="t('map.aria')"
|
||||
@pointerdown="onPointerDown"
|
||||
@pointermove="onPointerMove"
|
||||
@pointerup="onPointerUp"
|
||||
@pointercancel="drag = null"
|
||||
@pointerleave="emit('hover', null)"
|
||||
@keydown="onKey"
|
||||
>
|
||||
<defs>
|
||||
<clipPath id="map-fields">
|
||||
<rect :x="RULER" :y="RULER" :width="view.w * field" :height="view.h * field" />
|
||||
</clipPath>
|
||||
</defs>
|
||||
|
||||
<g clip-path="url(#map-fields)">
|
||||
<g :transform="`translate(${RULER} ${RULER})`">
|
||||
<g :transform="panOffset">
|
||||
<g v-for="f in fields" :key="`${f.x}|${f.y}`" @pointerenter="emit('hover', f.village)">
|
||||
<rect :x="f.px" :y="f.py" :width="field" :height="field" :fill="f.grass" />
|
||||
<g v-if="f.forest" :transform="`translate(${f.px} ${f.py}) scale(${field / 100})`">
|
||||
<g v-for="(r, i) in f.forest" :key="i" :transform="`translate(${18 + r * 52 + i * 8} ${34 + ((r * 7) % 1) * 40 + i * 6})`">
|
||||
<rect x="-2" y="18" width="4" height="9" fill="#6b4b2e" />
|
||||
<polygon points="0,-10 -13,20 0,16" fill="#3f7a37" />
|
||||
<polygon points="0,-10 13,20 0,16" fill="#5d9a47" />
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
|
||||
<!-- Continent labels and lines lie on the ground, under the villages. -->
|
||||
<text
|
||||
v-for="c in continents"
|
||||
:key="c.label"
|
||||
:x="c.px + 5"
|
||||
:y="c.py + 19"
|
||||
font-size="17"
|
||||
font-weight="700"
|
||||
font-family="Georgia, serif"
|
||||
fill="rgb(43 33 24 / 0.28)"
|
||||
>
|
||||
{{ c.label }}
|
||||
</text>
|
||||
|
||||
<line
|
||||
v-for="(l, i) in lines"
|
||||
:key="i"
|
||||
:x1="l.x1"
|
||||
:y1="l.y1"
|
||||
:x2="l.x2"
|
||||
:y2="l.y2"
|
||||
:stroke="l.kind === 'continent' ? 'rgb(43 33 24 / 0.75)' : 'rgb(43 33 24 / 0.22)'"
|
||||
:stroke-width="l.kind === 'continent' ? 2.5 : 1"
|
||||
/>
|
||||
|
||||
<g
|
||||
v-for="f in villageFields"
|
||||
:key="`v${f.x}|${f.y}`"
|
||||
:transform="`translate(${f.px} ${f.py}) scale(${field / 100})`"
|
||||
class="pointer-events-none"
|
||||
>
|
||||
<MapVillageMarker :tier="tier(f.village!.points)" :relation="relation(f.village!)" />
|
||||
</g>
|
||||
|
||||
<rect
|
||||
v-if="selected && selected.x >= view.x && selected.y >= view.y && selected.x < view.x + view.w && selected.y < view.y + view.h"
|
||||
:x="(selected.x - view.x) * field + 1"
|
||||
:y="(selected.y - view.y) * field + 1"
|
||||
:width="field - 2"
|
||||
:height="field - 2"
|
||||
rx="4"
|
||||
fill="rgb(255 255 255 / 0.18)"
|
||||
stroke="#b45309"
|
||||
stroke-width="2.5"
|
||||
/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
|
||||
<!-- Coordinate rulers, Die Stämme style: x along the top, y down the side. -->
|
||||
<rect x="0" y="0" :width="width" :height="RULER" fill="#eee1c9" />
|
||||
<rect x="0" y="0" :width="RULER" :height="height" fill="#eee1c9" />
|
||||
<text
|
||||
v-for="col in view.w"
|
||||
:key="`x${col}`"
|
||||
:x="RULER + (col - 0.5) * field"
|
||||
:y="RULER / 2 + 4"
|
||||
text-anchor="middle"
|
||||
:font-size="rulerFont"
|
||||
fill="#4a3b2e"
|
||||
class="tabular-nums"
|
||||
>
|
||||
{{ view.x + col - 1 }}
|
||||
</text>
|
||||
<text
|
||||
v-for="row in view.h"
|
||||
:key="`y${row}`"
|
||||
:x="RULER / 2"
|
||||
:y="RULER + (row - 0.5) * field + 4"
|
||||
text-anchor="middle"
|
||||
:font-size="rulerFont"
|
||||
fill="#4a3b2e"
|
||||
class="tabular-nums"
|
||||
>
|
||||
{{ view.y + row - 1 }}
|
||||
</text>
|
||||
</svg>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
import type { MapView } from '~/types/map'
|
||||
|
||||
/** One world's map window. Only the newest request wins, so fast panning never shows an older window. */
|
||||
export function useMap(worldId: number) {
|
||||
const view = ref<MapView | null>(null)
|
||||
const error = ref<string | null>(null)
|
||||
const busy = ref(false)
|
||||
const errorText = useErrorText()
|
||||
let latest = 0
|
||||
|
||||
/** Without x/y the server opens on the player's own village in this world. */
|
||||
async function load(at: { x: number; y: number } | null, w: number, h: number) {
|
||||
const request = ++latest
|
||||
busy.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const result = await ws.send<MapView>('map.view', { world_id: worldId, w, h, ...at })
|
||||
if (request === latest) view.value = result
|
||||
} catch (e) {
|
||||
if (request === latest) error.value = errorText(e)
|
||||
} finally {
|
||||
if (request === latest) busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return { view, error, busy, load }
|
||||
}
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
<script setup lang="ts">
|
||||
import type { MapVillage } from '~/types/map'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const { view, error, busy, load } = useMap(Number(route.params.worldId))
|
||||
useState<number | null>('world.current', () => null).value = Number(route.params.worldId)
|
||||
|
||||
const ZOOM = [36, 52, 72]
|
||||
const zoom = ref(1)
|
||||
const field = computed(() => ZOOM[zoom.value]!)
|
||||
|
||||
// The window fills the space the page gives it: odd sizes keep the centre field in the middle.
|
||||
const box = ref<HTMLElement | null>(null)
|
||||
const size = ref({ w: 15, h: 11 })
|
||||
const odd = (n: number) => (n % 2 ? n : n - 1)
|
||||
const clamp = (n: number, lo: number, hi: number) => Math.max(lo, Math.min(hi, n))
|
||||
|
||||
function measure() {
|
||||
if (!box.value) return
|
||||
const rect = box.value.getBoundingClientRect()
|
||||
const height = Math.max(360, window.innerHeight - rect.top - 24)
|
||||
size.value = {
|
||||
w: clamp(odd(Math.floor((rect.width - 26) / field.value)), 5, 41),
|
||||
h: clamp(odd(Math.floor((height - 26) / field.value)), 5, 41),
|
||||
}
|
||||
}
|
||||
|
||||
let observer: ResizeObserver | undefined
|
||||
onMounted(() => {
|
||||
measure()
|
||||
observer = new ResizeObserver(measure)
|
||||
if (box.value) observer.observe(box.value)
|
||||
})
|
||||
onBeforeUnmount(() => observer?.disconnect())
|
||||
watch(field, measure)
|
||||
|
||||
/** Centre from the URL (?x=&y=), or null to open on the player's village. */
|
||||
const center = computed(() => {
|
||||
const x = Number(route.query.x)
|
||||
const y = Number(route.query.y)
|
||||
return Number.isFinite(x) && Number.isFinite(y) && route.query.x !== undefined ? { x, y } : null
|
||||
})
|
||||
|
||||
watch([center, size], () => load(center.value, size.value.w, size.value.h), { immediate: true, deep: true })
|
||||
|
||||
function goTo(at: { x: number; y: number }) {
|
||||
const max = (view.value?.size ?? 1000) - 1
|
||||
router.replace({ query: { x: clamp(Math.round(at.x), 0, max), y: clamp(Math.round(at.y), 0, max) } })
|
||||
}
|
||||
|
||||
function pan(dx: number, dy: number) {
|
||||
const from = view.value?.center
|
||||
if (from) goTo({ x: from.x + dx, y: from.y + dy })
|
||||
}
|
||||
|
||||
// Jump-to form, prefilled with the centre.
|
||||
const jumpX = ref<number | null>(null)
|
||||
const jumpY = ref<number | null>(null)
|
||||
watch(
|
||||
() => view.value?.center,
|
||||
(c) => {
|
||||
if (c) {
|
||||
jumpX.value = c.x
|
||||
jumpY.value = c.y
|
||||
}
|
||||
},
|
||||
)
|
||||
function jump() {
|
||||
if (jumpX.value !== null && jumpY.value !== null) goTo({ x: jumpX.value, y: jumpY.value })
|
||||
}
|
||||
|
||||
const selected = ref<{ x: number; y: number } | null>(null)
|
||||
const hovered = ref<MapVillage | null>(null)
|
||||
const selectedVillage = computed(() =>
|
||||
selected.value ? (view.value?.villages.find((v) => v.x === selected.value!.x && v.y === selected.value!.y) ?? null) : null,
|
||||
)
|
||||
const shown = computed(() => hovered.value ?? selectedVillage.value)
|
||||
|
||||
const counts = computed(() => {
|
||||
const villages = view.value?.villages ?? []
|
||||
return {
|
||||
own: villages.filter((v) => v.own).length,
|
||||
players: villages.filter((v) => v.player && !v.own).length,
|
||||
barbarians: villages.filter((v) => !v.player).length,
|
||||
}
|
||||
})
|
||||
|
||||
const continent = computed(() => (view.value ? `K${Math.floor(view.value.center.y / 100)}${Math.floor(view.value.center.x / 100)}` : ''))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="px-4 py-5 lg:px-6">
|
||||
<header class="mb-4 flex flex-wrap items-end justify-between gap-3">
|
||||
<div>
|
||||
<p class="text-xs font-medium tracking-wide text-ink-500 uppercase">{{ $t('map.subtitle') }}</p>
|
||||
<h1 class="font-display text-2xl font-semibold sm:text-3xl">
|
||||
{{ $t('map.title') }}
|
||||
<span v-if="view" class="ml-2 text-lg font-normal text-ink-500 tabular-nums">{{ view.center.x }}|{{ view.center.y }} · {{ continent }}</span>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<form class="flex items-center gap-1.5" @submit.prevent="jump">
|
||||
<label class="sr-only" for="jump-x">x</label>
|
||||
<input id="jump-x" v-model.number="jumpX" class="input w-20 py-1.5 text-center tabular-nums" type="number" min="0" :max="(view?.size ?? 1000) - 1" />
|
||||
<span class="font-semibold text-ink-500">|</span>
|
||||
<label class="sr-only" for="jump-y">y</label>
|
||||
<input id="jump-y" v-model.number="jumpY" class="input w-20 py-1.5 text-center tabular-nums" type="number" min="0" :max="(view?.size ?? 1000) - 1" />
|
||||
<button type="submit" class="btn btn-primary">{{ $t('map.jump') }}</button>
|
||||
</form>
|
||||
<button type="button" class="btn btn-outline" @click="router.replace({ query: {} })">{{ $t('map.home') }}</button>
|
||||
<div class="flex items-center rounded-lg border border-parchment-300 bg-white">
|
||||
<button type="button" class="btn btn-ghost px-2.5" :disabled="zoom === 0" :aria-label="$t('map.zoom_out')" @click="zoom--">−</button>
|
||||
<button type="button" class="btn btn-ghost px-2.5" :disabled="zoom === ZOOM.length - 1" :aria-label="$t('map.zoom_in')" @click="zoom++">+</button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<p v-if="error" class="alert mb-4" role="alert">{{ error }}</p>
|
||||
|
||||
<div class="grid gap-5 xl:grid-cols-[1fr_20rem]">
|
||||
<div ref="box" class="relative min-w-0">
|
||||
<div class="panel overflow-hidden p-0">
|
||||
<div class="flex justify-center overflow-hidden bg-[#a9c27d]">
|
||||
<MapWorldMap
|
||||
v-if="view"
|
||||
:view="view"
|
||||
:field="field"
|
||||
:selected="selected"
|
||||
@select="selected = $event"
|
||||
@hover="hovered = $event"
|
||||
@pan="pan"
|
||||
/>
|
||||
<p v-else class="py-24 text-sm text-ink-500">{{ $t('common.loading') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-2 flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-ink-500">
|
||||
<span>{{ $t('map.controls') }}</span>
|
||||
<span v-if="busy">{{ $t('common.loading') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<aside class="space-y-5">
|
||||
<MapInfoCard :village="shown" :at="selected" @center="goTo" />
|
||||
<section class="panel">
|
||||
<div class="panel-head">
|
||||
<h2 class="panel-title">{{ $t('map.legend.title') }}</h2>
|
||||
</div>
|
||||
<ul class="panel-body space-y-2 text-sm">
|
||||
<li class="flex items-center gap-2"><span class="size-3 rounded-sm bg-[#f2b705] ring-1 ring-ink-900/30" /> {{ $t('map.legend.own') }} <span class="ml-auto tabular-nums text-ink-500">{{ counts.own }}</span></li>
|
||||
<li class="flex items-center gap-2"><span class="size-3 rounded-sm bg-[#c0392b] ring-1 ring-ink-900/30" /> {{ $t('map.legend.players') }} <span class="ml-auto tabular-nums text-ink-500">{{ counts.players }}</span></li>
|
||||
<li class="flex items-center gap-2"><span class="size-3 rounded-sm bg-[#7d7d7d] ring-1 ring-ink-900/30" /> {{ $t('map.legend.barbarians') }} <span class="ml-auto tabular-nums text-ink-500">{{ counts.barbarians }}</span></li>
|
||||
<li class="pt-1 text-xs text-ink-500">{{ $t('map.legend.lines') }}</li>
|
||||
</ul>
|
||||
</section>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
// `map.view` payloads. Coordinates are map fields; continents are 100 × 100 (K55 holds 500|500).
|
||||
|
||||
export interface MapVillage {
|
||||
id: number
|
||||
x: number
|
||||
y: number
|
||||
name: string
|
||||
points: number
|
||||
continent: string
|
||||
/** null for barbarian villages. */
|
||||
player: { id: number; name: string } | null
|
||||
own: boolean
|
||||
}
|
||||
|
||||
/** `map.view {world_id, x?, y?, w, h}`: the w × h window around center, kept inside the map. */
|
||||
export interface MapView {
|
||||
world_id: number
|
||||
/** The map is size × size fields. */
|
||||
size: number
|
||||
center: { x: number; y: number }
|
||||
/** Top-left field of the window. */
|
||||
x: number
|
||||
y: number
|
||||
w: number
|
||||
h: number
|
||||
villages: MapVillage[]
|
||||
}
|
||||
|
|
@ -2,11 +2,12 @@ import { mergeMessages } from '@blax-software/i18n'
|
|||
import networking from '@blax-software/networking/i18n'
|
||||
import en from './locales/en'
|
||||
import auth from './pages/auth'
|
||||
import map from './pages/map'
|
||||
import village from './pages/village'
|
||||
import worlds from './pages/worlds'
|
||||
|
||||
// Explicit imports instead of import.meta.glob: @nuxtjs/i18n also loads this file in the
|
||||
// Nitro build, where glob imports don't exist. Add new page files here, in path order.
|
||||
export default mergeMessages({ en }, [auth, village, worlds], { packages: [networking] }) as {
|
||||
export default mergeMessages({ en }, [auth, map, village, worlds], { packages: [networking] }) as {
|
||||
en: Record<string, any>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
import type { TranslationFile } from '@blax-software/i18n'
|
||||
|
||||
export default {
|
||||
en: {
|
||||
map: {
|
||||
title: 'World map',
|
||||
subtitle: 'Map',
|
||||
aria: 'World map. Drag or use the arrow keys to move, click a field to select it.',
|
||||
jump: 'Go',
|
||||
home: 'My village',
|
||||
zoom_in: 'Zoom in',
|
||||
zoom_out: 'Zoom out',
|
||||
controls: 'Drag or use the arrow keys (Shift for 5 fields) to move. Click a field for details.',
|
||||
barbarian: 'Barbarians',
|
||||
info: {
|
||||
title: 'Field',
|
||||
coordinates: 'Coordinates',
|
||||
owner: 'Owner',
|
||||
points: 'Points',
|
||||
open: 'Open village',
|
||||
center: 'Centre here',
|
||||
empty: 'Empty field',
|
||||
hint: 'Hover or click a field to see who lives there.',
|
||||
},
|
||||
legend: {
|
||||
title: 'Legend',
|
||||
own: 'Your villages',
|
||||
players: 'Other players',
|
||||
barbarians: 'Barbarian villages',
|
||||
// {'|'} is a literal pipe: a bare | separates plural forms in vue-i18n.
|
||||
lines: "Thin lines mark sectors of 10 fields, thick lines the continents of 100 (K55 holds 500{'|'}500).",
|
||||
},
|
||||
},
|
||||
},
|
||||
} satisfies TranslationFile
|
||||
Loading…
Reference in New Issue