From 4b82bc9d4542175e61c0ff38e681a8628e29042c Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Wed, 28 Oct 2026 17:57:44 +0100 Subject: [PATCH] feat: world list with join Co-Authored-By: Claude Opus 5.5 --- app/composables/useWorld.ts | 28 ++++++++++++++++++++++ app/pages/worlds.vue | 48 +++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 app/composables/useWorld.ts create mode 100644 app/pages/worlds.vue diff --git a/app/composables/useWorld.ts b/app/composables/useWorld.ts new file mode 100644 index 0000000..07c1f03 --- /dev/null +++ b/app/composables/useWorld.ts @@ -0,0 +1,28 @@ +import type { WorldSummary } from '~/types/game' + +export function useWorld() { + const worlds = useState('worlds', () => null) + const error = ref(null) + const busy = ref(false) + const errorText = useErrorText() + + async function run(fn: () => Promise) { + busy.value = true + error.value = null + try { + return await fn() + } catch (e) { + error.value = errorText(e) + } finally { + busy.value = false + } + } + + const refresh = () => run(async () => (worlds.value = await ws.send('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) + + return { worlds, error, busy, refresh, join } +} diff --git a/app/pages/worlds.vue b/app/pages/worlds.vue new file mode 100644 index 0000000..d4584a4 --- /dev/null +++ b/app/pages/worlds.vue @@ -0,0 +1,48 @@ + + +