feat: the headquarters list groups each building type: its portrait and count once, the instances as sub-rows in the server's rank (main, then Copy 2 · 50%), Build another as the group's last row, a heavier rule between groups; villagers next to every cost, no sideways scroll on phones; copies are named by rank everywhere
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f0cf3551c8
commit
4c638667e7
|
|
@ -8,6 +8,8 @@ const props = defineProps<{
|
||||||
resources: Resources
|
resources: Resources
|
||||||
canAfford: (cost: Cost) => boolean
|
canAfford: (cost: Cost) => boolean
|
||||||
busy: boolean
|
busy: boolean
|
||||||
|
/** Villagers free for a new level (`population.idle`): a villager count above it shows red. */
|
||||||
|
idle: number
|
||||||
/** A building type a quest points at: its rows are marked and scrolled into view. */
|
/** A building type a quest points at: its rows are marked and scrolled into view. */
|
||||||
hint?: string | null
|
hint?: string | null
|
||||||
}>()
|
}>()
|
||||||
|
|
@ -24,17 +26,21 @@ const { t } = useI18n()
|
||||||
// the second tab; types still waiting for requirements are listed at the bottom.
|
// the second tab; types still waiting for requirements are listed at the bottom.
|
||||||
const tab = ref<'construct' | 'demolish'>('construct')
|
const tab = ref<'construct' | 'demolish'>('construct')
|
||||||
|
|
||||||
|
/** Instances per type in the server's rank: the one that works in full first, then the copies. */
|
||||||
const byType = computed(() => {
|
const byType = computed(() => {
|
||||||
const map = new Map<BuildingType, Building[]>()
|
const map = new Map<BuildingType, Building[]>()
|
||||||
for (const b of props.buildings) map.set(b.type, [...(map.get(b.type) ?? []), b])
|
for (const b of props.buildings) map.set(b.type, [...(map.get(b.type) ?? []), b])
|
||||||
|
for (const [type, list] of map) map.set(type, ranked(list))
|
||||||
return map
|
return map
|
||||||
})
|
})
|
||||||
|
|
||||||
// Rows of one type form a group: its instances, then building one more of it, indented
|
// Rows of one type form a group. With two or more instances the group opens with a header
|
||||||
// under them so it reads as another copy and not as something still missing.
|
// (portrait, name, count) and the instances follow as sub-rows; building one more is the
|
||||||
type Row = { group: number; first: boolean } & (
|
// group's last sub-row. A type with one instance or none stays a single row.
|
||||||
| { kind: 'upgrade'; key: string; type: BuildingType; name: string; building: Building; offer: Offer | null }
|
type Row = { group: number; first: boolean; sub: boolean } & (
|
||||||
| { kind: 'build'; key: string; type: BuildingType; name: string; option: BuildOption; another: number }
|
| { kind: 'head'; key: string; type: BuildingType; count: number }
|
||||||
|
| { kind: 'upgrade'; key: string; type: BuildingType; building: Building; offer: Offer | null; rank: number }
|
||||||
|
| { kind: 'build'; key: string; type: BuildingType; option: BuildOption; another: boolean }
|
||||||
)
|
)
|
||||||
|
|
||||||
const rows = computed<Row[]>(() => {
|
const rows = computed<Row[]>(() => {
|
||||||
|
|
@ -43,33 +49,17 @@ const rows = computed<Row[]>(() => {
|
||||||
for (const o of props.options) {
|
for (const o of props.options) {
|
||||||
if (o.blocked === 'requires') continue
|
if (o.blocked === 'requires') continue
|
||||||
const instances = byType.value.get(o.type) ?? []
|
const instances = byType.value.get(o.type) ?? []
|
||||||
|
const grouped = instances.length > 1
|
||||||
const start = out.length
|
const start = out.length
|
||||||
group++
|
group++
|
||||||
const numbered = instances.length > 1 || (instances.length > 0 && o.blocked !== 'max_per_village')
|
if (grouped) out.push({ group, first: false, sub: false, kind: 'head', key: `head-${o.type}`, type: o.type, count: instances.length })
|
||||||
instances.forEach((b, i) => {
|
instances.forEach((b, rank) => {
|
||||||
out.push({
|
out.push({ group, first: false, sub: grouped, kind: 'upgrade', key: `b${b.id}`, type: b.type, building: b, offer: b.upgrade, rank })
|
||||||
group,
|
|
||||||
first: false,
|
|
||||||
kind: 'upgrade',
|
|
||||||
key: `b${b.id}`,
|
|
||||||
type: b.type,
|
|
||||||
name: numbered ? t('village.build.nth', { name: t(`buildings.${b.type}`), n: i + 1 }) : t(`buildings.${b.type}`),
|
|
||||||
building: b,
|
|
||||||
offer: b.upgrade,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
// A unique type that already stands has nothing more to build.
|
// A unique type that already stands has nothing more to build.
|
||||||
if (o.blocked === 'max_per_village' && instances.length) continue
|
if (!(o.blocked === 'max_per_village' && instances.length)) {
|
||||||
out.push({
|
out.push({ group, first: false, sub: instances.length > 0, kind: 'build', key: `new-${o.type}`, type: o.type, option: o, another: instances.length > 0 })
|
||||||
group,
|
}
|
||||||
first: false,
|
|
||||||
kind: 'build',
|
|
||||||
key: `new-${o.type}`,
|
|
||||||
type: o.type,
|
|
||||||
name: instances.length ? t('village.build.nth', { name: t(`buildings.${o.type}`), n: instances.length + 1 }) : t(`buildings.${o.type}`),
|
|
||||||
option: o,
|
|
||||||
another: instances.length ? instances.length + 1 : 0,
|
|
||||||
})
|
|
||||||
if (out[start]) out[start]!.first = true
|
if (out[start]) out[start]!.first = true
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
|
|
@ -98,14 +88,14 @@ function reason(offer: Offer | null) {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
const demolishable = computed(() =>
|
/** "Storage" for the one that works in full, "Storage, copy 2" for the copies after it. */
|
||||||
props.buildings.map((b) => ({
|
function nameOf(b: Building) {
|
||||||
b,
|
const name = t(`buildings.${b.type}`)
|
||||||
name: (byType.value.get(b.type)?.length ?? 0) > 1
|
const n = byType.value.get(b.type)?.indexOf(b) ?? 0
|
||||||
? t('village.build.nth', { name: t(`buildings.${b.type}`), n: byType.value.get(b.type)!.indexOf(b) + 1 })
|
return n > 0 ? t('village.copy.name', { name, n: n + 1 }) : name
|
||||||
: t(`buildings.${b.type}`),
|
}
|
||||||
})),
|
|
||||||
)
|
const demolishable = computed(() => [...byType.value.values()].flat().map((b) => ({ b, name: nameOf(b) })))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -130,26 +120,34 @@ const demolishable = computed(() =>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="tab === 'construct'" class="overflow-x-auto">
|
<div v-if="tab === 'construct'">
|
||||||
<table class="w-full min-w-[36rem] border-collapse text-sm">
|
<table class="grid-table build-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="border-b-2 border-wood-700 bg-parchment-100 text-left text-xs font-semibold text-ink-700">
|
<tr>
|
||||||
<th class="px-3 py-1.5">{{ $t('village.build.building') }}</th>
|
<th class="pl-3">{{ $t('village.build.building') }}</th>
|
||||||
<th class="px-2 py-1.5">{{ $t('village.build.cost') }}</th>
|
<th class="hidden @2xl:table-cell">{{ $t('village.build.cost') }}</th>
|
||||||
<th class="px-2 py-1.5 text-right">{{ $t('village.build.space_col') }}</th>
|
<th class="hidden text-right @2xl:table-cell">{{ $t('village.build.space_col') }}</th>
|
||||||
<th class="px-2 py-1.5 text-right">{{ $t('village.build.time') }}</th>
|
<th class="hidden text-right @2xl:table-cell">{{ $t('village.build.time') }}</th>
|
||||||
<th class="px-3 py-1.5 text-right">{{ $t('village.build.construct') }}</th>
|
<th class="pr-3 text-right">{{ $t('village.build.construct') }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr
|
<tr
|
||||||
v-for="row in rows"
|
v-for="row in rows"
|
||||||
:key="row.key"
|
:key="row.key"
|
||||||
class="border-parchment-300"
|
:class="[row.type === hint ? 'quest-hint' : row.group % 2 ? 'bg-parchment-100' : '', { 'group-start': row.first }]"
|
||||||
:class="[row.type === hint ? 'quest-hint' : row.group % 2 ? 'bg-parchment-100' : '', row.first ? 'border-t-2 border-t-parchment-400' : 'border-t']"
|
|
||||||
:data-hint="row.type === hint ? '' : undefined"
|
:data-hint="row.type === hint ? '' : undefined"
|
||||||
>
|
>
|
||||||
<td class="py-1 pr-3" :class="row.kind === 'build' && row.another ? 'pl-12' : 'pl-3'">
|
<!-- The group's header: the portrait once, the name and how many stand. -->
|
||||||
|
<td v-if="row.kind === 'head'" colspan="5" class="pl-3">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<VillagePortraitTile :type="row.type" :level="byType.get(row.type)![0]!.level" class="size-8" />
|
||||||
|
<p class="font-semibold">{{ $t('village.build.group', { name: $t(`buildings.${row.type}`), count: row.count }) }}</p>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<td class="pr-2" :class="row.sub ? 'pl-6 @2xl:pl-12' : 'pl-3'">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<span
|
<span
|
||||||
v-if="row.kind === 'build' && row.another"
|
v-if="row.kind === 'build' && row.another"
|
||||||
|
|
@ -158,70 +156,100 @@ const demolishable = computed(() =>
|
||||||
>
|
>
|
||||||
<IconUi name="plus" class="size-3.5" />
|
<IconUi name="plus" class="size-3.5" />
|
||||||
</span>
|
</span>
|
||||||
<VillagePortraitTile v-else :type="row.type" :level="row.kind === 'upgrade' ? row.building.level : 1" class="size-8" />
|
<VillagePortraitTile v-else-if="!row.sub" :type="row.type" :level="row.kind === 'upgrade' ? row.building.level : 1" class="size-8" />
|
||||||
<div class="min-w-0 leading-tight">
|
<div class="min-w-0 leading-tight">
|
||||||
|
<!-- A standing building: under its group header the level is its name. -->
|
||||||
|
<template v-if="row.kind === 'upgrade'">
|
||||||
<button
|
<button
|
||||||
v-if="row.kind === 'upgrade'"
|
|
||||||
type="button"
|
type="button"
|
||||||
class="block max-w-full truncate text-left font-semibold hover:text-blood-700 hover:underline"
|
class="block max-w-full truncate text-left font-semibold hover:text-blood-700 hover:underline"
|
||||||
:title="$t('village.buildings.show')"
|
:title="$t('village.buildings.show')"
|
||||||
@click="emit('select', row.building.id)"
|
@click="emit('select', row.building.id)"
|
||||||
>
|
>
|
||||||
{{ row.name }}
|
{{ row.sub ? $t('village.buildings.level_n', { level: row.building.level }) : $t(`buildings.${row.type}`) }}
|
||||||
</button>
|
</button>
|
||||||
<p v-else class="truncate font-semibold">{{ row.name }}</p>
|
<p class="flex flex-wrap items-center gap-1.5 text-xs text-ink-500">
|
||||||
|
<template v-if="!row.sub">{{ $t('village.buildings.level_n', { level: row.building.level }) }}</template>
|
||||||
<!-- A copy works at a share of the first: one amber chip, from the server's share. -->
|
<!-- A copy works at a share of the first: one amber chip, from the server's share. -->
|
||||||
<p class="flex items-center gap-1.5 text-xs whitespace-nowrap text-ink-500">
|
<span v-if="row.rank > 0" class="badge badge-gold whitespace-nowrap">
|
||||||
<template v-if="row.kind === 'upgrade'">
|
{{ $t('village.copy.nth', { n: row.rank + 1, share: sharePercent(row.building.instance_share) }) }}
|
||||||
{{ $t('village.buildings.level_n', { level: row.building.level }) }}
|
|
||||||
<span v-if="isCopy(row.building.instance_share)" class="badge badge-gold">
|
|
||||||
{{ $t('village.copy.share', { share: sharePercent(row.building.instance_share) }) }}
|
|
||||||
</span>
|
</span>
|
||||||
|
</p>
|
||||||
</template>
|
</template>
|
||||||
<span v-else-if="isCopy(row.option.instance_share)" class="badge badge-gold">
|
<!-- One more of a type that stands: an action, not a building. -->
|
||||||
|
<p v-else-if="row.another" class="text-xs text-ink-700">
|
||||||
|
<span v-if="isCopy(row.option.instance_share)" class="badge badge-gold whitespace-normal @2xl:whitespace-nowrap">
|
||||||
{{ $t('village.copy.new', { share: sharePercent(row.option.instance_share) }) }}
|
{{ $t('village.copy.new', { share: sharePercent(row.option.instance_share) }) }}
|
||||||
</span>
|
</span>
|
||||||
<template v-else>{{ row.another ? $t('village.build.another_hint') : $t('village.build.not_built') }}</template>
|
<template v-else>{{ $t('village.build.another_hint') }}</template>
|
||||||
|
</p>
|
||||||
|
<template v-else>
|
||||||
|
<p class="truncate font-semibold">{{ $t(`buildings.${row.type}`) }}</p>
|
||||||
|
<p class="text-xs text-ink-500">{{ $t('village.build.not_built') }}</p>
|
||||||
|
</template>
|
||||||
|
<!-- Narrow screens: cost, villagers, time and why not under the name instead of in columns. -->
|
||||||
|
<p v-if="row.kind === 'upgrade' ? row.offer : true" class="mt-0.5 flex flex-wrap items-center gap-x-2.5 gap-y-0.5 @2xl:hidden">
|
||||||
|
<template v-if="row.kind === 'upgrade'">
|
||||||
|
<UiCost :cost="row.offer!.cost" :have="resources" nowrap />
|
||||||
|
<UiVillagers :villagers="row.offer!.villagers" :idle="idle" />
|
||||||
|
<span class="inline-flex items-center gap-1 text-xs text-ink-700 tabular-nums"><IconUi name="clock" class="size-3" />{{ formatDuration(row.offer!.seconds) }}</span>
|
||||||
|
<span v-if="reason(row.offer)" class="basis-full text-xs font-semibold text-blood-700">{{ reason(row.offer) }}</span>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<UiCost :cost="row.option.cost" :have="resources" nowrap />
|
||||||
|
<UiVillagers :villagers="row.option.villagers" :idle="idle" />
|
||||||
|
<span class="inline-flex items-center gap-1 text-xs text-ink-700 tabular-nums"><IconUi name="clock" class="size-3" />{{ formatDuration(row.option.seconds) }}</span>
|
||||||
|
<span v-if="reason(row.option)" class="basis-full text-xs font-semibold text-blood-700">{{ reason(row.option) }}</span>
|
||||||
|
</template>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<template v-if="row.kind === 'upgrade'">
|
<template v-if="row.kind === 'upgrade'">
|
||||||
<td class="px-2 py-1"><UiCost v-if="row.offer" :cost="row.offer.cost" :have="resources" nowrap /></td>
|
<td class="hidden @2xl:table-cell"><UiCost v-if="row.offer" :cost="row.offer.cost" :have="resources" :villagers="row.offer.villagers" :idle="idle" nowrap /></td>
|
||||||
<td class="px-2 py-1 text-right text-ink-400">–</td>
|
<td class="hidden text-right text-ink-400 @2xl:table-cell">–</td>
|
||||||
<td class="px-2 py-1 text-right tabular-nums whitespace-nowrap">{{ row.offer ? formatDuration(row.offer.seconds) : '' }}</td>
|
<td class="hidden text-right tabular-nums whitespace-nowrap @2xl:table-cell">{{ row.offer ? formatDuration(row.offer.seconds) : '' }}</td>
|
||||||
<td class="px-3 py-1 text-right">
|
<td class="pr-3 text-right">
|
||||||
<button
|
<button
|
||||||
v-if="!reason(row.offer)"
|
v-if="!reason(row.offer)"
|
||||||
type="button"
|
type="button"
|
||||||
class="btn btn-primary min-w-[5.5rem] px-2.5 py-1 whitespace-nowrap"
|
class="btn btn-primary px-2 py-0.5 whitespace-nowrap @2xl:min-w-[5.5rem] @2xl:px-2.5"
|
||||||
:disabled="busy"
|
:disabled="busy"
|
||||||
@click="emit('upgrade', row.building.id)"
|
@click="emit('upgrade', row.building.id)"
|
||||||
>
|
>
|
||||||
<IconUi name="up" class="size-3.5" />
|
<IconUi name="up" class="size-3.5" />
|
||||||
{{ $t('village.build.level_button', { level: row.offer!.target_level }) }}
|
{{ $t('village.build.level_button', { level: row.offer!.target_level }) }}
|
||||||
</button>
|
</button>
|
||||||
<span v-else class="text-xs font-semibold whitespace-nowrap text-blood-700">{{ reason(row.offer) }}</span>
|
<!-- On narrow screens the reason stands under the name; max level has no line there. -->
|
||||||
|
<span
|
||||||
|
v-else
|
||||||
|
class="text-xs font-semibold whitespace-nowrap text-blood-700 @2xl:inline"
|
||||||
|
:class="row.offer ? 'hidden' : ''"
|
||||||
|
>{{ reason(row.offer) }}</span>
|
||||||
</td>
|
</td>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<td class="px-2 py-1"><UiCost :cost="row.option.cost" :have="resources" nowrap /></td>
|
<td class="hidden @2xl:table-cell"><UiCost :cost="row.option.cost" :have="resources" :villagers="row.option.villagers" :idle="idle" nowrap /></td>
|
||||||
<td class="px-2 py-1 text-right tabular-nums">{{ row.option.space || '–' }}</td>
|
<td class="hidden text-right tabular-nums @2xl:table-cell">{{ row.option.space || '–' }}</td>
|
||||||
<td class="px-2 py-1 text-right tabular-nums whitespace-nowrap">{{ formatDuration(row.option.seconds) }}</td>
|
<td class="hidden text-right tabular-nums whitespace-nowrap @2xl:table-cell">{{ formatDuration(row.option.seconds) }}</td>
|
||||||
<td class="px-3 py-1 text-right">
|
<td class="pr-3 text-right">
|
||||||
<button
|
<button
|
||||||
v-if="!reason(row.option)"
|
v-if="!reason(row.option)"
|
||||||
type="button"
|
type="button"
|
||||||
class="btn btn-outline min-w-[5.5rem] border-blood-700 px-2.5 py-1 whitespace-nowrap text-blood-700"
|
class="btn btn-outline border-blood-700 px-2 py-0.5 whitespace-nowrap text-blood-700 @2xl:min-w-[5.5rem] @2xl:px-2.5"
|
||||||
:disabled="busy"
|
:disabled="busy"
|
||||||
|
:title="row.another ? $t('village.build.submit_another') : undefined"
|
||||||
@click="emit('build', row.type)"
|
@click="emit('build', row.type)"
|
||||||
>
|
>
|
||||||
<IconUi :name="row.another ? 'plus' : 'hammer'" class="size-3.5" />
|
<IconUi :name="row.another ? 'plus' : 'hammer'" class="size-3.5" />
|
||||||
{{ $t(row.another ? 'village.build.submit_another' : 'village.build.submit') }}
|
<!-- Phones say just "Build": the plus and the row already say it is another one. -->
|
||||||
|
<span v-if="row.another" class="hidden @2xl:inline">{{ $t('village.build.submit_another') }}</span>
|
||||||
|
<span :class="row.another ? '@2xl:hidden' : ''">{{ $t('village.build.submit') }}</span>
|
||||||
</button>
|
</button>
|
||||||
<span v-else class="text-xs font-semibold whitespace-nowrap text-blood-700">{{ reason(row.option) }}</span>
|
<span v-else class="hidden text-xs font-semibold whitespace-nowrap text-blood-700 @2xl:inline">{{ reason(row.option) }}</span>
|
||||||
</td>
|
</td>
|
||||||
</template>
|
</template>
|
||||||
|
</template>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
@ -252,34 +280,38 @@ const demolishable = computed(() =>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else class="overflow-x-auto">
|
<div v-else>
|
||||||
<table class="w-full min-w-[34rem] border-collapse text-sm">
|
<table class="grid-table build-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="border-b-2 border-wood-700 bg-parchment-100 text-left text-xs font-semibold text-ink-700">
|
<tr>
|
||||||
<th class="px-3 py-1.5">{{ $t('village.build.building') }}</th>
|
<th class="pl-3">{{ $t('village.build.building') }}</th>
|
||||||
<th class="px-2 py-1.5">{{ $t('village.build.refund') }}</th>
|
<th class="hidden @xl:table-cell">{{ $t('village.build.refund') }}</th>
|
||||||
<th class="px-2 py-1.5 text-right">{{ $t('village.build.time') }}</th>
|
<th class="hidden text-right @xl:table-cell">{{ $t('village.build.time') }}</th>
|
||||||
<th class="px-3 py-1.5 text-right">{{ $t('village.build.tab_demolish') }}</th>
|
<th class="pr-3 text-right">{{ $t('village.build.tab_demolish') }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="{ b, name } in demolishable" :key="b.id" class="border-b border-parchment-300 last:border-b-0 even:bg-parchment-100">
|
<tr v-for="{ b, name } in demolishable" :key="b.id" class="even:bg-parchment-100">
|
||||||
<td class="px-3 py-1">
|
<td class="pl-3">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<IconBuildingTile :type="b.type" class="size-7" />
|
<IconBuildingTile :type="b.type" class="size-7" />
|
||||||
<div class="min-w-0 leading-tight">
|
<div class="min-w-0 leading-tight">
|
||||||
<p class="truncate font-semibold">{{ name }}</p>
|
<p class="truncate font-semibold">{{ name }}</p>
|
||||||
<p class="text-xs text-ink-500">{{ $t('village.buildings.level_n', { level: b.level }) }}</p>
|
<p class="text-xs text-ink-500">{{ $t('village.buildings.level_n', { level: b.level }) }}</p>
|
||||||
|
<p v-if="b.demolish" class="mt-0.5 flex flex-wrap items-center gap-x-2.5 @xl:hidden">
|
||||||
|
<UiCost :cost="b.demolish.refund" />
|
||||||
|
<span class="inline-flex items-center gap-1 text-xs text-ink-700 tabular-nums"><IconUi name="clock" class="size-3" />{{ formatDuration(b.demolish.seconds) }}</span>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-2 py-1"><UiCost v-if="b.demolish" :cost="b.demolish.refund" nowrap /></td>
|
<td class="hidden @xl:table-cell"><UiCost v-if="b.demolish" :cost="b.demolish.refund" nowrap /></td>
|
||||||
<td class="px-2 py-1 text-right tabular-nums whitespace-nowrap">{{ b.demolish ? formatDuration(b.demolish.seconds) : '' }}</td>
|
<td class="hidden text-right tabular-nums whitespace-nowrap @xl:table-cell">{{ b.demolish ? formatDuration(b.demolish.seconds) : '' }}</td>
|
||||||
<td class="px-3 py-1 text-right">
|
<td class="pr-3 text-right">
|
||||||
<button
|
<button
|
||||||
v-if="b.demolish"
|
v-if="b.demolish"
|
||||||
type="button"
|
type="button"
|
||||||
class="btn btn-outline min-w-[5.5rem] border-blood-700 px-2.5 py-1 whitespace-nowrap text-blood-700"
|
class="btn btn-outline min-w-[5.5rem] border-blood-700 px-2.5 py-0.5 whitespace-nowrap text-blood-700"
|
||||||
:disabled="busy"
|
:disabled="busy"
|
||||||
@click="emit('demolish', b.id)"
|
@click="emit('demolish', b.id)"
|
||||||
>
|
>
|
||||||
|
|
@ -301,6 +333,11 @@ const demolishable = computed(() =>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@reference "~/assets/css/main.css";
|
@reference "~/assets/css/main.css";
|
||||||
|
|
||||||
|
/* A heavier rule opens each building type, so the groups read as blocks. */
|
||||||
|
.build-table tr.group-start td {
|
||||||
|
@apply border-t-2 border-t-wood-600;
|
||||||
|
}
|
||||||
|
|
||||||
/* The row a quest points at: a gold band and a marker before the name. */
|
/* The row a quest points at: a gold band and a marker before the name. */
|
||||||
.quest-hint {
|
.quest-hint {
|
||||||
@apply bg-gold-400;
|
@apply bg-gold-400;
|
||||||
|
|
|
||||||
|
|
@ -11,18 +11,17 @@ const emit = defineEmits<{
|
||||||
}>()
|
}>()
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
// Who works where: building and upgrading live in the construction table above.
|
// Who works where: building and upgrading live in the construction table above. Copies are
|
||||||
|
// named in the server's rank, like everywhere else ("Storage, copy 2").
|
||||||
const named = computed(() => {
|
const named = computed(() => {
|
||||||
const seen = new Map<BuildingType, number>()
|
const byType = new Map<BuildingType, Building[]>()
|
||||||
const totals = new Map<BuildingType, number>()
|
for (const b of props.buildings) byType.set(b.type, [...(byType.get(b.type) ?? []), b])
|
||||||
for (const b of props.buildings) totals.set(b.type, (totals.get(b.type) ?? 0) + 1)
|
const rank = new Map<number, number>()
|
||||||
|
for (const list of byType.values()) ranked(list).forEach((b, i) => rank.set(b.id, i))
|
||||||
return props.buildings.map((b) => {
|
return props.buildings.map((b) => {
|
||||||
const n = (seen.get(b.type) ?? 0) + 1
|
const n = rank.get(b.id) ?? 0
|
||||||
seen.set(b.type, n)
|
const name = t(`buildings.${b.type}`)
|
||||||
return {
|
return { b, name: n > 0 ? t('village.copy.name', { name, n: n + 1 }) : name }
|
||||||
b,
|
|
||||||
name: (totals.get(b.type) ?? 0) > 1 ? t('village.build.nth', { name: t(`buildings.${b.type}`), n }) : t(`buildings.${b.type}`),
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,12 @@ const { t } = useI18n()
|
||||||
// building instance has its own tab, since each one trains in its own queue.
|
// building instance has its own tab, since each one trains in its own queue.
|
||||||
const current = computed(() => props.military.find((m) => m.building_id === selected.value) ?? props.military[0] ?? null)
|
const current = computed(() => props.military.find((m) => m.building_id === selected.value) ?? props.military[0] ?? null)
|
||||||
|
|
||||||
|
const v = useVillageContextOrNull()
|
||||||
|
/** The building's name as everywhere else: copies in the server's rank ("Barracks, copy 2"). */
|
||||||
function tabName(m: MilitaryBuilding) {
|
function tabName(m: MilitaryBuilding) {
|
||||||
const same = props.military.filter((x) => x.type === m.type)
|
const village = v?.village.value
|
||||||
const name = t(`buildings.${m.type}`)
|
const building = village?.buildings.find((b) => b.id === m.building_id)
|
||||||
return same.length > 1 ? t('village.build.nth', { name, n: same.indexOf(m) + 1 }) : name
|
return village && building ? buildingName(village, building, t) : t(`buildings.${m.type}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const amounts = reactive<Partial<Record<UnitType, number>>>({})
|
const amounts = reactive<Partial<Record<UnitType, number>>>({})
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ function showBuilding(id: number) {
|
||||||
:resources="resources"
|
:resources="resources"
|
||||||
:can-afford="v.canAfford"
|
:can-afford="v.canAfford"
|
||||||
:busy="v.busy.value"
|
:busy="v.busy.value"
|
||||||
|
:idle="village.population.idle"
|
||||||
:hint="typeof route.query.hint === 'string' ? route.query.hint : null"
|
:hint="typeof route.query.hint === 'string' ? route.query.hint : null"
|
||||||
@build="v.build"
|
@build="v.build"
|
||||||
@upgrade="v.upgrade"
|
@upgrade="v.upgrade"
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ watch(building, (b) => {
|
||||||
:resources="resources"
|
:resources="resources"
|
||||||
:can-afford="v.canAfford"
|
:can-afford="v.canAfford"
|
||||||
:busy="v.busy.value"
|
:busy="v.busy.value"
|
||||||
|
:idle="village.population.idle"
|
||||||
@build="v.build"
|
@build="v.build"
|
||||||
@upgrade="v.upgrade"
|
@upgrade="v.upgrade"
|
||||||
@demolish="v.demolish"
|
@demolish="v.demolish"
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,11 @@ export const isCopy = (share: number | undefined) => share !== undefined && shar
|
||||||
|
|
||||||
/** 0.5 → 50, 0.125 → 12.5. */
|
/** 0.5 → 50, 0.125 → 12.5. */
|
||||||
export const sharePercent = (share: number) => Math.round(share * 1000) / 10
|
export const sharePercent = (share: number) => Math.round(share * 1000) / 10
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The instances of one type in the server's rank: by share (the first works in full), then
|
||||||
|
* level, then age. The share decides, so the order needs no copy rule in the client.
|
||||||
|
*/
|
||||||
|
export function ranked<B extends { id: number; level: number; instance_share: number }>(instances: B[]): B[] {
|
||||||
|
return [...instances].sort((a, b) => b.instance_share - a.instance_share || b.level - a.level || a.id - b.id)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,12 @@ export function buildingOfRoute(village: VillageState, path: string, query: Reco
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A building's name, numbered ("Timber camp 2") when the village has more than one of its type. */
|
/**
|
||||||
|
* A building's name. Copies are counted in the server's rank ("Timber camp, copy 2"); the
|
||||||
|
* one that works in full is the plain name.
|
||||||
|
*/
|
||||||
export function buildingName(village: VillageState, building: Building, t: (key: string, params?: Record<string, unknown>) => string) {
|
export function buildingName(village: VillageState, building: Building, t: (key: string, params?: Record<string, unknown>) => string) {
|
||||||
const same = village.buildings.filter((b) => b.type === building.type)
|
|
||||||
const name = t(`buildings.${building.type}`)
|
const name = t(`buildings.${building.type}`)
|
||||||
return same.length > 1 ? t('village.build.nth', { name, n: same.findIndex((b) => b.id === building.id) + 1 }) : name
|
const n = ranked(village.buildings.filter((b) => b.type === building.type)).findIndex((b) => b.id === building.id)
|
||||||
|
return n > 0 ? t('village.copy.name', { name, n: n + 1 }) : name
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -324,7 +324,6 @@ export default {
|
||||||
build: {
|
build: {
|
||||||
tab_construct: 'Construct',
|
tab_construct: 'Construct',
|
||||||
tab_demolish: 'Demolition',
|
tab_demolish: 'Demolition',
|
||||||
nth: '{name} {n}',
|
|
||||||
not_built: 'Not built yet',
|
not_built: 'Not built yet',
|
||||||
another_hint: 'New copy, not built yet',
|
another_hint: 'New copy, not built yet',
|
||||||
submit_another: 'Build another',
|
submit_another: 'Build another',
|
||||||
|
|
@ -349,7 +348,6 @@ export default {
|
||||||
copy: {
|
copy: {
|
||||||
name: '{name}, copy {n}',
|
name: '{name}, copy {n}',
|
||||||
nth: 'Copy {n} · {share}%',
|
nth: 'Copy {n} · {share}%',
|
||||||
share: 'works at {share}%',
|
|
||||||
this: 'Copy: works at {share}%',
|
this: 'Copy: works at {share}%',
|
||||||
new: 'New copy: works at {share}%, costs more',
|
new: 'New copy: works at {share}%, costs more',
|
||||||
offer: 'This copy would work at {share}% and cost more than the first.',
|
offer: 'This copy would work at {share}% and cost more than the first.',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue