feat: launch: world overview with stats and every setting, account page (password, delete), lost villages announced and left, fresh start for fallen players, ended-world banner

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-30 11:30:34 +01:00
parent 5de40ad5d7
commit c01527f161
10 changed files with 350 additions and 4 deletions

View File

@ -154,6 +154,7 @@ watch(() => route.fullPath, () => menuKey.value++)
</button>
<div class="menu-drop right-0 left-auto">
<NuxtLink to="/worlds" class="menu-drop-item">{{ t('app.change_world') }}</NuxtLink>
<NuxtLink to="/account" class="menu-drop-item">{{ t('app.account') }}</NuxtLink>
<button type="button" class="menu-drop-item w-full text-left" @click="logout()">{{ t('app.logout') }}</button>
</div>
</div>

View File

@ -1,5 +1,6 @@
<script setup lang="ts">
import type { SceneInset } from '~/diorama/scene'
import type { VillageLost } from '~/types/game'
const props = defineProps<{ villageId: number }>()
// One village state for every screen in the world: the village header, the village's
@ -69,6 +70,16 @@ const screenTitle = computed(() => {
})
const picked = computed(() => !!plot.value)
// A village of ours was taken ("geadelt"): say so, and leave its screens for another
// village, or for the worlds page where a fresh start waits.
const notices = useNotices()
ws.listenWhileMounted<VillageLost>('village:lost', null, (lost) => {
notices.push(t(lost.by ? 'village.lost' : 'village.lost_unknown', { name: lost.name, x: lost.x, y: lost.y, by: lost.by }), 'error')
if (lost.village_id !== props.villageId) return v.refresh()
const next = v.village.value?.villages.find((o) => o.id !== lost.village_id)
navigateTo(next ? `/village/${next.id}` : '/worlds')
})
// Esc closes what is open: the window back to the overview, or the build card. A native
// dialog (the quest book) closes itself first.
function onEscape(e: KeyboardEvent) {
@ -169,6 +180,10 @@ useShortcuts(() => {
:seconds-until="v.secondsUntil"
/>
<div v-if="v.village.value" class="pointer-events-auto space-y-1 empty:hidden">
<p v-if="v.village.value.season.winner" class="border border-gold-600 bg-parchment-100 px-2 py-0.5 text-sm text-wood-900">
{{ $t('village.world_ended', { player: v.village.value.season.winner.name }) }}
<NuxtLink to="/worlds" class="ml-2 font-semibold text-blood-700 underline">{{ $t('village.season.next') }}</NuxtLink>
</p>
<VillageFoodWarning :starvation="v.village.value.starvation" :levy="v.village.value.levy" :seconds-until="v.secondsUntil" />
</div>
<p v-if="v.error.value" class="alert pointer-events-auto" role="alert">{{ v.error.value }}</p>

View File

@ -1195,9 +1195,50 @@ const handlers: Record<string, Handler> = {
WORLDS.map((w) => ({
...w,
village_id: state.villages.find((v) => v.world_id === w.id && v.user_id === user.id)?.id ?? null,
fallen: false,
started_at: iso(Date.now() - 3 * 86_400_000),
players: state.villages.filter((v) => v.world_id === w.id).length,
villages: state.villages.filter((v) => v.world_id === w.id).length,
tribes: (state.tribes ?? []).filter((t) => t.world_id === w.id).length,
crowns_at: iso(Date.now() - 86_400_000),
holder: null,
ends_at: null,
ended_at: null,
winner: null,
})),
// Rough numbers: the backend's config is the truth.
'world.settings': (_state, _user, data) => {
const w = WORLDS.find((w) => w.id === Number(data.world_id)) ?? fail('not_found')
const s = (seconds: number) => Math.round(seconds / w.speed)
return {
id: w.id,
name: w.name,
settings: {
pace: { speed: w.speed, unit_speed: 1, protection: s(3 * 86400), inactive: 14 * 86400 },
village: { space: 40, space_per_hq_level: 5, builders: 2, map_size: 1000 },
combat: { morale: true, luck: 25, night: null, noble_distance: 100, loyalty_drop: [20, 35], loyalty_regen: w.speed },
raids: { every: [s(18 * 3600), s(30 * 3600)], warning: s(3 * 3600), range: 15 },
tribes: { max_members: 25, notice: s(86400) },
season: { crowns: 5, needed: 3, crowns_after: s(30 * 86400), hold: s(7 * 86400) },
},
}
},
'account.show': (state, user) => ({
name: user.name,
email: user.email,
since: iso(Date.now()),
worlds: WORLDS.filter((w) => state.villages.some((v) => v.world_id === w.id && v.user_id === user.id)).map((w) => ({
world: { id: w.id, name: w.name },
villages: state.villages.filter((v) => v.world_id === w.id && v.user_id === user.id).length,
points: 0,
tribe: null,
})),
}),
'account.password': (state, user, data) => {
if (String(data.password ?? '').length < 8) fail('password_short')
return handlers['account.show']!(state, user, data, Date.now())
},
'account.delete': () => ({ deleted: true }),
'world.join': (state, user, data, now) => {
const world = WORLDS.find((w) => w.id === Number(data.world_id)) ?? fail('not_found')

126
app/pages/account.vue Normal file
View File

@ -0,0 +1,126 @@
<script setup lang="ts">
import type { AccountState } from '~/types/game'
const errorText = useErrorText()
const notices = useNotices()
const { t } = useI18n()
const { logout } = useAuth()
const account = ref<AccountState | null>(null)
const error = ref<string | null>(null)
const busy = ref(false)
async function call<T>(event: string, data: object = {}) {
busy.value = true
error.value = null
try {
return await ws.send<T>(event, data)
} catch (e) {
error.value = errorText(e)
return null
} finally {
busy.value = false
}
}
call<AccountState>('account.show').then((a) => (account.value = a))
const pw = reactive({ current: '', next: '', again: '' })
async function changePassword() {
if (pw.next !== pw.again) {
error.value = t('auth.password_mismatch')
return
}
const a = await call<AccountState>('account.password', { current: pw.current, password: pw.next })
if (a) {
account.value = a
Object.assign(pw, { current: '', next: '', again: '' })
notices.push(t('account.password_changed'), 'success')
}
}
const leave = reactive({ password: '', sure: false })
async function deleteAccount() {
if (!leave.sure) return
if (await call('account.delete', { password: leave.password })) {
logout()
await navigateTo('/')
}
}
</script>
<!-- The account: who you are on which worlds, a new password, and leaving for good. -->
<template>
<div>
<div class="mx-auto max-w-3xl space-y-4 px-4 py-8 text-sm">
<h1 class="font-display text-3xl font-semibold text-wood-900" style="font-variant: small-caps">{{ $t('account.title') }}</h1>
<p v-if="error" class="alert" role="alert">{{ error }}</p>
<p v-if="!account" class="text-ink-500">{{ $t('common.loading') }}</p>
<template v-else>
<section class="panel">
<div class="panel-head"><h2 class="panel-title">{{ account.name }}</h2></div>
<dl class="grid grid-cols-[auto_1fr] gap-x-6 gap-y-1 p-3">
<dt class="text-ink-500">{{ $t('auth.email') }}</dt>
<dd>{{ account.email }}</dd>
<dt class="text-ink-500">{{ $t('account.since') }}</dt>
<dd>{{ new Date(account.since).toLocaleDateString() }}</dd>
</dl>
<table v-if="account.worlds.length" class="grid-table">
<thead>
<tr>
<th>{{ $t('account.world') }}</th>
<th class="text-right">{{ $t('account.villages') }}</th>
<th class="text-right">{{ $t('account.points') }}</th>
<th>{{ $t('account.tribe') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="w in account.worlds" :key="w.world.id">
<td class="font-semibold">{{ w.world.name }}</td>
<td class="text-right tabular-nums">{{ w.villages }}</td>
<td class="text-right tabular-nums">{{ w.points }}</td>
<td>{{ w.tribe ? `${w.tribe.name} [${w.tribe.tag}]` : '' }}</td>
</tr>
</tbody>
</table>
</section>
<section class="panel">
<div class="panel-head"><h2 class="panel-title">{{ $t('account.password') }}</h2></div>
<form class="grid gap-3 p-3 sm:grid-cols-3" @submit.prevent="changePassword">
<label class="block">
<span class="label">{{ $t('account.current') }}</span>
<input v-model="pw.current" class="input" type="password" autocomplete="current-password" required />
</label>
<label class="block">
<span class="label">{{ $t('account.new') }}</span>
<input v-model="pw.next" class="input" type="password" autocomplete="new-password" required />
</label>
<label class="block">
<span class="label">{{ $t('auth.password_again') }}</span>
<input v-model="pw.again" class="input" type="password" autocomplete="new-password" required />
</label>
<div class="sm:col-span-3">
<button type="submit" class="btn btn-primary" :disabled="busy">{{ $t('account.change') }}</button>
</div>
</form>
</section>
<section class="panel border-blood-700">
<div class="panel-head"><h2 class="panel-title text-blood-700">{{ $t('account.delete') }}</h2></div>
<form class="space-y-3 p-3" @submit.prevent="deleteAccount">
<p>{{ $t('account.delete_text') }}</p>
<label class="block max-w-xs">
<span class="label">{{ $t('auth.password') }}</span>
<input v-model="leave.password" class="input" type="password" autocomplete="current-password" required />
</label>
<label class="flex items-center gap-2">
<input v-model="leave.sure" type="checkbox" />
{{ $t('account.delete_sure') }}
</label>
<button type="submit" class="btn btn-attack" :disabled="busy || !leave.sure">{{ $t('account.delete_button') }}</button>
</form>
</section>
</template>
</div>
<GameFooter />
</div>
</template>

View File

@ -1,5 +1,5 @@
<script setup lang="ts">
import type { StartDirection } from '~/types/game'
import type { StartDirection, WorldSettings } from '~/types/game'
const { worlds, error, busy, refresh, join } = useWorld()
const mock = isMockServer
@ -16,6 +16,34 @@ async function enter(worldId: number, direction: StartDirection = 'random') {
const choosing = ref<number | null>(null)
const DIRECTIONS: StartDirection[] = ['nw', 'ne', 'random', 'sw', 'se']
const { t } = useI18n()
const clock = useNow()
const settings = ref<Record<number, WorldSettings>>({})
const open = ref<number | null>(null)
async function toggleSettings(id: number) {
open.value = open.value === id ? null : id
if (open.value && !settings.value[id]) settings.value[id] = await ws.send<WorldSettings>('world.settings', { world_id: id })
}
const span = (s: number) => formatSpan(s, t)
/** A setting's value in words: durations, shares, switches. */
function rule(name: string, value: unknown): string {
if (typeof value === 'boolean') return t(value ? 'worlds.on' : 'worlds.off')
if (value === null) return t('worlds.off')
if (['protection', 'notice', 'hold', 'crowns_after', 'warning'].includes(name)) return span(value as number)
if (name === 'inactive') return value ? span(value as number) : t('worlds.off')
if (name === 'every') return (value as number[]).map(span).join(' – ')
if (name === 'speed' || name === 'unit_speed') return `${value}×`
if (name === 'luck') return `±${value}%`
if (name === 'loyalty_drop') return (value as number[]).join(' – ')
if (name === 'night') {
const n = value as { start: number; end: number; factor: number }
return t('worlds.night', { start: n.start, end: n.end, factor: n.factor })
}
return String(value)
}
const until = (iso: string) => Math.max(0, (Date.parse(iso) - clock.value) / 1000)
const age = (iso: string) => Math.max(0, Math.floor((clock.value - Date.parse(iso)) / 86_400_000))
async function resetMock() {
await ws.send('mock.reset')
await refresh()
@ -23,7 +51,7 @@ async function resetMock() {
</script>
<template>
<div class="mx-auto max-w-2xl px-4 py-10">
<div class="mx-auto max-w-3xl 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>
@ -44,8 +72,17 @@ async function resetMock() {
<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>
<span v-if="w.fallen" class="badge badge-plain text-blood-700">{{ $t('worlds.fallen') }}</span>
<span v-if="w.ended_at" class="badge badge-plain">{{ w.winner ? $t('worlds.won_by', { player: w.winner.name }) : $t('worlds.ended') }}</span>
</p>
<p class="mt-1 text-sm text-ink-700">
{{ $t('worlds.stats', { players: w.players, villages: w.villages, tribes: w.tribes, days: age(w.started_at) }) }}
</p>
<p v-if="!w.ended_at" class="text-sm text-ink-700">
<template v-if="w.holder && w.ends_at">{{ $t('worlds.holds', { player: w.holder.name, time: span(until(w.ends_at)) }) }}</template>
<template v-else-if="until(w.crowns_at) > 0">{{ $t('worlds.crowns_in', { time: span(until(w.crowns_at)) }) }}</template>
<template v-else>{{ $t('worlds.crowns_stand') }}</template>
</p>
</div>
<div class="flex w-full gap-2 sm:w-auto">
<button
@ -56,10 +93,29 @@ async function resetMock() {
:disabled="busy"
@click="w.village_id ? enter(w.id) : (choosing = choosing === w.id ? null : w.id)"
>
{{ w.village_id ? $t('worlds.open') : $t('worlds.join') }}
{{ w.village_id ? $t('worlds.open') : w.fallen ? $t('worlds.restart') : $t('worlds.join') }}
</button>
<button type="button" class="btn btn-outline" :aria-expanded="open === w.id" @click="toggleSettings(w.id)">{{ $t('worlds.settings') }}</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 world's rules, like Die Stämme's world settings. -->
<div v-if="open === w.id" class="w-full border border-wood-700 bg-parchment-50 text-sm">
<p v-if="!settings[w.id]" class="p-3 text-ink-500">{{ $t('common.loading') }}</p>
<div v-else class="grid gap-x-6 sm:grid-cols-2">
<dl v-for="(group, key) in settings[w.id]!.settings" :key="key" class="grid content-start grid-cols-[1fr_auto] gap-x-3 gap-y-0.5 border-b border-parchment-300 p-2">
<dt class="col-span-2 mb-0.5 font-semibold text-wood-900">{{ $t(`worlds.groups.${key}`) }}</dt>
<template v-if="!group">
<dt class="text-ink-500">{{ $t('worlds.off') }}</dt>
<dd />
</template>
<template v-for="(value, name) in group ?? {}" v-else :key="name">
<dt class="text-ink-700">{{ $t(`worlds.rules.${name}`) }}</dt>
<dd class="text-right font-semibold tabular-nums">{{ rule(String(name), value) }}</dd>
</template>
</dl>
</div>
</div>
<div v-if="w.fallen && choosing !== w.id" class="w-full border border-blood-700 bg-[#f0d6c8] px-3 py-2 text-sm text-blood-800">{{ $t('worlds.fallen_hint') }}</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-sm font-semibold">{{ $t('worlds.start') }}</p>

View File

@ -63,11 +63,54 @@ export interface WorldSummary {
slug: string
speed: number
village_id: number | null
/** Joined once and lost every village: a fresh start is open. */
fallen: boolean
started_at: string
players: number
villages: number
tribes: number
/** When the crown forts appear, or appeared. */
crowns_at: string
holder: { id: number; name: string } | null
/** When the holder wins if they keep the crowns. */
ends_at: string | null
/** Set once someone won the world; it stays readable. */
ended_at: string | null
winner: { id: number; name: string } | null
}
/** `world.settings`: the rules in plain units; durations in seconds at the world's speed. */
export interface WorldSettings {
id: number
name: string
settings: {
pace: { speed: number; unit_speed: number; protection: number; inactive: number }
village: { space: number; space_per_hq_level: number; builders: number; map_size: number }
combat: { morale: boolean; luck: number; night: { start: number; end: number; factor: number } | null; noble_distance: number; loyalty_drop: [number, number]; loyalty_regen: number }
raids: { every: [number, number]; warning: number; range: number } | null
tribes: { max_members: number; notice: number }
season: { crowns: number; needed: number; crowns_after: number; hold: number } | null
}
}
/** `account.show`. */
export interface AccountState {
name: string
email: string
since: string
worlds: { world: { id: number; name: string }; villages: number; points: number; tribe: TribeRef | null }[]
}
/** Push `village:lost` to the old owner of a village that was taken. */
export interface VillageLost {
world_id: number
village_id: number
name: string
x: number
y: number
by: string | null
}
/** A world as a season: crown forts appear round 0|0, holding most of them long enough wins. */
export interface SeasonState {
/** When the crowns appear, or appeared. */

View File

@ -1,6 +1,7 @@
import { mergeMessages } from '@blax-software/i18n'
import networking from '@blax-software/networking/i18n'
import en from './locales/en'
import account from './pages/account'
import auth from './pages/auth'
import chat from './pages/chat'
import landing from './pages/landing'
@ -15,6 +16,6 @@ import worlds from './pages/worlds'
// Explicit imports instead of import.meta.glob: @nuxtjs/i18n also loads this file in the
// Nitro build, where glob imports don't exist. Add new page files here, in path order.
export default mergeMessages({ en }, [auth, chat, landing, legal, map, quests, ranking, reports, tribe, village, worlds], { packages: [networking] }) as {
export default mergeMessages({ en }, [account, auth, chat, landing, legal, map, quests, ranking, reports, tribe, village, worlds], { packages: [networking] }) as {
en: Record<string, any>
}

23
i18n/pages/account.ts Normal file
View File

@ -0,0 +1,23 @@
import type { TranslationFile } from '@blax-software/i18n'
export default {
en: {
account: {
title: 'Account',
since: 'Playing since',
world: 'World',
villages: 'Villages',
points: 'Points',
tribe: 'Tribe',
password: 'Change password',
current: 'Current password',
new: 'New password',
change: 'Change password',
password_changed: 'Your password is changed.',
delete: 'Delete account',
delete_text: 'This cannot be undone. On every world your villages turn barbarian, a tribe you lead goes to its next member, and your account, reports and chat messages are deleted.',
delete_sure: 'Yes, delete my account for good.',
delete_button: 'Delete account',
},
},
} satisfies TranslationFile

View File

@ -81,6 +81,9 @@ export default {
fields: '{fields} fields',
detection: 'Spots incoming troops {fields} fields further out',
},
lost: "{by} took {name} ({x}{'|'}{y}). The report tells how.",
lost_unknown: "{name} ({x}{'|'}{y}) is no longer yours.",
world_ended: 'This world has ended: {player} holds the crown. Nothing changes here any more.',
season: {
title: 'Season',
crowns_in: "Crown forts appear round 0{'|'}0 in {time}.",

View File

@ -12,6 +12,43 @@ export default {
joined: 'Your village is here',
village: 'Your village',
join: 'Join',
restart: 'Start again',
fallen: 'Your villages fell',
fallen_hint: 'Every village you had here was taken. Start again with a new village on the edge of the world, under beginner protection.',
stats: '{players} players · {villages} villages · {tribes} tribes · day {days}',
holds: '{player} holds the crowns and wins in {time}.',
crowns_in: 'The crown forts appear in {time}.',
crowns_stand: 'The crown forts stand; nobody holds enough of them yet.',
settings: 'Settings',
on: 'on',
off: 'off',
night: '{start}–{end} h, defence ×{factor}',
groups: { pace: 'Pace', village: 'Villages', combat: 'Combat and conquest', raids: 'Raiders', tribes: 'Tribes', season: 'Season' },
rules: {
speed: 'World speed',
unit_speed: 'Unit speed',
protection: 'Beginner protection',
inactive: 'Abandoned villages turn barbarian after',
space: 'Building space at the start',
space_per_hq_level: 'More space per headquarters level',
builders: 'Builders',
map_size: 'Map size (fields per side)',
morale: 'Morale',
luck: 'Luck',
night: 'Night bonus',
noble_distance: 'Noblemen march at most (fields)',
loyalty_drop: 'Loyalty lost per nobleman',
loyalty_regen: 'Loyalty regained per hour',
every: 'A raid every',
warning: 'Warning ahead of a raid',
range: 'Raiding camps within (fields)',
max_members: 'Members per tribe',
notice: 'Notice to end a pact',
crowns: 'Crown forts',
needed: 'Crowns to hold',
crowns_after: 'Crown forts appear after',
hold: 'Hold them for',
},
ended: 'Ended',
won_by: 'Won by {player}',
open: 'Open village',