game-village-politics-frontend/app/components/game/VillageFrame.vue

73 lines
2.4 KiB
Vue
Raw Normal View History

<script setup lang="ts">
const props = defineProps<{ villageId: number }>()
// 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().
const v = useVillage(props.villageId)
provideVillage(v)
v.refresh()
const { enter } = useCurrentWorld()
watch(v.village, (state) => {
if (state) enter(state.world_id, state.id)
})
// 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
},
)
// One key per screen of the world, as the menu and quick bar titles show.
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}`])),
...(worldId ? { map: `/map/${worldId}`, reports: `/reports/${worldId}` } : {}),
}
})
</script>
<!-- The centred column: village header, thin notices, then the framed content. -->
<template>
<div>
<div class="mx-auto max-w-[1100px] space-y-1 px-1 pt-1.5 sm:px-2">
<GameVillageBar v-if="v.village.value && v.resources.value" :village="v.village.value" :resources="v.resources.value" />
<GameProtectionBar
v-if="v.village.value?.rally.protected_until"
:until="v.village.value.rally.protected_until"
:village-id="villageId"
:seconds-until="v.secondsUntil"
/>
<VillageFoodWarning
v-if="v.village.value"
:starvation="v.village.value.starvation"
:levy="v.village.value.levy"
:seconds-until="v.secondsUntil"
/>
<p v-if="v.error.value" class="alert" role="alert">{{ v.error.value }}</p>
</div>
<main class="mx-auto max-w-[1100px] px-1 pt-1 pb-4 sm:px-2">
<div class="frame">
<slot />
</div>
</main>
<GameTabBar :village-id="villageId" />
<QuestBook v-if="v.village.value" />
</div>
</template>