feat: tribes in the client: tribe page with news, members and roles, invites, diplomacy and all tribes; menu entry with invites count, key S; tribe ranking and tags
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4063939bec
commit
5ad01b9d98
|
|
@ -12,6 +12,8 @@ const { user, logout } = useAuth()
|
|||
const { current } = useCurrentWorld()
|
||||
const { worlds, refresh } = useWorld()
|
||||
const unread = useUnreadReports()
|
||||
const villageContext = useVillageContextOrNull()
|
||||
const villageState = computed(() => villageContext?.village.value ?? null)
|
||||
const { now } = useServerClock()
|
||||
const route = useRoute()
|
||||
|
||||
|
|
@ -19,7 +21,7 @@ const world = computed(() => (props.inWorld && current.value ? (worlds.value?.fi
|
|||
if (props.inWorld && !worlds.value) refresh()
|
||||
|
||||
interface Entry {
|
||||
key: 'village' | 'map' | 'reports' | 'ranking'
|
||||
key: 'village' | 'map' | 'reports' | 'ranking' | 'tribe'
|
||||
to: string
|
||||
icon: UiIconName
|
||||
active: boolean
|
||||
|
|
@ -56,12 +58,21 @@ const entries = computed<Entry[]>(() => {
|
|||
to: kind === 'all' ? `/reports/${c.worldId}` : { path: `/reports/${c.worldId}`, query: { type: kind } },
|
||||
})),
|
||||
})
|
||||
out.push({
|
||||
key: 'tribe',
|
||||
to: `/tribe/${c.worldId}`,
|
||||
icon: 'users',
|
||||
active: route.path.startsWith('/tribe/'),
|
||||
// Invites waiting while the player has no tribe.
|
||||
count: villageState.value?.tribe.tribe ? undefined : villageState.value?.tribe.invites,
|
||||
sub: [],
|
||||
})
|
||||
out.push({
|
||||
key: 'ranking',
|
||||
to: `/ranking/${c.worldId}`,
|
||||
icon: 'rank',
|
||||
active: route.path.startsWith('/ranking/'),
|
||||
sub: (['players', 'villages', 'attack', 'defense'] as const).map((kind) => ({
|
||||
sub: (['players', 'tribes', 'villages', 'attack', 'defense'] as const).map((kind) => ({
|
||||
label: t(`ranking.kinds.${kind}`),
|
||||
to: kind === 'players' ? `/ranking/${c.worldId}` : { path: `/ranking/${c.worldId}`, query: { kind } },
|
||||
})),
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ const screenTitle = computed(() => {
|
|||
}
|
||||
if (route.path.startsWith('/reports/')) return t('reports.title')
|
||||
if (route.path.startsWith('/ranking/')) return t('app.ranking')
|
||||
if (route.path.startsWith('/tribe/')) return t('app.tribe')
|
||||
const s = VILLAGE_SCREENS.find((s) => s.path && route.path.startsWith(`${base.value}${s.path}`))
|
||||
return s ? t(`village.screens.${s.name}`) : ''
|
||||
})
|
||||
|
|
@ -127,7 +128,7 @@ useShortcuts(() => {
|
|||
const worldId = v.village.value?.world_id
|
||||
return {
|
||||
...Object.fromEntries(VILLAGE_SCREENS.map((s) => [s.name, `${base}${s.path}`])),
|
||||
...(worldId ? { map: `/map/${worldId}`, reports: `/reports/${worldId}`, ranking: `/ranking/${worldId}` } : {}),
|
||||
...(worldId ? { map: `/map/${worldId}`, reports: `/reports/${worldId}`, ranking: `/ranking/${worldId}`, tribe: `/tribe/${worldId}` } : {}),
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/** Keys for the screens of a world, like the shortcuts in Die Stämme: one letter, no modifier. */
|
||||
export const SHORTCUTS = { overview: 'v', build: 'h', recruit: 't', rally: 'p', workforce: 'w', map: 'm', reports: 'r', ranking: 'k' } as const
|
||||
export const SHORTCUTS = { overview: 'v', build: 'h', recruit: 't', rally: 'p', workforce: 'w', map: 'm', reports: 'r', ranking: 'k', tribe: 's' } as const
|
||||
|
||||
/**
|
||||
* Jumps between screens by key while the page is mounted. Keys typed into a field,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
import type { TribeListRow, TribePage } from '~/types/game'
|
||||
|
||||
/** The player's tribe on one world: its page, every tribe of the world, and the changes. */
|
||||
export function useTribe(worldId: number) {
|
||||
const page = ref<TribePage | null>(null)
|
||||
const tribes = ref<TribeListRow[] | null>(null)
|
||||
const error = ref<string | null>(null)
|
||||
const busy = ref(false)
|
||||
const errorText = useErrorText()
|
||||
const v = useVillageContextOrNull()
|
||||
|
||||
async function call<T>(event: string, data: object = {}): Promise<T | null> {
|
||||
busy.value = true
|
||||
error.value = null
|
||||
try {
|
||||
return await ws.send<T>(event, { world_id: worldId, ...data })
|
||||
} catch (e) {
|
||||
error.value = errorText(e)
|
||||
return null
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const load = async () => (page.value = (await call<TribePage>('tribe.show')) ?? page.value)
|
||||
const loadList = async () => (tribes.value = (await call<TribeListRow[]>('tribe.list')) ?? tribes.value)
|
||||
|
||||
/** A change answers with the fresh page; the village header learns about it too. */
|
||||
async function act(intent: string, data: object = {}) {
|
||||
const next = await call<TribePage>(`tribe.${intent}`, data)
|
||||
if (!next) return false
|
||||
page.value = next
|
||||
v?.refresh()
|
||||
if (tribes.value) loadList()
|
||||
return true
|
||||
}
|
||||
|
||||
return { page, tribes, error, busy, load, loadList, act }
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
import { onUnmounted, ref } from 'vue'
|
||||
import type {
|
||||
TribePage,
|
||||
RankingPage,
|
||||
RankingRow,
|
||||
Specialisation,
|
||||
|
|
@ -158,6 +159,8 @@ interface MockState {
|
|||
reports?: MockReport[]
|
||||
/** Claimed quests per `user:world`. */
|
||||
quests?: Record<string, string[]>
|
||||
/** Tribes, each led by the one user who founded it: the mock has no other players. */
|
||||
tribes?: { id: number; world_id: number; user_id: number; name: string; tag: string; description: string | null; events: { type: string; payload: Record<string, any>; at: string }[] }[]
|
||||
}
|
||||
|
||||
const STORAGE_KEY = 'vp.mock.v4'
|
||||
|
|
@ -335,6 +338,32 @@ function refund(v: MockVillage, amount: Cost) {
|
|||
v.resources.iron = Math.min(cap, v.resources.iron + amount.iron)
|
||||
}
|
||||
|
||||
// Tribes in the mock: one player, so one member, no invites and no diplomacy partners.
|
||||
const mockTribe = (state: MockState, userId: number, worldId: number) => (state.tribes ?? []).find((t) => t.user_id === userId && t.world_id === worldId) ?? null
|
||||
const tribeRef = (t: { id: number; name: string; tag: string }) => ({ id: t.id, name: t.name, tag: t.tag })
|
||||
|
||||
function tribePage(state: MockState, userId: number, worldId: number): TribePage {
|
||||
const t = mockTribe(state, userId, worldId)
|
||||
const user = state.users.find((u) => u.id === userId)
|
||||
return {
|
||||
tribe: t
|
||||
? {
|
||||
...tribeRef(t),
|
||||
description: t.description,
|
||||
role: 'leader',
|
||||
player_id: userId,
|
||||
members: [{ player: { id: userId, name: user?.name ?? '?' }, role: 'leader', points: 0, villages: state.villages.filter((v) => v.user_id === userId && v.world_id === worldId).length }],
|
||||
invites: [],
|
||||
relations: [],
|
||||
events: t.events,
|
||||
}
|
||||
: null,
|
||||
invites: [],
|
||||
max_members: 25,
|
||||
notice_seconds: 86400,
|
||||
}
|
||||
}
|
||||
|
||||
/** Village roles as the backend defines them (world.village.specialisation); the mock grants no bonus. */
|
||||
const ROLES: Specialisation['roles'] = [
|
||||
{ role: 'resources', buildings: ['timber_camp', 'clay_pit', 'iron_mine'], bonuses: { production: 0.2 } },
|
||||
|
|
@ -565,6 +594,7 @@ function view(state: MockState, v: MockVillage, now: number): VillageState {
|
|||
points: points(v),
|
||||
space: { used: spaceUsed(v), max: spaceMax(v) },
|
||||
specialisation: specialisation(v),
|
||||
tribe: { tribe: mockTribe(state, v.user_id, v.world_id) ? { ...tribeRef(mockTribe(state, v.user_id, v.world_id)!), role: 'leader' } : null, invites: 0 },
|
||||
resources: { ...v.resources },
|
||||
resources_at: iso(v.resources_at),
|
||||
rates: rates(v),
|
||||
|
|
@ -1401,6 +1431,35 @@ const handlers: Record<string, Handler> = {
|
|||
return { book: questBook(state, v), village: view(state, v, now) }
|
||||
},
|
||||
|
||||
'tribe.show': (state, user, data) => tribePage(state, user.id, Number(data.world_id)),
|
||||
'tribe.list': (state, user, data) =>
|
||||
(state.tribes ?? [])
|
||||
.filter((t) => t.world_id === Number(data.world_id))
|
||||
.map((t) => ({ ...tribeRef(t), members: 1, points: 0, relation: t.user_id === user.id ? ('tribe' as const) : ('none' as const) })),
|
||||
'tribe.found': (state, user, data) => {
|
||||
const worldId = Number(data.world_id)
|
||||
if (mockTribe(state, user.id, worldId)) fail('in_tribe')
|
||||
const name = String(data.name ?? '').trim()
|
||||
const tag = String(data.tag ?? '').trim()
|
||||
if (name.length < 3 || name.length > 32 || tag.length < 2 || tag.length > 6) fail('tribe_name')
|
||||
if ((state.tribes ?? []).some((t) => t.world_id === worldId && (t.name === name || t.tag === tag))) fail('tribe_taken')
|
||||
;(state.tribes ??= []).push({ id: nextId(state), world_id: worldId, user_id: user.id, name, tag, description: null, events: [{ type: 'founded', payload: { player: user.name }, at: iso(Date.now()) }] })
|
||||
return tribePage(state, user.id, worldId)
|
||||
},
|
||||
'tribe.describe': (state, user, data) => {
|
||||
const tribe = mockTribe(state, user.id, Number(data.world_id)) ?? fail('no_tribe')
|
||||
tribe.description = String(data.description ?? '').trim() || null
|
||||
return tribePage(state, user.id, Number(data.world_id))
|
||||
},
|
||||
'tribe.leave': (state, user, data) => {
|
||||
state.tribes = (state.tribes ?? []).filter((t) => !(t.user_id === user.id && t.world_id === Number(data.world_id)))
|
||||
return tribePage(state, user.id, Number(data.world_id))
|
||||
},
|
||||
'tribe.disband': (state, user, data) => {
|
||||
state.tribes = (state.tribes ?? []).filter((t) => !(t.user_id === user.id && t.world_id === Number(data.world_id)))
|
||||
return tribePage(state, user.id, Number(data.world_id))
|
||||
},
|
||||
|
||||
// Only the player's own villages exist in the mock, so the ranking is short.
|
||||
'ranking.index': (state, user, data): RankingPage => {
|
||||
const kind = (['players', 'villages', 'attack', 'defense'] as const).find((k) => k === data.kind) ?? 'players'
|
||||
|
|
@ -1409,9 +1468,9 @@ const handlers: Record<string, Handler> = {
|
|||
const points = (v: MockVillage) => v.buildings.reduce((sum, b) => sum + b.level * 5, 0)
|
||||
const rows: RankingRow[] =
|
||||
kind === 'players' && mine.length
|
||||
? [{ rank: 1, player, value: mine.reduce((sum, v) => sum + points(v), 0), villages: mine.length, own: true }]
|
||||
? [{ rank: 1, player: { ...player, tribe: null }, value: mine.reduce((sum, v) => sum + points(v), 0), villages: mine.length, own: true }]
|
||||
: kind === 'villages'
|
||||
? mine.map((v, i) => ({ rank: i + 1, player, village: { id: v.id, name: v.name, x: v.x, y: v.y }, value: points(v), own: true }))
|
||||
? mine.map((v, i) => ({ rank: i + 1, player: { ...player, tribe: null }, village: { id: v.id, name: v.name, x: v.x, y: v.y }, value: points(v), own: true }))
|
||||
: []
|
||||
return { kind, page: 1, pages: 1, rows, own: rows.length ? { rank: 1, page: 1 } : null }
|
||||
},
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ useCurrentWorld().enter(worldId)
|
|||
const { t } = useI18n()
|
||||
|
||||
// The kind comes from the URL, so the menu's dropdown and the side menu link here.
|
||||
const KINDS = ['players', 'villages', 'attack', 'defense'] as const
|
||||
const KINDS = ['players', 'tribes', 'villages', 'attack', 'defense'] as const
|
||||
const kind = computed<RankingKind>(() => (KINDS.includes(route.query.kind as RankingKind) ? (route.query.kind as RankingKind) : 'players'))
|
||||
watch(kind, (k) => load(k), { immediate: true })
|
||||
|
||||
|
|
@ -44,20 +44,25 @@ const mapLink = (v: { x: number; y: number }) => ({ path: `/map/${worldId}`, que
|
|||
<tr>
|
||||
<th class="w-12 text-right">{{ $t('ranking.rank') }}</th>
|
||||
<th v-if="kind === 'villages'">{{ $t('ranking.village') }}</th>
|
||||
<th>{{ $t('ranking.player') }}</th>
|
||||
<th>{{ $t(kind === 'tribes' ? 'ranking.tribe' : 'ranking.player') }}</th>
|
||||
<th class="text-right">{{ $t(`ranking.value.${kind}`) }}</th>
|
||||
<th v-if="kind === 'players'" class="text-right">{{ $t('ranking.villages') }}</th>
|
||||
<th v-if="kind === 'tribes'" class="text-right">{{ $t('ranking.members') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="r in page.rows" :key="r.village?.id ?? r.player.id" :class="r.own ? 'bg-gold-100 font-bold' : 'hover:bg-parchment-100'">
|
||||
<tr v-for="r in page.rows" :key="r.village?.id ?? r.tribe?.id ?? r.player?.id" :class="r.own ? 'bg-gold-100 font-bold' : 'hover:bg-parchment-100'">
|
||||
<td class="text-right tabular-nums">{{ r.rank }}</td>
|
||||
<td v-if="kind === 'villages' && r.village">
|
||||
<NuxtLink :to="mapLink(r.village)" class="hover:text-blood-700 hover:underline">{{ villageLabel({ ...r.village, player: null }) }}</NuxtLink>
|
||||
</td>
|
||||
<td>{{ r.player.name }}</td>
|
||||
<td v-if="r.tribe">{{ r.tribe.name }} [{{ r.tribe.tag }}]</td>
|
||||
<td v-else-if="r.player">
|
||||
{{ r.player.name }}<span v-if="r.player.tribe" class="ml-1 font-normal text-ink-500">[{{ r.player.tribe.tag }}]</span>
|
||||
</td>
|
||||
<td class="text-right tabular-nums">{{ r.value.toLocaleString() }}</td>
|
||||
<td v-if="kind === 'players'" class="text-right tabular-nums">{{ r.villages }}</td>
|
||||
<td v-if="kind === 'tribes'" class="text-right tabular-nums">{{ r.members }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,286 @@
|
|||
<script setup lang="ts">
|
||||
import type { Pact, TribeRole } from '~/types/game'
|
||||
|
||||
definePageMeta({ layout: 'game' })
|
||||
|
||||
const route = useRoute()
|
||||
const worldId = Number(route.params.worldId)
|
||||
useCurrentWorld().enter(worldId)
|
||||
const { page, tribes, error, busy, load, loadList, act } = useTribe(worldId)
|
||||
const { t } = useI18n()
|
||||
const clock = useNow()
|
||||
load()
|
||||
loadList()
|
||||
|
||||
const tribe = computed(() => page.value?.tribe ?? null)
|
||||
const manages = computed(() => tribe.value?.role === 'leader' || tribe.value?.role === 'council')
|
||||
const leads = computed(() => tribe.value?.role === 'leader')
|
||||
const myId = computed(() => tribe.value?.player_id)
|
||||
|
||||
// Like the tribe screens of Die Stämme: the tribe and its news, members, invites, diplomacy,
|
||||
// and every tribe of the world. Without a tribe: found one, the invites, the tribes.
|
||||
type Tab = 'overview' | 'members' | 'invites' | 'diplomacy' | 'tribes'
|
||||
const tab = ref<Tab>((route.query.tab as Tab) ?? 'overview')
|
||||
const tabs = computed(() =>
|
||||
(tribe.value ? (['overview', 'members', ...(manages.value ? ['invites'] : []), 'diplomacy', 'tribes'] as Tab[]) : (['overview', 'tribes'] as Tab[])).map((key) => ({
|
||||
key,
|
||||
label: t(`tribe.tabs.${key}`),
|
||||
count: key === 'diplomacy' ? tribe.value?.relations.filter((r) => r.status === 'incoming').length : key === 'overview' && !tribe.value ? page.value?.invites.length : undefined,
|
||||
})),
|
||||
)
|
||||
|
||||
const found = reactive({ name: '', tag: '' })
|
||||
const invitee = ref('')
|
||||
const description = ref<string | null>(null)
|
||||
const pact = reactive<{ tag: string; state: Pact | 'enemy' }>({ tag: '', state: 'ally' })
|
||||
|
||||
async function invite() {
|
||||
if (await act('invite', { player: invitee.value })) invitee.value = ''
|
||||
}
|
||||
async function saveDescription() {
|
||||
if (await act('describe', { description: description.value ?? '' })) description.value = null
|
||||
}
|
||||
async function offer() {
|
||||
const ok = pact.state === 'enemy' ? await act('enemy', { tag: pact.tag }) : await act('propose', { tag: pact.tag, state: pact.state })
|
||||
if (ok) pact.tag = ''
|
||||
}
|
||||
function leave() {
|
||||
if (confirm(t(leads.value && tribe.value?.members.length === 1 ? 'tribe.confirm_last' : 'tribe.confirm_leave'))) act('leave')
|
||||
}
|
||||
function disband() {
|
||||
if (confirm(t('tribe.confirm_disband'))) act('disband')
|
||||
}
|
||||
const canKick = (role: TribeRole, id: number) => id !== myId.value && (leads.value || (tribe.value?.role === 'council' && role === 'member'))
|
||||
const secondsUntil = (iso: string) => Math.max(0, (Date.parse(iso) - clock.value) / 1000)
|
||||
|
||||
/** One line of the news, from its type and what happened. */
|
||||
function event(e: { type: string; payload: Record<string, any> }) {
|
||||
const p = { ...e.payload }
|
||||
if (p.state) p.state = t(`tribe.states.${p.state}`)
|
||||
if (p.role) p.role = t(`tribe.roles.${p.role}`)
|
||||
if (p.between) p.between = p.between.join(' & ')
|
||||
if (p.ends_at) p.ends_at = formatArrival(Date.parse(p.ends_at), clock.value, t)
|
||||
return t(`tribe.events.${e.type}`, p)
|
||||
}
|
||||
const TONE: Record<string, string> = { ally: 'text-iron-700', nap: 'text-[#6b3f8f]', enemy: 'text-blood-700', tribe: 'text-iron-700', none: 'text-ink-500' }
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="space-y-2 p-2.5 text-sm">
|
||||
<header class="flex flex-wrap items-baseline gap-x-3 gap-y-1">
|
||||
<h1 class="font-display text-xl font-semibold">{{ tribe ? `${tribe.name} [${tribe.tag}]` : $t('tribe.none_title') }}</h1>
|
||||
<span v-if="tribe" class="text-ink-500">{{ $t(`tribe.roles.${tribe.role}`) }} · {{ $t('tribe.member_count', { n: tribe.members.length, max: page?.max_members }) }}</span>
|
||||
</header>
|
||||
<UiSubTabs v-model="tab" :tabs="tabs" />
|
||||
<p v-if="error" class="alert" role="alert">{{ error }}</p>
|
||||
<p v-if="!page" class="py-6 text-center text-ink-500">{{ $t('common.loading') }}</p>
|
||||
|
||||
<!-- Without a tribe: found one, or take an invite. -->
|
||||
<template v-else-if="tab === 'overview' && !tribe">
|
||||
<section class="panel">
|
||||
<div class="panel-head"><h2 class="panel-title">{{ $t('tribe.invites_received') }}</h2></div>
|
||||
<table v-if="page.invites.length" class="grid-table">
|
||||
<tbody>
|
||||
<tr v-for="i in page.invites" :key="i.tribe.id">
|
||||
<td class="font-semibold">{{ i.tribe.name }} [{{ i.tribe.tag }}]</td>
|
||||
<td class="text-ink-500">{{ $t('tribe.members_n', { n: i.members }) }}</td>
|
||||
<td class="text-right whitespace-nowrap">
|
||||
<button type="button" class="btn btn-primary" :disabled="busy" @click="act('join', { tribe_id: i.tribe.id })">{{ $t('tribe.join') }}</button>
|
||||
<button type="button" class="btn btn-outline ml-1" :disabled="busy" @click="act('refuse', { tribe_id: i.tribe.id })">{{ $t('tribe.refuse') }}</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p v-else class="panel-body text-ink-500">{{ $t('tribe.no_invites') }}</p>
|
||||
</section>
|
||||
<section class="panel">
|
||||
<div class="panel-head"><h2 class="panel-title">{{ $t('tribe.found') }}</h2></div>
|
||||
<form class="panel-body flex flex-wrap items-end gap-2" @submit.prevent="act('found', found)">
|
||||
<label class="flex flex-col gap-0.5">
|
||||
<span class="text-xs text-ink-500">{{ $t('tribe.name') }}</span>
|
||||
<input v-model="found.name" class="input w-56" maxlength="32" required />
|
||||
</label>
|
||||
<label class="flex flex-col gap-0.5">
|
||||
<span class="text-xs text-ink-500">{{ $t('tribe.tag') }}</span>
|
||||
<input v-model="found.tag" class="input w-24" maxlength="6" required />
|
||||
</label>
|
||||
<button type="submit" class="btn btn-primary" :disabled="busy">{{ $t('tribe.found_button') }}</button>
|
||||
</form>
|
||||
<p class="px-2.5 pb-2 text-xs text-ink-500">{{ $t('tribe.found_hint') }}</p>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<!-- The tribe: description, news, leaving. -->
|
||||
<template v-else-if="tab === 'overview' && tribe">
|
||||
<section class="panel">
|
||||
<div class="panel-head">
|
||||
<h2 class="panel-title">{{ $t('tribe.about') }}</h2>
|
||||
<button v-if="manages && description === null" type="button" class="btn btn-ghost" @click="description = tribe.description ?? ''">
|
||||
<IconUi name="edit" class="size-4" />{{ $t('tribe.edit') }}
|
||||
</button>
|
||||
</div>
|
||||
<form v-if="description !== null" class="panel-body space-y-2" @submit.prevent="saveDescription">
|
||||
<textarea v-model="description" class="input h-28 w-full" maxlength="2000" />
|
||||
<div class="flex gap-1">
|
||||
<button type="submit" class="btn btn-primary" :disabled="busy">{{ $t('tribe.save') }}</button>
|
||||
<button type="button" class="btn btn-outline" @click="description = null">{{ $t('tribe.cancel') }}</button>
|
||||
</div>
|
||||
</form>
|
||||
<p v-else class="panel-body whitespace-pre-line" :class="tribe.description ? '' : 'text-ink-500'">{{ tribe.description || $t('tribe.no_description') }}</p>
|
||||
</section>
|
||||
<section class="panel">
|
||||
<div class="panel-head"><h2 class="panel-title">{{ $t('tribe.news') }}</h2></div>
|
||||
<ul class="divide-y divide-parchment-300">
|
||||
<li v-for="(e, i) in tribe.events" :key="i" class="flex gap-3 px-2.5 py-1">
|
||||
<span class="w-40 shrink-0 text-ink-500 tabular-nums">{{ formatArrival(Date.parse(e.at), clock, t) }}</span>
|
||||
<span>{{ event(e) }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<div class="flex gap-2">
|
||||
<button type="button" class="btn btn-outline" :disabled="busy" @click="leave">{{ $t('tribe.leave') }}</button>
|
||||
<button v-if="leads" type="button" class="btn btn-attack" :disabled="busy" @click="disband">{{ $t('tribe.disband') }}</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<section v-else-if="tab === 'members' && tribe" class="panel">
|
||||
<table class="grid-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ $t('tribe.player') }}</th>
|
||||
<th>{{ $t('tribe.role') }}</th>
|
||||
<th class="text-right">{{ $t('tribe.points') }}</th>
|
||||
<th class="text-right">{{ $t('tribe.villages') }}</th>
|
||||
<th />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="m in tribe.members" :key="m.player.id">
|
||||
<td class="font-semibold">{{ m.player.name }}</td>
|
||||
<td>
|
||||
<select
|
||||
v-if="leads && m.player.id !== myId"
|
||||
class="input w-auto py-0.5"
|
||||
:value="m.role"
|
||||
:disabled="busy"
|
||||
@change="act('role', { player_id: m.player.id, role: ($event.target as HTMLSelectElement).value })"
|
||||
>
|
||||
<option v-for="r in ['leader', 'council', 'member']" :key="r" :value="r">{{ $t(`tribe.roles.${r}`) }}</option>
|
||||
</select>
|
||||
<span v-else>{{ $t(`tribe.roles.${m.role}`) }}</span>
|
||||
</td>
|
||||
<td class="text-right tabular-nums">{{ m.points }}</td>
|
||||
<td class="text-right tabular-nums">{{ m.villages }}</td>
|
||||
<td class="text-right">
|
||||
<button v-if="canKick(m.role, m.player.id)" type="button" class="btn btn-outline py-0.5" :disabled="busy" @click="act('kick', { player_id: m.player.id })">
|
||||
{{ $t('tribe.kick') }}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
<template v-else-if="tab === 'invites' && tribe">
|
||||
<section class="panel">
|
||||
<div class="panel-head"><h2 class="panel-title">{{ $t('tribe.invite') }}</h2></div>
|
||||
<form class="panel-body flex gap-2" @submit.prevent="invite">
|
||||
<input v-model="invitee" class="input w-56" :placeholder="$t('tribe.player_name')" required />
|
||||
<button type="submit" class="btn btn-primary" :disabled="busy">{{ $t('tribe.invite_button') }}</button>
|
||||
</form>
|
||||
</section>
|
||||
<section class="panel">
|
||||
<div class="panel-head"><h2 class="panel-title">{{ $t('tribe.invites_sent') }}</h2></div>
|
||||
<table v-if="tribe.invites.length" class="grid-table">
|
||||
<tbody>
|
||||
<tr v-for="i in tribe.invites" :key="i.player.id">
|
||||
<td class="font-semibold">{{ i.player.name }}</td>
|
||||
<td class="text-ink-500">{{ formatArrival(Date.parse(i.at), clock, t) }}</td>
|
||||
<td class="text-right">
|
||||
<button type="button" class="btn btn-outline py-0.5" :disabled="busy" @click="act('cancelInvite', { player_id: i.player.id })">{{ $t('tribe.withdraw') }}</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p v-else class="panel-body text-ink-500">{{ $t('tribe.no_invites_sent') }}</p>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<template v-else-if="tab === 'diplomacy' && tribe">
|
||||
<section class="panel">
|
||||
<table v-if="tribe.relations.length" class="grid-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ $t('tribe.tribe') }}</th>
|
||||
<th>{{ $t('tribe.relation') }}</th>
|
||||
<th>{{ $t('tribe.status') }}</th>
|
||||
<th />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="r in tribe.relations" :key="`${r.tribe.id}-${r.status}`">
|
||||
<td class="font-semibold">{{ r.tribe.name }} [{{ r.tribe.tag }}]</td>
|
||||
<td :class="TONE[r.state]">{{ $t(`tribe.states.${r.state}`) }}</td>
|
||||
<td>
|
||||
{{ $t(`tribe.status_${r.status}`) }}
|
||||
<span v-if="r.ends_at" class="tabular-nums text-ink-500"> · {{ formatSpan(secondsUntil(r.ends_at), t) }}</span>
|
||||
</td>
|
||||
<td class="text-right whitespace-nowrap">
|
||||
<template v-if="manages">
|
||||
<button v-if="r.status === 'incoming'" type="button" class="btn btn-primary py-0.5" :disabled="busy" @click="act('accept', { tribe_id: r.tribe.id })">{{ $t('tribe.accept') }}</button>
|
||||
<button
|
||||
v-if="r.status !== 'hostile' && r.status !== 'ending'"
|
||||
type="button"
|
||||
class="btn btn-outline ml-1 py-0.5"
|
||||
:disabled="busy"
|
||||
@click="act('end', { tribe_id: r.tribe.id })"
|
||||
>
|
||||
{{ $t(`tribe.undo_${r.status}`) }}
|
||||
</button>
|
||||
</template>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p v-else class="panel-body text-ink-500">{{ $t('tribe.no_relations') }}</p>
|
||||
</section>
|
||||
<section v-if="manages" class="panel">
|
||||
<div class="panel-head"><h2 class="panel-title">{{ $t('tribe.new_relation') }}</h2></div>
|
||||
<form class="panel-body flex flex-wrap gap-2" @submit.prevent="offer">
|
||||
<input v-model="pact.tag" class="input w-28" maxlength="6" :placeholder="$t('tribe.tag')" required />
|
||||
<select v-model="pact.state" class="input w-auto">
|
||||
<option value="ally">{{ $t('tribe.offer.ally') }}</option>
|
||||
<option value="nap">{{ $t('tribe.offer.nap') }}</option>
|
||||
<option value="enemy">{{ $t('tribe.offer.enemy') }}</option>
|
||||
</select>
|
||||
<button type="submit" class="btn btn-primary" :disabled="busy">{{ $t('tribe.send') }}</button>
|
||||
</form>
|
||||
<p class="px-2.5 pb-2 text-xs text-ink-500">{{ $t('tribe.diplomacy_hint', { time: formatSpan(page.notice_seconds, t) }) }}</p>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<section v-else-if="tab === 'tribes'" class="panel">
|
||||
<table v-if="tribes?.length" class="grid-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="w-10 text-right">#</th>
|
||||
<th>{{ $t('tribe.tribe') }}</th>
|
||||
<th class="text-right">{{ $t('tribe.members') }}</th>
|
||||
<th class="text-right">{{ $t('tribe.points') }}</th>
|
||||
<th>{{ $t('tribe.relation') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(r, i) in tribes" :key="r.id" :class="r.relation === 'tribe' ? 'bg-gold-100 font-bold' : ''">
|
||||
<td class="text-right tabular-nums">{{ i + 1 }}</td>
|
||||
<td>{{ r.name }} [{{ r.tag }}]</td>
|
||||
<td class="text-right tabular-nums">{{ r.members }}</td>
|
||||
<td class="text-right tabular-nums">{{ r.points }}</td>
|
||||
<td :class="TONE[r.relation]">{{ r.relation === 'none' ? '' : $t(`tribe.states.${r.relation}`) }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p v-else class="panel-body text-ink-500">{{ $t('tribe.no_tribes') }}</p>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -116,6 +116,8 @@ export interface VillageState {
|
|||
space: { used: number; max: number }
|
||||
specialisation: Specialisation
|
||||
season: SeasonState
|
||||
/** The player's tribe and their role in it, and tribe invites waiting. */
|
||||
tribe: { tribe: (TribeRef & { role: TribeRole }) | null; invites: number }
|
||||
/** Amounts stored at `resources_at`. */
|
||||
resources: Resources
|
||||
resources_at: string
|
||||
|
|
@ -291,11 +293,59 @@ export type Report =
|
|||
| (ReportBase & { type: 'attack' | 'defense'; payload: BattleReport | ScatteredRaid })
|
||||
| (ReportBase & { type: 'support'; payload: SupportReport })
|
||||
|
||||
export type RankingKind = 'players' | 'villages' | 'attack' | 'defense'
|
||||
export type TribeRole = 'leader' | 'council' | 'member'
|
||||
export type Pact = 'ally' | 'nap'
|
||||
/** What one player's tribe is to another's. */
|
||||
export type TribeRelation = 'tribe' | 'ally' | 'nap' | 'enemy' | 'none'
|
||||
export interface TribeRef {
|
||||
id: number
|
||||
name: string
|
||||
tag: string
|
||||
}
|
||||
|
||||
/** `tribe.show` and the reply to every `tribe.*` change. */
|
||||
export interface TribePage {
|
||||
tribe: {
|
||||
id: number
|
||||
name: string
|
||||
tag: string
|
||||
description: string | null
|
||||
/** The player's own role and player id. */
|
||||
role: TribeRole
|
||||
player_id: number
|
||||
members: { player: { id: number; name: string }; role: TribeRole; points: number; villages: number }[]
|
||||
/** Invites sent, for the leader and the council. */
|
||||
invites: { player: { id: number; name: string }; at: string }[]
|
||||
/**
|
||||
* holds/ending: a pact both accepted (ending: until ends_at); offered: ours waiting;
|
||||
* incoming: theirs waiting for us; enemy: we declared them; hostile: they declared us.
|
||||
*/
|
||||
relations: { tribe: TribeRef; state: Pact | 'enemy'; status: 'holds' | 'ending' | 'offered' | 'incoming' | 'enemy' | 'hostile'; ends_at: string | null }[]
|
||||
events: { type: string; payload: Record<string, any>; at: string }[]
|
||||
} | null
|
||||
/** Invites the player has received. */
|
||||
invites: { tribe: TribeRef; members: number; at: string }[]
|
||||
max_members: number
|
||||
/** How long ending a pact takes. */
|
||||
notice_seconds: number
|
||||
}
|
||||
|
||||
/** `tribe.list`: every tribe of the world, strongest first. */
|
||||
export interface TribeListRow extends TribeRef {
|
||||
members: number
|
||||
points: number
|
||||
relation: TribeRelation
|
||||
}
|
||||
|
||||
export type RankingKind = 'players' | 'tribes' | 'villages' | 'attack' | 'defense'
|
||||
|
||||
export interface RankingRow {
|
||||
rank: number
|
||||
player: { id: number; name: string }
|
||||
/** Every kind but tribes. */
|
||||
player?: { id: number; name: string; tribe: { id: number; tag: string } | null }
|
||||
/** Only in the tribe ranking. */
|
||||
tribe?: TribeRef
|
||||
members?: number
|
||||
/** Only in the village ranking. */
|
||||
village?: { id: number; name: string; x: number; y: number }
|
||||
/** Points, or opponents defeated (by the food the fallen ate). */
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ export default {
|
|||
map: 'Map',
|
||||
reports: 'Reports',
|
||||
ranking: 'Ranking',
|
||||
tribe: 'Tribe',
|
||||
unread_reports: '{count} unread reports',
|
||||
village: 'Village',
|
||||
change_world: 'Change world',
|
||||
|
|
@ -70,6 +71,19 @@ export default {
|
|||
email_taken: 'This email is already registered.',
|
||||
not_found: 'Not found.',
|
||||
world_ended: 'This world has ended.',
|
||||
pact: 'Your tribes are at peace: end the pact first.',
|
||||
own_tribe: 'That village belongs to your own tribe.',
|
||||
tribe_taken: 'That tribe name or tag is taken.',
|
||||
tribe_name: 'Name 3 to 32 characters, tag 2 to 6.',
|
||||
in_tribe: 'Leave your tribe first.',
|
||||
tribe_full: 'That tribe is full.',
|
||||
hand_over: 'Make someone else leader first.',
|
||||
rank: 'Your rank in the tribe does not allow that.',
|
||||
no_player: 'No player of that name on this world.',
|
||||
no_tribe_tag: 'No tribe with that tag.',
|
||||
pact_active: 'A pact holds: end it first.',
|
||||
already_member: 'Already in your tribe.',
|
||||
no_tribe: 'You are not in a tribe.',
|
||||
no_space: 'Not enough building space.',
|
||||
max_per_village: 'Only one of these per village.',
|
||||
max_level: 'Already at max level.',
|
||||
|
|
|
|||
|
|
@ -5,12 +5,13 @@ import auth from './pages/auth'
|
|||
import map from './pages/map'
|
||||
import quests from './pages/quests'
|
||||
import ranking from './pages/ranking'
|
||||
import tribe from './pages/tribe'
|
||||
import reports from './pages/reports'
|
||||
import village from './pages/village'
|
||||
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, map, quests, ranking, reports, village, worlds], { packages: [networking] }) as {
|
||||
export default mergeMessages({ en }, [auth, map, quests, ranking, reports, tribe, village, worlds], { packages: [networking] }) as {
|
||||
en: Record<string, any>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,11 @@ import type { TranslationFile } from '@blax-software/i18n'
|
|||
export default {
|
||||
en: {
|
||||
ranking: {
|
||||
kinds: { players: 'Players', villages: 'Villages', attack: 'Attackers', defense: 'Defenders' },
|
||||
titles: { players: 'Players by points', villages: 'Villages by points', attack: 'Opponents defeated in attack', defense: 'Opponents defeated in defence' },
|
||||
kinds: { players: 'Players', tribes: 'Tribes', villages: 'Villages', attack: 'Attackers', defense: 'Defenders' },
|
||||
titles: { players: 'Players by points', tribes: 'Tribes by points', villages: 'Villages by points', attack: 'Opponents defeated in attack', defense: 'Opponents defeated in defence' },
|
||||
none: {
|
||||
players: 'No players yet.',
|
||||
tribes: 'No tribes yet.',
|
||||
villages: 'No villages yet.',
|
||||
attack: 'Nobody has defeated anyone in an attack yet.',
|
||||
defense: 'Nobody has beaten off an attack yet.',
|
||||
|
|
@ -14,8 +15,10 @@ export default {
|
|||
rank: 'Rank',
|
||||
player: 'Player',
|
||||
village: 'Village',
|
||||
tribe: 'Tribe',
|
||||
members: 'Members',
|
||||
villages: 'Villages',
|
||||
value: { players: 'Points', villages: 'Points', attack: 'Defeated', defense: 'Defeated' },
|
||||
value: { players: 'Points', tribes: 'Points', villages: 'Points', attack: 'Defeated', defense: 'Defeated' },
|
||||
own: 'Your rank: {rank}',
|
||||
own_rank: 'You are ranked {rank}.',
|
||||
},
|
||||
|
|
|
|||
|
|
@ -0,0 +1,81 @@
|
|||
import type { TranslationFile } from '@blax-software/i18n'
|
||||
|
||||
export default {
|
||||
en: {
|
||||
tribe: {
|
||||
none_title: 'No tribe yet',
|
||||
tabs: { overview: 'Tribe', members: 'Members', invites: 'Invites', diplomacy: 'Diplomacy', tribes: 'All tribes' },
|
||||
roles: { leader: 'Leader', council: 'Council', member: 'Member' },
|
||||
states: { ally: 'Alliance', nap: 'Non-aggression pact', enemy: 'Enemy', tribe: 'Own tribe' },
|
||||
offer: { ally: 'Offer an alliance', nap: 'Offer a non-aggression pact', enemy: 'Declare an enemy' },
|
||||
member_count: '{n} of {max} members',
|
||||
members_n: '{n} members',
|
||||
invites_received: 'Invitations',
|
||||
no_invites: 'No tribe has invited you yet.',
|
||||
found: 'Found a tribe',
|
||||
found_button: 'Found',
|
||||
found_hint: 'Name 3 to 32 characters, tag 2 to 6. You lead the tribe you found.',
|
||||
name: 'Name',
|
||||
tag: 'Tag',
|
||||
join: 'Join',
|
||||
refuse: 'Turn down',
|
||||
about: 'About the tribe',
|
||||
edit: 'Edit',
|
||||
save: 'Save',
|
||||
cancel: 'Cancel',
|
||||
no_description: 'No description yet.',
|
||||
news: 'News',
|
||||
leave: 'Leave the tribe',
|
||||
disband: 'Disband the tribe',
|
||||
confirm_leave: 'Leave the tribe?',
|
||||
confirm_last: 'You are the last member: leaving ends the tribe. Go on?',
|
||||
confirm_disband: 'Disband the tribe for everyone?',
|
||||
player: 'Player',
|
||||
role: 'Role',
|
||||
points: 'Points',
|
||||
villages: 'Villages',
|
||||
members: 'Members',
|
||||
kick: 'Remove',
|
||||
invite: 'Invite a player',
|
||||
invite_button: 'Invite',
|
||||
player_name: 'Player name',
|
||||
invites_sent: 'Invites sent',
|
||||
no_invites_sent: 'No open invites.',
|
||||
withdraw: 'Withdraw',
|
||||
tribe: 'Tribe',
|
||||
relation: 'Relation',
|
||||
status: 'Status',
|
||||
status_holds: 'holds',
|
||||
status_ending: 'ending',
|
||||
status_offered: 'offered by us',
|
||||
status_incoming: 'offered to us',
|
||||
status_enemy: 'declared by us',
|
||||
status_hostile: 'declared by them',
|
||||
accept: 'Accept',
|
||||
undo_holds: 'End',
|
||||
undo_offered: 'Withdraw',
|
||||
undo_incoming: 'Turn down',
|
||||
undo_enemy: 'Make peace',
|
||||
no_relations: 'No alliances, pacts or enemies yet.',
|
||||
new_relation: 'New relation',
|
||||
send: 'Send',
|
||||
diplomacy_hint: 'An alliance or a non-aggression pact holds once the other tribe accepts: then neither side can attack the other. Ending one takes {time} of notice. Enemies are declared alone.',
|
||||
no_tribes: 'No tribes on this world yet.',
|
||||
events: {
|
||||
founded: '{player} founded the tribe.',
|
||||
joined: '{player} joined.',
|
||||
left: '{player} left.',
|
||||
kicked: '{by} removed {player}.',
|
||||
role: '{player} is now {role}.',
|
||||
invited: '{by} invited {player}.',
|
||||
pact_proposed: '{from} offered {to}: {state}.',
|
||||
pact_sealed: '{between}: {state} sealed.',
|
||||
pact_ending: '{by} ended the {state}; it holds until {ends_at}.',
|
||||
pact_withdrawn: '{by} withdrew the offer: {state}.',
|
||||
pact_refused: '{by} turned down the offer: {state}.',
|
||||
enemy_declared: '{by} declared {against} an enemy.',
|
||||
enemy_cleared: '{by} made peace.',
|
||||
},
|
||||
},
|
||||
},
|
||||
} satisfies TranslationFile
|
||||
Loading…
Reference in New Issue