66 lines
2.6 KiB
Vue
66 lines
2.6 KiB
Vue
<script setup lang="ts">
|
|
const { worlds, error, busy, refresh, join } = useWorld()
|
|
const mock = isMockServer
|
|
const { enter: enterWorld } = useCurrentWorld()
|
|
|
|
refresh()
|
|
|
|
async function enter(worldId: number) {
|
|
const villageId = await join(worldId)
|
|
if (villageId) await navigateTo(`/village/${villageId}`)
|
|
}
|
|
|
|
async function resetMock() {
|
|
await ws.send('mock.reset')
|
|
await refresh()
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="mx-auto max-w-2xl px-4 py-10">
|
|
<header class="mb-6">
|
|
<h1 class="font-display text-3xl font-semibold text-wood-900" style="font-variant: small-caps">{{ $t('worlds.title') }}</h1>
|
|
<p class="mt-1 text-ink-500">{{ $t('worlds.subtitle') }}</p>
|
|
</header>
|
|
|
|
<p v-if="error" class="alert mb-4" role="alert">{{ error }}</p>
|
|
|
|
<div class="panel overflow-hidden">
|
|
<p v-if="!worlds" class="px-4 py-8 text-center text-sm text-ink-500">{{ $t('common.loading') }}</p>
|
|
<p v-else-if="!worlds.length" class="px-4 py-8 text-center text-sm text-ink-500">{{ $t('worlds.none') }}</p>
|
|
<ul v-else class="divide-y-2 divide-parchment-200">
|
|
<li v-for="w in worlds" :key="w.id" class="flex flex-wrap items-center gap-x-4 gap-y-3 px-4 py-4">
|
|
<span class="grid size-11 shrink-0 place-items-center rounded-sm border-2 border-wood-700 bg-moss-600 text-parchment-50">
|
|
<IconUi name="globe" class="size-6" />
|
|
</span>
|
|
<div class="min-w-0 flex-1">
|
|
<p class="truncate font-display text-lg font-semibold text-wood-900">{{ w.name }}</p>
|
|
<p class="mt-0.5 flex flex-wrap gap-1.5">
|
|
<span class="badge badge-plain">{{ $t('worlds.speed_value', { speed: w.speed }) }}</span>
|
|
<span v-if="w.village_id" class="badge badge-moss">{{ $t('worlds.joined') }}</span>
|
|
</p>
|
|
</div>
|
|
<div class="flex w-full gap-2 sm:w-auto">
|
|
<button
|
|
type="button"
|
|
class="btn flex-1 sm:flex-none"
|
|
:class="w.village_id ? 'btn-primary' : 'btn-outline'"
|
|
:disabled="busy"
|
|
@click="enter(w.id)"
|
|
>
|
|
{{ w.village_id ? $t('worlds.open') : $t('worlds.join') }}
|
|
</button>
|
|
<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>
|
|
</div>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<p v-if="mock" class="mt-6 text-center">
|
|
<button type="button" class="btn btn-ghost text-xs text-ink-500" :disabled="busy" @click="resetMock">
|
|
{{ $t('worlds.reset') }}
|
|
</button>
|
|
</p>
|
|
</div>
|
|
</template>
|