49 lines
1.3 KiB
Vue
49 lines
1.3 KiB
Vue
<script setup lang="ts">
|
||
const { worlds, error, busy, refresh, join } = useWorld()
|
||
const mock = isMockServer
|
||
|
||
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>
|
||
<section>
|
||
<h1>{{ $t('worlds.title') }}</h1>
|
||
<p v-if="error" role="alert">{{ error }}</p>
|
||
<p v-if="!worlds">{{ $t('common.loading') }}</p>
|
||
<p v-else-if="!worlds.length">{{ $t('worlds.none') }}</p>
|
||
<table v-else>
|
||
<thead>
|
||
<tr>
|
||
<th>{{ $t('worlds.name') }}</th>
|
||
<th>{{ $t('worlds.speed') }}</th>
|
||
<th>{{ $t('worlds.village') }}</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr v-for="w in worlds" :key="w.id">
|
||
<td>{{ w.name }}</td>
|
||
<td>{{ w.speed }}×</td>
|
||
<td>
|
||
<button type="button" :disabled="busy" @click="enter(w.id)">
|
||
{{ w.village_id ? $t('worlds.open') : $t('worlds.join') }}
|
||
</button>
|
||
</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<p v-if="mock">
|
||
<button type="button" :disabled="busy" @click="resetMock">{{ $t('worlds.reset') }}</button>
|
||
</p>
|
||
</section>
|
||
</template>
|