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

53 lines
1.8 KiB
Vue

<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)
})
// 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" />
</div>
</template>