123 lines
5.7 KiB
Vue
123 lines
5.7 KiB
Vue
<script setup lang="ts">
|
|
const props = defineProps<{
|
|
/** Inside a world: show the world's menu (village, map, reports) and its clock. */
|
|
inWorld?: boolean
|
|
}>()
|
|
const { t } = useI18n()
|
|
const { user, logout } = useAuth()
|
|
const { current } = useCurrentWorld()
|
|
const { worlds, refresh } = useWorld()
|
|
const unread = useUnreadReports()
|
|
const { now } = useServerClock()
|
|
const route = useRoute()
|
|
|
|
const world = computed(() => (props.inWorld && current.value ? (worlds.value?.find((w) => w.id === current.value!.worldId) ?? null) : null))
|
|
if (props.inWorld && !worlds.value) refresh()
|
|
|
|
const home = computed(() => (props.inWorld && current.value?.villageId ? `/village/${current.value.villageId}` : '/worlds'))
|
|
const links = computed(() => {
|
|
const c = current.value
|
|
if (!props.inWorld || !c) return []
|
|
return [
|
|
...(c.villageId ? [{ key: 'village', to: `/village/${c.villageId}`, icon: 'home' as const, active: route.path.startsWith('/village/') }] : []),
|
|
{ key: 'map', to: `/map/${c.worldId}`, icon: 'pin' as const, active: route.path.startsWith('/map/') },
|
|
{ key: 'reports', to: `/reports/${c.worldId}`, icon: 'report' as const, active: route.path.startsWith('/reports/') },
|
|
]
|
|
})
|
|
|
|
/** The key that opens a menu entry (the village link opens its overview). */
|
|
const shortcutOf = (key: string) => SHORTCUTS[(key === 'village' ? 'overview' : key) as keyof typeof SHORTCUTS].toUpperCase()
|
|
|
|
const connection = computed(() =>
|
|
isMockServer
|
|
? { text: t('app.mock'), tone: 'bg-gold-400' }
|
|
: ws.is_opened.value
|
|
? { text: t('app.connected'), tone: 'bg-moss-500' }
|
|
: { text: t('app.offline'), tone: 'bg-blood-600' },
|
|
)
|
|
const clock = computed(() => new Date(now.value).toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false }))
|
|
|
|
// The account menu closes when a link in it is followed.
|
|
const menu = ref<HTMLDetailsElement | null>(null)
|
|
watch(() => route.fullPath, () => menu.value?.removeAttribute('open'))
|
|
</script>
|
|
|
|
<!-- The dark wooden bar on top of every page: the game's main menu, the server clock and the account. -->
|
|
<template>
|
|
<header class="border-b-4 border-wood-950 bg-wood-900 text-parchment-100">
|
|
<div class="mx-auto flex h-12 max-w-[96rem] items-center gap-1 px-2 sm:gap-2 sm:px-4">
|
|
<NuxtLink :to="home" class="mr-1 shrink-0 items-center gap-2" :class="links.length ? 'hidden sm:flex' : 'flex'" :title="t('app.title')">
|
|
<span class="grid size-8 place-items-center rounded-sm border border-gold-600 bg-blood-700 text-gold-400">
|
|
<IconBuilding type="headquarters" class="size-5" />
|
|
</span>
|
|
<span class="hidden font-display text-lg font-semibold text-gold-400 lg:inline" style="font-variant: small-caps">{{ t('app.title') }}</span>
|
|
</NuxtLink>
|
|
|
|
<nav v-if="links.length" class="flex items-center gap-0.5" :aria-label="t('app.menu')">
|
|
<NuxtLink
|
|
v-for="l in links"
|
|
:key="l.key"
|
|
:to="l.to"
|
|
class="menu-link"
|
|
:class="{ 'menu-link-active': l.active }"
|
|
:aria-current="l.active ? 'page' : undefined"
|
|
:title="t('app.shortcut', { key: shortcutOf(l.key) })"
|
|
>
|
|
<span class="relative">
|
|
<IconUi :name="l.icon" class="size-5 sm:size-4" />
|
|
<span
|
|
v-if="l.key === 'reports' && unread"
|
|
class="absolute -top-2 -right-2.5 min-w-4 rounded-full border border-wood-950 bg-gold-400 px-1 text-center text-[10px] leading-3.5 font-bold text-wood-950 sm:hidden"
|
|
>
|
|
{{ unread }}
|
|
</span>
|
|
</span>
|
|
<span class="hidden sm:inline">{{ t(`app.${l.key}`) }}</span>
|
|
<span v-if="l.key === 'reports' && unread" class="hidden rounded-sm bg-gold-400 px-1.5 text-xs font-bold text-wood-950 sm:inline" :title="t('app.unread_reports', { count: unread })">
|
|
{{ unread }}
|
|
</span>
|
|
</NuxtLink>
|
|
</nav>
|
|
|
|
<div class="ml-auto flex min-w-0 items-center gap-2 sm:gap-3">
|
|
<span v-if="world" class="hidden truncate text-sm text-parchment-300 md:inline">{{ world.name }}</span>
|
|
<span v-if="user" class="flex items-center gap-1.5 text-sm tabular-nums text-parchment-200" :title="`${t('app.server_time')} · ${connection.text}`">
|
|
<span class="size-2 rounded-full" :class="connection.tone" />
|
|
{{ clock }}
|
|
</span>
|
|
<details v-if="user" ref="menu" class="relative">
|
|
<summary class="menu-link list-none" :title="t('app.account')">
|
|
<IconUi name="users" class="size-4" />
|
|
<span class="hidden max-w-32 truncate md:inline">{{ user.name }}</span>
|
|
</summary>
|
|
<div class="absolute right-0 z-50 mt-2 w-52 rounded-sm border-2 border-wood-950 bg-parchment-50 py-1 text-sm text-ink-900 shadow-hard">
|
|
<p class="truncate border-b border-parchment-300 px-3 py-1.5 font-semibold">{{ user.name }}</p>
|
|
<NuxtLink to="/worlds" class="account-item">
|
|
<IconUi name="globe" class="size-4" />
|
|
{{ t('app.change_world') }}
|
|
</NuxtLink>
|
|
<button type="button" class="account-item w-full" @click="logout()">
|
|
<IconUi name="logout" class="size-4" />
|
|
{{ t('app.logout') }}
|
|
</button>
|
|
</div>
|
|
</details>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
</template>
|
|
|
|
<style scoped>
|
|
@reference "~/assets/css/main.css";
|
|
|
|
.menu-link {
|
|
@apply inline-flex h-9 items-center gap-1.5 rounded-sm border border-transparent px-2.5 text-sm font-semibold text-parchment-100 transition-colors hover:border-wood-600 hover:bg-wood-800 focus-visible:outline-2 focus-visible:outline-gold-500;
|
|
}
|
|
.menu-link-active {
|
|
@apply border-gold-600 bg-wood-800 text-gold-400;
|
|
}
|
|
.account-item {
|
|
@apply flex items-center gap-2 px-3 py-1.5 text-left hover:bg-parchment-200;
|
|
}
|
|
</style>
|