2026-10-28 23:38:54 +00:00
|
|
|
<script setup lang="ts">
|
2026-10-29 10:15:26 +00:00
|
|
|
import type { SceneInset } from '~/diorama/scene'
|
2026-10-30 10:30:34 +00:00
|
|
|
import type { VillageLost } from '~/types/game'
|
2026-10-28 23:38:54 +00:00
|
|
|
const props = defineProps<{ villageId: number }>()
|
|
|
|
|
|
2026-10-29 00:26:08 +00:00
|
|
|
// One village state for every screen in the world: the village header, the village's
|
|
|
|
|
// own screens, the map and the reports all read it through useVillageContext().
|
2026-10-28 23:38:54 +00:00
|
|
|
const v = useVillage(props.villageId)
|
|
|
|
|
provideVillage(v)
|
|
|
|
|
v.refresh()
|
|
|
|
|
|
|
|
|
|
const { enter } = useCurrentWorld()
|
|
|
|
|
watch(v.village, (state) => {
|
|
|
|
|
if (state) enter(state.world_id, state.id)
|
|
|
|
|
})
|
feat: rally point tabs, map village popups, report filters, beginner protection bar, keyboard shortcuts
Ideas taken from how Die Stämme works, in our own look: the rally point splits into
commands, troops and simulator; hovering a village on the map shows its owner, points
and distance, a click offers send troops and centre; reports filter by attacks,
defence and support; a dismissible bar counts down beginner protection; one key per
screen (V, H, T, P, W, M, R); resources in the village bar lead to the workforce.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 00:00:13 +00:00
|
|
|
|
2026-10-29 09:15:36 +00:00
|
|
|
// The quest book opens by itself when a quest is newly complete, like Die Stämme's.
|
|
|
|
|
// What the player has already seen is kept per world, so a reload doesn't reopen it.
|
|
|
|
|
const questBook = useQuestBookOpen()
|
|
|
|
|
watch(
|
|
|
|
|
() => v.village.value && { world: v.village.value.world_id, claimable: v.village.value.quests.claimable },
|
|
|
|
|
(now) => {
|
|
|
|
|
if (!now) return
|
|
|
|
|
const key = `vp.quests.${now.world}`
|
|
|
|
|
let seen = 0
|
|
|
|
|
try {
|
|
|
|
|
seen = Number(localStorage.getItem(key) ?? 0)
|
|
|
|
|
localStorage.setItem(key, String(now.claimable))
|
|
|
|
|
} catch {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (now.claimable > seen) questBook.value = true
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
2026-10-29 14:59:48 +00:00
|
|
|
// Every page of the world fills the screen with the same bars and docks over it, so
|
|
|
|
|
// nothing moves when hopping between them: the village behind its own screens and the
|
|
|
|
|
// reports, the map behind itself.
|
2026-10-29 09:56:52 +00:00
|
|
|
const route = useRoute()
|
|
|
|
|
const base = computed(() => `/village/${props.villageId}`)
|
2026-10-29 14:59:48 +00:00
|
|
|
const onMap = computed(() => route.path.startsWith('/map/'))
|
2026-10-29 09:56:52 +00:00
|
|
|
const overview = computed(() => route.path === base.value || route.path === `${base.value}/`)
|
2026-10-29 13:38:34 +00:00
|
|
|
const { plot, clear } = useVillageSelection()
|
2026-10-29 09:56:52 +00:00
|
|
|
clear()
|
2026-10-29 13:38:34 +00:00
|
|
|
// An empty plot's build card lives on the overview.
|
|
|
|
|
watch(plot, (p) => {
|
2026-10-29 14:59:48 +00:00
|
|
|
if (p && !overview.value) navigateTo(base.value)
|
2026-10-29 13:38:34 +00:00
|
|
|
})
|
|
|
|
|
// Clicking a building enters it: its screen opens in the window, and the building stays
|
|
|
|
|
// outlined in the village while it is open. Clicking it again goes back to the overview.
|
|
|
|
|
const openBuilding = computed(() => (v.village.value ? buildingOfRoute(v.village.value, route.path, route.query) : null))
|
|
|
|
|
const selected = computed<number | null>({
|
|
|
|
|
get: () => openBuilding.value?.id ?? null,
|
|
|
|
|
set: (id) => {
|
|
|
|
|
const village = v.village.value
|
|
|
|
|
const building = id !== null ? village?.buildings.find((b) => b.id === id) : null
|
|
|
|
|
navigateTo(village && building ? buildingRoute(village, building) : base.value)
|
|
|
|
|
},
|
2026-10-29 09:56:52 +00:00
|
|
|
})
|
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
const screenTitle = computed(() => {
|
2026-10-29 13:38:34 +00:00
|
|
|
if (route.path.startsWith(`${base.value}/building/`) && openBuilding.value && v.village.value) {
|
|
|
|
|
return buildingName(v.village.value, openBuilding.value, t)
|
|
|
|
|
}
|
2026-10-29 14:59:48 +00:00
|
|
|
if (route.path.startsWith('/reports/')) return t('reports.title')
|
2026-10-29 15:27:21 +00:00
|
|
|
if (route.path.startsWith('/ranking/')) return t('app.ranking')
|
2026-10-30 09:54:16 +00:00
|
|
|
if (route.path.startsWith('/tribe/')) return t('app.tribe')
|
2026-10-29 09:56:52 +00:00
|
|
|
const s = VILLAGE_SCREENS.find((s) => s.path && route.path.startsWith(`${base.value}${s.path}`))
|
|
|
|
|
return s ? t(`village.screens.${s.name}`) : ''
|
|
|
|
|
})
|
2026-10-29 13:38:34 +00:00
|
|
|
const picked = computed(() => !!plot.value)
|
2026-10-30 10:41:32 +00:00
|
|
|
/**
|
|
|
|
|
* Every screen but the overview and the map is a page of its own: the building screens,
|
|
|
|
|
* the reports, the ranking, the tribe. The village shows only on its overview.
|
|
|
|
|
*/
|
|
|
|
|
const page = computed(() => !overview.value && !onMap.value)
|
|
|
|
|
/** The world's pages carry their title in a band; building screens have their own header. */
|
|
|
|
|
const pageTitle = computed(() => (route.path.startsWith(`${base.value}/`) ? '' : screenTitle.value))
|
2026-10-29 09:56:52 +00:00
|
|
|
|
2026-10-30 10:30:34 +00:00
|
|
|
// A village of ours was taken ("geadelt"): say so, and leave its screens for another
|
|
|
|
|
// village, or for the worlds page where a fresh start waits.
|
|
|
|
|
const notices = useNotices()
|
|
|
|
|
ws.listenWhileMounted<VillageLost>('village:lost', null, (lost) => {
|
|
|
|
|
notices.push(t(lost.by ? 'village.lost' : 'village.lost_unknown', { name: lost.name, x: lost.x, y: lost.y, by: lost.by }), 'error')
|
|
|
|
|
if (lost.village_id !== props.villageId) return v.refresh()
|
|
|
|
|
const next = v.village.value?.villages.find((o) => o.id !== lost.village_id)
|
|
|
|
|
navigateTo(next ? `/village/${next.id}` : '/worlds')
|
|
|
|
|
})
|
|
|
|
|
|
feat: the village at a glance: a tag over every building with its live number, stock cells with amount, limit and rate, a click outside a window closes it
Camps show production, storage its fullest resource against the limit, the farm
free villagers, the HQ building space, military buildings what they train, the
rally point its troops (red under attack), wall, hiding place and watchtower their
effect. While a window or build card is open, a click in the village only closes
it; Esc closes too.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-30 09:15:22 +00:00
|
|
|
// Esc closes what is open: the window back to the overview, or the build card. A native
|
|
|
|
|
// dialog (the quest book) closes itself first.
|
|
|
|
|
function onEscape(e: KeyboardEvent) {
|
|
|
|
|
if (e.key !== 'Escape' || e.defaultPrevented || document.querySelector('dialog[open]')) return
|
|
|
|
|
const el = e.target as HTMLElement | null
|
|
|
|
|
if (el && ['INPUT', 'TEXTAREA', 'SELECT'].includes(el.tagName)) return
|
|
|
|
|
if (picked.value) clear()
|
|
|
|
|
}
|
|
|
|
|
onMounted(() => window.addEventListener('keydown', onEscape))
|
|
|
|
|
onBeforeUnmount(() => window.removeEventListener('keydown', onEscape))
|
|
|
|
|
|
2026-10-29 14:59:48 +00:00
|
|
|
// The map draws itself under the menu bar; it needs to know where that ends.
|
|
|
|
|
const menuBar = ref<HTMLElement | null>(null)
|
|
|
|
|
const menuBottom = ref(0)
|
|
|
|
|
provideStage({ menuBottom })
|
2026-10-29 10:15:26 +00:00
|
|
|
// What the bars, the right column and the phone tab bar cover, so the whole village fits
|
|
|
|
|
// into the rest of the screen while land and forest run on beneath them.
|
|
|
|
|
const topBars = ref<HTMLElement | null>(null)
|
|
|
|
|
const sideColumn = ref<HTMLElement | null>(null)
|
|
|
|
|
const inset = ref<SceneInset>({ top: 0, right: 0, bottom: 0, left: 0 })
|
|
|
|
|
const snap = (n: number) => Math.round(n / 8) * 8
|
|
|
|
|
function measureInset() {
|
2026-10-29 14:43:33 +00:00
|
|
|
// The layout viewport, without the page scrollbar every page keeps.
|
|
|
|
|
const W = document.documentElement.clientWidth
|
|
|
|
|
const H = document.documentElement.clientHeight
|
2026-10-29 10:15:26 +00:00
|
|
|
const top = topBars.value?.getBoundingClientRect().bottom ?? 0
|
2026-10-29 14:59:48 +00:00
|
|
|
menuBottom.value = Math.round(menuBar.value?.getBoundingClientRect().bottom ?? 0)
|
2026-10-29 10:15:26 +00:00
|
|
|
const side = sideColumn.value?.getBoundingClientRect()
|
|
|
|
|
const shown = side && side.width > 0 && side.height > 0
|
|
|
|
|
// A column on the right takes its width; on phones the boxes sit at the bottom instead.
|
|
|
|
|
const right = shown && side.left > W / 2 ? W - side.left : 0
|
|
|
|
|
const sheet = shown && side.left <= W / 2 ? H - side.top : 0
|
|
|
|
|
const tabBar = W < 768 ? 56 : 0
|
|
|
|
|
const next = { top: snap(top), right: snap(right), bottom: snap(Math.max(sheet, tabBar)), left: 0 }
|
|
|
|
|
if (JSON.stringify(next) !== JSON.stringify(inset.value)) inset.value = next
|
|
|
|
|
}
|
|
|
|
|
let insetObserver: ResizeObserver | undefined
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
insetObserver = new ResizeObserver(measureInset)
|
|
|
|
|
window.addEventListener('resize', measureInset)
|
|
|
|
|
})
|
2026-10-29 14:59:48 +00:00
|
|
|
watch([topBars, sideColumn, picked, overview, onMap], async () => {
|
2026-10-29 10:15:26 +00:00
|
|
|
await nextTick()
|
|
|
|
|
insetObserver?.disconnect()
|
|
|
|
|
for (const el of [topBars.value, sideColumn.value]) if (el) insetObserver?.observe(el)
|
|
|
|
|
measureInset()
|
|
|
|
|
}, { flush: 'post' })
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
|
insetObserver?.disconnect()
|
|
|
|
|
window.removeEventListener('resize', measureInset)
|
|
|
|
|
})
|
|
|
|
|
|
2026-10-29 00:26:08 +00:00
|
|
|
// One key per screen of the world, as the menu and quick bar titles show.
|
feat: rally point tabs, map village popups, report filters, beginner protection bar, keyboard shortcuts
Ideas taken from how Die Stämme works, in our own look: the rally point splits into
commands, troops and simulator; hovering a village on the map shows its owner, points
and distance, a click offers send troops and centre; reports filter by attacks,
defence and support; a dismissible bar counts down beginner protection; one key per
screen (V, H, T, P, W, M, R); resources in the village bar lead to the workforce.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 00:00:13 +00:00
|
|
|
useShortcuts(() => {
|
|
|
|
|
const base = `/village/${props.villageId}`
|
|
|
|
|
const worldId = v.village.value?.world_id
|
|
|
|
|
return {
|
|
|
|
|
...Object.fromEntries(VILLAGE_SCREENS.map((s) => [s.name, `${base}${s.path}`])),
|
2026-10-30 09:54:16 +00:00
|
|
|
...(worldId ? { map: `/map/${worldId}`, reports: `/reports/${worldId}`, ranking: `/ranking/${worldId}`, tribe: `/tribe/${worldId}` } : {}),
|
feat: rally point tabs, map village popups, report filters, beginner protection bar, keyboard shortcuts
Ideas taken from how Die Stämme works, in our own look: the rally point splits into
commands, troops and simulator; hovering a village on the map shows its owner, points
and distance, a click offers send troops and centre; reports filter by attacks,
defence and support; a dismissible bar counts down beginner protection; one key per
screen (V, H, T, P, W, M, R); resources in the village bar lead to the workforce.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 00:00:13 +00:00
|
|
|
}
|
|
|
|
|
})
|
2026-10-28 23:38:54 +00:00
|
|
|
</script>
|
|
|
|
|
|
2026-10-29 14:59:48 +00:00
|
|
|
<!--
|
2026-10-30 10:53:13 +00:00
|
|
|
Every page of the world across the full width, under the menu and the village bar: on
|
|
|
|
|
the overview the village fills the screen with its boxes docked on the right, the map
|
2026-10-30 11:11:15 +00:00
|
|
|
fills it itself, and every other screen is a page (building pages: their work on the
|
|
|
|
|
left, the building itself on the right).
|
2026-10-29 14:59:48 +00:00
|
|
|
-->
|
2026-10-28 23:38:54 +00:00
|
|
|
<template>
|
2026-10-29 14:59:48 +00:00
|
|
|
<div>
|
2026-10-30 11:11:15 +00:00
|
|
|
<!-- A screen of its own, across the full width under the menu and the village bar. -->
|
2026-10-30 10:41:32 +00:00
|
|
|
<div v-if="page" class="min-h-dvh pb-14 md:pb-0">
|
|
|
|
|
<GameMenuBar in-world />
|
2026-10-30 10:53:13 +00:00
|
|
|
<div class="space-y-1 px-1 pt-1 sm:px-2">
|
2026-10-30 10:41:32 +00:00
|
|
|
<GameVillageBar v-if="v.village.value && v.resources.value" :village="v.village.value" :resources="v.resources.value" />
|
|
|
|
|
<GameVillageNotices :village-id="villageId" />
|
|
|
|
|
</div>
|
2026-10-30 11:11:15 +00:00
|
|
|
<main class="px-1 pt-1.5 pb-4 sm:px-2">
|
|
|
|
|
<div class="frame @container">
|
|
|
|
|
<div v-if="pageTitle" class="panel-head"><h1 class="panel-title">{{ pageTitle }}</h1></div>
|
|
|
|
|
<slot />
|
|
|
|
|
</div>
|
|
|
|
|
</main>
|
2026-10-30 10:41:32 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<template v-else>
|
2026-10-29 14:59:48 +00:00
|
|
|
<div v-if="!onMap" class="fixed inset-0 z-0">
|
2026-10-29 09:56:52 +00:00
|
|
|
<VillageDiorama
|
|
|
|
|
v-if="v.village.value"
|
|
|
|
|
v-model:selected="selected"
|
|
|
|
|
v-model:plot="plot"
|
|
|
|
|
fill
|
2026-10-29 10:15:26 +00:00
|
|
|
:inset="inset"
|
2026-10-29 09:56:52 +00:00
|
|
|
:village="v.village.value"
|
feat: the village at a glance: a tag over every building with its live number, stock cells with amount, limit and rate, a click outside a window closes it
Camps show production, storage its fullest resource against the limit, the farm
free villagers, the HQ building space, military buildings what they train, the
rally point its troops (red under attack), wall, hiding place and watchtower their
effect. While a window or build card is open, a click in the village only closes
it; Esc closes too.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-30 09:15:22 +00:00
|
|
|
:resources="v.resources.value"
|
2026-10-30 10:41:32 +00:00
|
|
|
:dismiss="picked"
|
2026-10-29 09:56:52 +00:00
|
|
|
:seconds-until="v.secondsUntil"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2026-10-29 14:59:48 +00:00
|
|
|
<!-- The map draws itself across the screen and puts its panels into the dock. -->
|
|
|
|
|
<slot v-else />
|
|
|
|
|
|
2026-10-29 09:56:52 +00:00
|
|
|
<div class="pointer-events-none fixed inset-0 z-10 flex flex-col">
|
2026-10-29 13:09:03 +00:00
|
|
|
<div ref="topBars" class="shrink-0">
|
2026-10-30 10:53:13 +00:00
|
|
|
<div ref="menuBar"><GameMenuBar class="pointer-events-auto" in-world /></div>
|
2026-10-29 09:56:52 +00:00
|
|
|
<div class="space-y-1 px-1 pt-1 sm:px-2">
|
|
|
|
|
<GameVillageBar v-if="v.village.value && v.resources.value" :village="v.village.value" :resources="v.resources.value" />
|
2026-10-30 10:41:32 +00:00
|
|
|
<div class="pointer-events-auto space-y-1 empty:hidden">
|
|
|
|
|
<GameVillageNotices :village-id="villageId" />
|
2026-10-29 13:09:03 +00:00
|
|
|
</div>
|
2026-10-29 09:56:52 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="flex min-h-0 flex-1 items-start gap-2 p-1 pb-14 sm:p-2 md:pb-2">
|
2026-10-30 10:41:32 +00:00
|
|
|
<!-- Left, on the overview: the build card of an empty plot picked in the village. -->
|
|
|
|
|
<div v-if="!onMap" v-show="picked" class="scroll-y float pointer-events-auto max-h-full w-full border border-wood-900 bg-parchment-200 p-1.5 sm:w-80">
|
|
|
|
|
<slot />
|
|
|
|
|
</div>
|
2026-10-29 09:56:52 +00:00
|
|
|
|
2026-10-29 14:59:48 +00:00
|
|
|
<!-- Right: the village's boxes, or on the map its own panels. -->
|
|
|
|
|
<!-- On the map it is there from the start: the map's panels teleport into it. -->
|
2026-10-29 09:56:52 +00:00
|
|
|
<div
|
2026-10-29 14:59:48 +00:00
|
|
|
v-if="v.village.value || onMap"
|
2026-10-29 10:15:26 +00:00
|
|
|
ref="sideColumn"
|
2026-10-29 14:25:26 +00:00
|
|
|
class="scroll-y float pointer-events-auto ml-auto max-h-full w-[17.5rem] shrink-0 border border-wood-900 bg-parchment-200"
|
2026-10-29 09:56:52 +00:00
|
|
|
:class="overview && !picked ? 'max-lg:w-full max-lg:self-end max-lg:max-h-[45dvh]' : 'hidden lg:block'"
|
|
|
|
|
>
|
2026-10-29 14:59:48 +00:00
|
|
|
<div v-if="onMap" id="stage-dock" class="space-y-2 p-2" />
|
|
|
|
|
<VillageOverviewSidebar v-else-if="v.village.value" :village="v.village.value" :base="base" :seconds-until="v.secondsUntil" />
|
2026-10-29 09:56:52 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-10-30 10:41:32 +00:00
|
|
|
</template>
|
2026-10-29 09:56:52 +00:00
|
|
|
<GameTabBar :village-id="villageId" />
|
|
|
|
|
<QuestBook v-if="v.village.value" />
|
2026-10-30 09:59:07 +00:00
|
|
|
<GameChat v-if="v.village.value" :world-id="v.village.value.world_id" :tribe="!!v.village.value.tribe.tribe" />
|
2026-10-29 09:56:52 +00:00
|
|
|
</div>
|
2026-10-28 23:38:54 +00:00
|
|
|
</template>
|