feat: pick a start direction when joining a world
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b072231ba7
commit
ab2062698e
|
|
@ -1,4 +1,4 @@
|
|||
import type { WorldSummary } from '~/types/game'
|
||||
import type { StartDirection, WorldSummary } from '~/types/game'
|
||||
|
||||
export function useWorld() {
|
||||
const worlds = useState<WorldSummary[] | null>('worlds', () => null)
|
||||
|
|
@ -20,9 +20,9 @@ export function useWorld() {
|
|||
|
||||
const refresh = () => run(async () => (worlds.value = await ws.send<WorldSummary[]>('world.index')))
|
||||
|
||||
/** Joins (or re-enters) a world and returns the player's village there. */
|
||||
const join = (worldId: number) =>
|
||||
run(async () => (await ws.send<{ village_id: number }>('world.join', { world_id: worldId })).village_id)
|
||||
/** Joins (or re-enters) a world, starting in the given quarter of the map, and returns the player's village there. */
|
||||
const join = (worldId: number, direction: StartDirection = 'random') =>
|
||||
run(async () => (await ws.send<{ village_id: number }>('world.join', { world_id: worldId, direction })).village_id)
|
||||
|
||||
return { worlds, error, busy, refresh, join }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,21 @@
|
|||
<script setup lang="ts">
|
||||
import type { StartDirection } from '~/types/game'
|
||||
|
||||
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)
|
||||
async function enter(worldId: number, direction: StartDirection = 'random') {
|
||||
const villageId = await join(worldId, direction)
|
||||
if (villageId) await navigateTo(`/village/${villageId}`)
|
||||
}
|
||||
|
||||
// A new player picks where to start, like the direction choice in Die Stämme.
|
||||
const choosing = ref<number | null>(null)
|
||||
const DIRECTIONS: StartDirection[] = ['nw', 'ne', 'random', 'sw', 'se']
|
||||
|
||||
async function resetMock() {
|
||||
await ws.send('mock.reset')
|
||||
await refresh()
|
||||
|
|
@ -46,12 +52,30 @@ async function resetMock() {
|
|||
class="btn flex-1 sm:flex-none"
|
||||
:class="w.village_id ? 'btn-primary' : 'btn-outline'"
|
||||
:disabled="busy"
|
||||
@click="enter(w.id)"
|
||||
@click="w.village_id ? enter(w.id) : (choosing = choosing === w.id ? null : 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>
|
||||
<!-- The start direction: a small compass of five buttons. -->
|
||||
<div v-if="choosing === w.id && !w.village_id" class="w-full border border-wood-700 bg-parchment-200 p-2">
|
||||
<p class="text-[13px] font-semibold">{{ $t('worlds.start') }}</p>
|
||||
<p class="mb-2 text-xs text-ink-500">{{ $t('worlds.start_hint') }}</p>
|
||||
<div class="grid w-64 grid-cols-2 gap-1">
|
||||
<button
|
||||
v-for="d in DIRECTIONS"
|
||||
:key="d"
|
||||
type="button"
|
||||
class="btn"
|
||||
:class="d === 'random' ? 'btn-primary col-span-2' : 'btn-outline'"
|
||||
:disabled="busy"
|
||||
@click="enter(w.id, d)"
|
||||
>
|
||||
{{ $t(`worlds.directions.${d}`) }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@ export interface AuthResult {
|
|||
user: AuthUser
|
||||
}
|
||||
|
||||
/** Where a new village starts: anywhere on the frontier, or in one quarter of the map. */
|
||||
export type StartDirection = 'random' | 'nw' | 'ne' | 'sw' | 'se'
|
||||
|
||||
/** One row of `world.index`. */
|
||||
export interface WorldSummary {
|
||||
id: number
|
||||
|
|
@ -69,7 +72,7 @@ export interface VillageState {
|
|||
name: string
|
||||
x: number
|
||||
y: number
|
||||
/** Map continent, e.g. K55 for 500|500. */
|
||||
/** Map continent, e.g. K55 for 0|0 to 99|99. */
|
||||
continent: string
|
||||
/** Sum of the buildings' level points, as shown on the map. */
|
||||
points: number
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ export default {
|
|||
protected: 'That player is still under beginner protection.',
|
||||
protected_self: 'Under beginner protection you can only attack barbarian villages.',
|
||||
too_late: 'Too late to call it back.',
|
||||
direction: 'Pick a start direction.',
|
||||
name: 'A village name has 1 to 32 characters.',
|
||||
world_full: 'This world is full.',
|
||||
},
|
||||
|
|
|
|||
|
|
@ -15,6 +15,10 @@ export default {
|
|||
open: 'Open village',
|
||||
none: 'No worlds yet.',
|
||||
reset: 'Reset mock data',
|
||||
start: 'Where do you want to start?',
|
||||
start_hint: "The world grows outward from its centre at 0{'|'}0; new villages settle on its edge.",
|
||||
directions: { random: 'Anywhere', nw: 'North-west', ne: 'North-east', sw: 'South-west', se: 'South-east' },
|
||||
cancel: 'Cancel',
|
||||
},
|
||||
},
|
||||
} satisfies TranslationFile
|
||||
|
|
|
|||
Loading…
Reference in New Issue