feat: in-world header with Village and Map; changing worlds is a quiet link
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
af096c6d08
commit
36e47d48ce
32
app/app.vue
32
app/app.vue
|
|
@ -2,8 +2,14 @@
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const { user, logout } = useAuth()
|
const { user, logout } = useAuth()
|
||||||
const notices = useNotices()
|
const notices = useNotices()
|
||||||
/** The world of the village or map on screen, for the Map link. */
|
const route = useRoute()
|
||||||
const currentWorld = useState<number | null>('world.current', () => null)
|
const { current } = useCurrentWorld()
|
||||||
|
|
||||||
|
/** Inside a world (village or map) the header is that world's navigation. */
|
||||||
|
const inWorld = computed(() => !!current.value && /^\/(village|map)\//.test(route.path))
|
||||||
|
const home = computed(() =>
|
||||||
|
inWorld.value && current.value?.villageId ? `/village/${current.value.villageId}` : '/worlds',
|
||||||
|
)
|
||||||
|
|
||||||
const connection = computed(() =>
|
const connection = computed(() =>
|
||||||
isMockServer
|
isMockServer
|
||||||
|
|
@ -28,7 +34,7 @@ useHead({ title: () => t('app.title') })
|
||||||
<!-- A dark wooden bar, like a tavern sign board. -->
|
<!-- A dark wooden bar, like a tavern sign board. -->
|
||||||
<header class="border-b-4 border-wood-950 bg-wood-900 text-parchment-100">
|
<header class="border-b-4 border-wood-950 bg-wood-900 text-parchment-100">
|
||||||
<div class="flex items-center gap-2 px-4 py-2 sm:gap-3 sm:px-6">
|
<div class="flex items-center gap-2 px-4 py-2 sm:gap-3 sm:px-6">
|
||||||
<NuxtLink to="/" class="flex min-w-0 items-center gap-2">
|
<NuxtLink :to="home" class="flex min-w-0 items-center gap-2">
|
||||||
<span class="grid size-8 shrink-0 place-items-center rounded-sm border border-gold-600 bg-blood-700 text-gold-400">
|
<span class="grid size-8 shrink-0 place-items-center rounded-sm border border-gold-600 bg-blood-700 text-gold-400">
|
||||||
<IconBuilding type="headquarters" class="size-5" />
|
<IconBuilding type="headquarters" class="size-5" />
|
||||||
</span>
|
</span>
|
||||||
|
|
@ -37,12 +43,17 @@ useHead({ title: () => t('app.title') })
|
||||||
</span>
|
</span>
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
|
|
||||||
<nav v-if="user" class="ml-1 flex items-center gap-1">
|
<nav v-if="user && inWorld && current" class="ml-1 flex items-center gap-1">
|
||||||
<NuxtLink to="/worlds" class="nav-link" active-class="nav-link-active">
|
<NuxtLink
|
||||||
<IconUi name="globe" class="size-4" />
|
v-if="current.villageId"
|
||||||
{{ t('app.worlds') }}
|
:to="`/village/${current.villageId}`"
|
||||||
|
class="nav-link"
|
||||||
|
active-class="nav-link-active"
|
||||||
|
>
|
||||||
|
<IconBuilding type="headquarters" class="size-4" />
|
||||||
|
{{ t('app.village') }}
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
<NuxtLink v-if="currentWorld" :to="`/map/${currentWorld}`" class="nav-link" active-class="nav-link-active">
|
<NuxtLink :to="`/map/${current.worldId}`" class="nav-link" active-class="nav-link-active">
|
||||||
<IconUi name="pin" class="size-4" />
|
<IconUi name="pin" class="size-4" />
|
||||||
{{ t('app.map') }}
|
{{ t('app.map') }}
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
|
|
@ -56,6 +67,11 @@ useHead({ title: () => t('app.title') })
|
||||||
</span>
|
</span>
|
||||||
<template v-if="user">
|
<template v-if="user">
|
||||||
<span class="hidden truncate text-sm text-parchment-300 md:inline">{{ user.name }}</span>
|
<span class="hidden truncate text-sm text-parchment-300 md:inline">{{ user.name }}</span>
|
||||||
|
<!-- Leaving the world is a quiet way out, not a tab. -->
|
||||||
|
<NuxtLink v-if="inWorld" to="/worlds" class="nav-link px-2" :title="t('app.change_world')">
|
||||||
|
<IconUi name="globe" class="size-4" />
|
||||||
|
<span class="hidden lg:inline">{{ t('app.change_world') }}</span>
|
||||||
|
</NuxtLink>
|
||||||
<button type="button" class="nav-link px-2" :title="t('app.logout')" @click="logout()">
|
<button type="button" class="nav-link px-2" :title="t('app.logout')" @click="logout()">
|
||||||
<IconUi name="logout" class="size-4" />
|
<IconUi name="logout" class="size-4" />
|
||||||
<span class="hidden sm:inline">{{ t('app.logout') }}</span>
|
<span class="hidden sm:inline">{{ t('app.logout') }}</span>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
export interface CurrentWorld {
|
||||||
|
worldId: number
|
||||||
|
/** The player's village there, once known. */
|
||||||
|
villageId: number | null
|
||||||
|
}
|
||||||
|
|
||||||
|
const KEY = 'vp.world'
|
||||||
|
|
||||||
|
function read(): CurrentWorld | null {
|
||||||
|
try {
|
||||||
|
const raw = localStorage.getItem(KEY)
|
||||||
|
return raw ? JSON.parse(raw) : null
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The world the player is in. Inside a world the header only shows that world's
|
||||||
|
* navigation; remembered across reloads so the Village link stays.
|
||||||
|
*/
|
||||||
|
export function useCurrentWorld() {
|
||||||
|
const current = useState<CurrentWorld | null>('world.current', read)
|
||||||
|
|
||||||
|
function enter(worldId: number, villageId: number | null = null) {
|
||||||
|
const keep = current.value?.worldId === worldId ? current.value.villageId : null
|
||||||
|
current.value = { worldId, villageId: villageId ?? keep }
|
||||||
|
try {
|
||||||
|
localStorage.setItem(KEY, JSON.stringify(current.value))
|
||||||
|
} catch {
|
||||||
|
// only the Village link after a reload is lost
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { current, enter }
|
||||||
|
}
|
||||||
|
|
@ -4,7 +4,7 @@ import type { MapVillage } from '~/types/map'
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { view, error, busy, load } = useMap(Number(route.params.worldId))
|
const { view, error, busy, load } = useMap(Number(route.params.worldId))
|
||||||
useState<number | null>('world.current', () => null).value = Number(route.params.worldId)
|
useCurrentWorld().enter(Number(route.params.worldId))
|
||||||
|
|
||||||
// The minimap: a 61 × 61 window around the same centre, refetched when the centre moves.
|
// The minimap: a 61 × 61 window around the same centre, refetched when the centre moves.
|
||||||
const overview = useMap(Number(route.params.worldId))
|
const overview = useMap(Number(route.params.worldId))
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,9 @@ watch(selectedBuilding, (b) => {
|
||||||
|
|
||||||
const spaceShare = computed(() => (village.value ? village.value.space.used / village.value.space.max : 0))
|
const spaceShare = computed(() => (village.value ? village.value.space.used / village.value.space.max : 0))
|
||||||
|
|
||||||
const currentWorld = useState<number | null>('world.current', () => null)
|
const { enter } = useCurrentWorld()
|
||||||
watch(village, (v) => {
|
watch(village, (v) => {
|
||||||
if (v) currentWorld.value = v.world_id
|
if (v) enter(v.world_id, v.id)
|
||||||
})
|
})
|
||||||
|
|
||||||
v.refresh()
|
v.refresh()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const { worlds, error, busy, refresh, join } = useWorld()
|
const { worlds, error, busy, refresh, join } = useWorld()
|
||||||
const mock = isMockServer
|
const mock = isMockServer
|
||||||
|
const { enter: enterWorld } = useCurrentWorld()
|
||||||
|
|
||||||
refresh()
|
refresh()
|
||||||
|
|
||||||
|
|
@ -48,7 +49,7 @@ async function resetMock() {
|
||||||
>
|
>
|
||||||
{{ w.village_id ? $t('worlds.open') : $t('worlds.join') }}
|
{{ w.village_id ? $t('worlds.open') : $t('worlds.join') }}
|
||||||
</button>
|
</button>
|
||||||
<NuxtLink v-if="w.village_id" :to="`/map/${w.id}`" class="btn btn-outline">{{ $t('worlds.map') }}</NuxtLink>
|
<NuxtLink v-if="w.village_id" :to="`/map/${w.id}`" class="btn btn-outline" @click="enterWorld(w.id, w.village_id)">{{ $t('worlds.map') }}</NuxtLink>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
export default {
|
export default {
|
||||||
app: {
|
app: {
|
||||||
title: 'Village Politics',
|
title: 'Village Politics',
|
||||||
worlds: 'Worlds',
|
|
||||||
map: 'Map',
|
map: 'Map',
|
||||||
|
village: 'Village',
|
||||||
|
change_world: 'Change world',
|
||||||
logout: 'Log out',
|
logout: 'Log out',
|
||||||
mock: 'Mock server, no backend',
|
mock: 'Mock server, no backend',
|
||||||
connected: 'Connected',
|
connected: 'Connected',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue