feat: the village at a glance: a tag over every building with its live number, stock cells with amount, limit and rate, a click outside a window closes it
Camps show production, storage its fullest resource against the limit, the farm free villagers, the HQ building space, military buildings what they train, the rally point its troops (red under attack), wall, hiding place and watchtower their effect. While a window or build card is open, a click in the village only closes it; Esc closes too. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
6e443f0e11
commit
bcba3edf73
|
|
@ -25,15 +25,22 @@ const title = computed(() =>
|
||||||
)
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- One resource in the village row: icon and amount, with a hairline of how full the storage is. -->
|
<!--
|
||||||
|
One resource in the village row, everything about it side by side: the amount against
|
||||||
|
the storage limit, what comes in per hour, and a bar of how full the storage is.
|
||||||
|
-->
|
||||||
<template>
|
<template>
|
||||||
<span class="inline-flex min-w-0 items-center gap-1" :title="title">
|
<span class="inline-flex min-w-0 items-center gap-1 sm:gap-1.5" :title="title">
|
||||||
<IconResource :resource="resource" class="size-4 shrink-0" />
|
<IconResource :resource="resource" class="size-4 shrink-0 sm:size-5" />
|
||||||
<span class="flex min-w-0 flex-col">
|
<span class="flex min-w-0 flex-col leading-tight">
|
||||||
<span class="leading-tight font-semibold tabular-nums" :class="full || rate < 0 ? 'text-blood-700' : 'text-ink-900'">
|
<span class="whitespace-nowrap tabular-nums">
|
||||||
{{ formatAmount(amount) }}
|
<span class="font-semibold" :class="full ? 'text-blood-700' : 'text-ink-900'">{{ formatAmount(amount) }}</span>
|
||||||
|
<span class="hidden text-xs text-ink-500 sm:inline">/{{ cap }}</span>
|
||||||
</span>
|
</span>
|
||||||
<span class="h-0.5 w-full min-w-8 bg-parchment-300" aria-hidden="true">
|
<span class="text-xs whitespace-nowrap tabular-nums" :class="full || rate < 0 ? 'font-semibold text-blood-700' : 'text-moss-700'">
|
||||||
|
{{ full ? $t('village.resources.full_short') : $t('village.resources.per_hour', { rate: formatRate(rate) }) }}
|
||||||
|
</span>
|
||||||
|
<span class="mt-0.5 h-1 w-full min-w-8 bg-parchment-300" aria-hidden="true">
|
||||||
<span class="block h-full" :class="full ? 'bg-blood-700' : share > 0.85 ? 'bg-gold-500' : 'bg-moss-600'" :style="{ width: `${share * 100}%` }" />
|
<span class="block h-full" :class="full ? 'bg-blood-700' : share > 0.85 ? 'bg-gold-500' : 'bg-moss-600'" :style="{ width: `${share * 100}%` }" />
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ const incoming = computed(() => props.village.movements.filter((m) => m.directio
|
||||||
const attacks = computed(() => incoming.value.filter((m) => m.type === 'attack'))
|
const attacks = computed(() => incoming.value.filter((m) => m.type === 'attack'))
|
||||||
const nextAttack = computed(() => attacks.value[0] ?? null)
|
const nextAttack = computed(() => attacks.value[0] ?? null)
|
||||||
const support = computed(() => incoming.value.length - attacks.value.length)
|
const support = computed(() => incoming.value.length - attacks.value.length)
|
||||||
|
/** Villagers neither working nor levied: free to staff a new building or to train. */
|
||||||
|
const idle = computed(() => Math.max(0, props.village.population.villagers - props.village.population.workers - props.village.levy.militia))
|
||||||
const isActive = (path: string) => route.path === `${base.value}${path}`
|
const isActive = (path: string) => route.path === `${base.value}${path}`
|
||||||
|
|
||||||
/** Another of the player's villages, on the same screen where the URL has one. */
|
/** Another of the player's villages, on the same screen where the URL has one. */
|
||||||
|
|
@ -123,17 +125,16 @@ async function rename() {
|
||||||
<span v-if="village.loyalty < 100" class="cell flex font-semibold text-blood-700" :title="`${$t('village.loyalty')}: ${$t('village.loyalty_about')}`">
|
<span v-if="village.loyalty < 100" class="cell flex font-semibold text-blood-700" :title="`${$t('village.loyalty')}: ${$t('village.loyalty_about')}`">
|
||||||
{{ $t('village.loyalty') }} <span class="tabular-nums">{{ village.loyalty }}</span>
|
{{ $t('village.loyalty') }} <span class="tabular-nums">{{ village.loyalty }}</span>
|
||||||
</span>
|
</span>
|
||||||
<span class="cell hidden lg:flex" :title="$t('village.resources.cap')">
|
|
||||||
<IconBuilding type="storage" class="size-4 text-wood-800" />
|
|
||||||
<span class="tabular-nums">{{ village.storage_cap }}</span>
|
|
||||||
</span>
|
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
:to="`${base}/workforce`"
|
:to="`${base}/workforce`"
|
||||||
class="cell flex hover:bg-parchment-100"
|
class="cell flex hover:bg-parchment-100"
|
||||||
:title="`${$t('village.population.villagers')}: ${village.population.villagers} · ${$t('village.population.upkeep')}: ${village.population.upkeep}/${village.population.food_budget}`"
|
:title="`${$t('village.population.villagers')}: ${village.population.villagers} · ${$t('village.population.upkeep')}: ${village.population.upkeep}/${village.population.food_budget}`"
|
||||||
>
|
>
|
||||||
<IconUi name="users" class="size-4 text-wood-800" />
|
<IconUi name="users" class="size-4 shrink-0 text-wood-800 sm:size-5" />
|
||||||
<span class="tabular-nums">{{ village.population.villagers }}</span>
|
<span class="flex flex-col leading-tight">
|
||||||
|
<span class="font-semibold tabular-nums">{{ village.population.villagers }}</span>
|
||||||
|
<span class="text-xs whitespace-nowrap text-ink-500 tabular-nums">{{ $t('village.resources.free', { free: idle }) }}</span>
|
||||||
|
</span>
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -163,6 +164,6 @@ async function rename() {
|
||||||
@apply bg-parchment-50 text-blood-700;
|
@apply bg-parchment-50 text-blood-700;
|
||||||
}
|
}
|
||||||
.cell {
|
.cell {
|
||||||
@apply items-center justify-center gap-1 border-l border-parchment-300 px-2 py-1 first:border-l-0;
|
@apply items-center justify-center gap-1 border-l border-parchment-300 px-1 py-1 first:border-l-0 sm:px-2;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,18 @@ const screenTitle = computed(() => {
|
||||||
})
|
})
|
||||||
const picked = computed(() => !!plot.value)
|
const picked = computed(() => !!plot.value)
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
if (e.key !== 'Escape' || e.defaultPrevented || document.querySelector('dialog[open]')) return
|
||||||
|
const el = e.target as HTMLElement | null
|
||||||
|
if (el && ['INPUT', 'TEXTAREA', 'SELECT'].includes(el.tagName)) return
|
||||||
|
if (picked.value) clear()
|
||||||
|
else if (!overview.value && !onMap.value) navigateTo(base.value)
|
||||||
|
}
|
||||||
|
onMounted(() => window.addEventListener('keydown', onEscape))
|
||||||
|
onBeforeUnmount(() => window.removeEventListener('keydown', onEscape))
|
||||||
|
|
||||||
// The map draws itself under the menu bar; it needs to know where that ends.
|
// The map draws itself under the menu bar; it needs to know where that ends.
|
||||||
const menuBar = ref<HTMLElement | null>(null)
|
const menuBar = ref<HTMLElement | null>(null)
|
||||||
const menuBottom = ref(0)
|
const menuBottom = ref(0)
|
||||||
|
|
@ -135,6 +147,8 @@ useShortcuts(() => {
|
||||||
fill
|
fill
|
||||||
:inset="inset"
|
:inset="inset"
|
||||||
:village="v.village.value"
|
:village="v.village.value"
|
||||||
|
:resources="v.resources.value"
|
||||||
|
:dismiss="!overview || picked"
|
||||||
:seconds-until="v.secondsUntil"
|
:seconds-until="v.secondsUntil"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { BuildingType, VillageState } from '~/types/game'
|
import type { BuildingType, Resources, VillageState } from '~/types/game'
|
||||||
import { drillThrust, workInPlace } from '~/diorama/life'
|
import { drillThrust, workInPlace } from '~/diorama/life'
|
||||||
import { buildScene, type SceneBuilding, type SceneInset, type ScenePlot } from '~/diorama/scene'
|
import { buildScene, type SceneBuilding, type SceneInset, type ScenePlot } from '~/diorama/scene'
|
||||||
|
import type { BuildingTag } from '~/utils/buildingTags'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
village: VillageState
|
village: VillageState
|
||||||
|
|
@ -11,6 +12,10 @@ const props = defineProps<{
|
||||||
fill?: boolean
|
fill?: boolean
|
||||||
/** With `fill`: pixels at the edges that windows cover; the whole village fits into the rest. */
|
/** With `fill`: pixels at the edges that windows cover; the whole village fits into the rest. */
|
||||||
inset?: SceneInset
|
inset?: SceneInset
|
||||||
|
/** Projected stock, for the storage's tag. */
|
||||||
|
resources?: Resources | null
|
||||||
|
/** A window or card is open: a click in the village closes it instead of opening another. */
|
||||||
|
dismiss?: boolean
|
||||||
}>()
|
}>()
|
||||||
/** Id of the building whose details are open. */
|
/** Id of the building whose details are open. */
|
||||||
const selected = defineModel<number | null>('selected', { default: null })
|
const selected = defineModel<number | null>('selected', { default: null })
|
||||||
|
|
@ -68,23 +73,56 @@ function clear() {
|
||||||
selected.value = null
|
selected.value = null
|
||||||
plot.value = null
|
plot.value = null
|
||||||
}
|
}
|
||||||
|
// A pointer click while something is open only closes it, so a stray click never swaps
|
||||||
|
// the window for another; keys still open what has focus.
|
||||||
|
const press = (id: number) => (props.dismiss ? clear() : toggle(id))
|
||||||
|
const pressPlot = (type: BuildingType) => (props.dismiss ? clear() : pick(type))
|
||||||
|
|
||||||
/** viewBox units per screen pixel: badges keep the same size however the scene is scaled. */
|
/** viewBox units per screen pixel: badges keep the same size however the scene is scaled. */
|
||||||
const k = computed(() => (scene.value.width / Math.max(1, size.value.w)) * (size.value.w < 900 ? 0.85 : 1))
|
const k = computed(() => (scene.value.width / Math.max(1, size.value.w)) * (size.value.w < 900 ? 0.85 : 1))
|
||||||
|
|
||||||
// Badges that would overlap move up above the one in front, nearest buildings first.
|
// Every building wears a tag like the old village views: its level and the one number
|
||||||
|
// that says what it does now (app/utils/buildingTags.ts). Sizes are screen pixels, scaled
|
||||||
|
// by k into the scene, so tags read the same however the village is scaled.
|
||||||
|
const TAG = { h: 20, chip: 20, icon: 14, gap: 4, pad: 6, font: 12 }
|
||||||
|
const FONT = 'ui-sans-serif, system-ui, sans-serif'
|
||||||
|
let measurer: CanvasRenderingContext2D | null = null
|
||||||
|
const widths = new Map<string, number>()
|
||||||
|
function textWidth(text: string) {
|
||||||
|
if (!widths.has(text)) {
|
||||||
|
measurer ??= import.meta.client ? document.createElement('canvas').getContext('2d') : null
|
||||||
|
if (measurer) measurer.font = `700 ${TAG.font}px ${FONT}`
|
||||||
|
widths.set(text, measurer ? Math.ceil(measurer.measureText(text).width) : text.length * 7.5)
|
||||||
|
}
|
||||||
|
return widths.get(text)!
|
||||||
|
}
|
||||||
|
const TONES = {
|
||||||
|
plain: { fill: '#f3e7c9', stroke: '#57391f', text: '#2f2013', icon: '#57391f' },
|
||||||
|
warn: { fill: '#e8cd7c', stroke: '#8a6a1c', text: '#2f2013', icon: '#57391f' },
|
||||||
|
alarm: { fill: '#7b1e16', stroke: '#4a120d', text: '#f3e7c9', icon: '#f3e7c9' },
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tags that would overlap move up above the one in front, nearest buildings first.
|
||||||
const badges = computed(() => {
|
const badges = computed(() => {
|
||||||
|
const K = k.value
|
||||||
const list = scene.value.objects.flatMap((o) => (o.building?.focusable ? [o.building] : []))
|
const list = scene.value.objects.flatMap((o) => (o.building?.focusable ? [o.building] : []))
|
||||||
const r = 13 * k.value
|
const placed: { b: SceneBuilding; info: BuildingTag | null; x: number; y: number; w: number; h: number }[] = []
|
||||||
const placed: { b: SceneBuilding; x: number; y: number }[] = []
|
const overlaps = (x: number, y: number, w: number, h: number) =>
|
||||||
|
placed.some((p) => Math.abs(p.x - x) < (p.w + w) / 2 + 2 * K && Math.abs(p.y - y) < (p.h + h) / 2 + 2 * K)
|
||||||
for (const b of [...list].sort((p, q) => q.label[1] - p.label[1])) {
|
for (const b of [...list].sort((p, q) => q.label[1] - p.label[1])) {
|
||||||
|
const building = props.village.buildings.find((x) => x.id === b.id)
|
||||||
|
const info = building && props.resources ? buildingTag(props.village, building, props.resources, props.secondsUntil, t) : null
|
||||||
|
const inner = info ? TAG.pad + (info.icon ? TAG.icon + TAG.gap : 0) + textWidth(info.text) + TAG.pad : 0
|
||||||
|
const w = (TAG.chip + inner) * K
|
||||||
|
const h = TAG.h * K
|
||||||
const [x] = b.label
|
const [x] = b.label
|
||||||
let y = b.label[1]
|
let y = b.label[1]
|
||||||
for (let n = 0; n < 6 && placed.some((p) => Math.abs(p.x - x) < r * 2.1 && Math.abs(p.y - y) < r * 2.1); n++) y -= r * 2.2
|
for (let n = 0; n < 8 && overlaps(x, y, w, h); n++) y -= h * 1.2
|
||||||
placed.push({ b, x, y })
|
placed.push({ b, info, x, y, w, h })
|
||||||
}
|
}
|
||||||
return placed
|
return placed
|
||||||
})
|
})
|
||||||
|
const tagTitle = (b: SceneBuilding, info: BuildingTag | null) => [label(b), info?.title].filter(Boolean).join(' · ')
|
||||||
|
|
||||||
// Countdowns sit right above what is being built: over the level badge, or over the
|
// Countdowns sit right above what is being built: over the level badge, or over the
|
||||||
// scaffold of a new building.
|
// scaffold of a new building.
|
||||||
|
|
@ -95,11 +133,11 @@ const timers = computed(() => {
|
||||||
const placed: { x: number; y: number }[] = []
|
const placed: { x: number; y: number }[] = []
|
||||||
const hits = (x: number, y: number) =>
|
const hits = (x: number, y: number) =>
|
||||||
placed.some((p) => Math.abs(p.x - x) < half.w * 2 && Math.abs(p.y - y) < half.h * 2) ||
|
placed.some((p) => Math.abs(p.x - x) < half.w * 2 && Math.abs(p.y - y) < half.h * 2) ||
|
||||||
badges.value.some((p) => Math.abs(p.x - x) < half.w + 13 * K && Math.abs(p.y - y) < half.h + 13 * K)
|
badges.value.some((p) => Math.abs(p.x - x) < half.w + p.w / 2 && Math.abs(p.y - y) < half.h + p.h / 2)
|
||||||
return scene.value.timers
|
return scene.value.timers
|
||||||
.map((tm) => {
|
.map((tm) => {
|
||||||
const badge = tm.buildingId !== null ? badges.value.find((p) => p.b.id === tm.buildingId) : undefined
|
const badge = tm.buildingId !== null ? badges.value.find((p) => p.b.id === tm.buildingId) : undefined
|
||||||
const lift = badge ? 29 : 2
|
const lift = badge ? 24 : 2
|
||||||
return { ...tm, x: badge?.x ?? tm.at[0], y: (badge?.y ?? tm.at[1]) - lift * K }
|
return { ...tm, x: badge?.x ?? tm.at[0], y: (badge?.y ?? tm.at[1]) - lift * K }
|
||||||
})
|
})
|
||||||
.sort((a, b) => b.y - a.y)
|
.sort((a, b) => b.y - a.y)
|
||||||
|
|
@ -159,7 +197,7 @@ const timers = computed(() => {
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
:aria-label="plotLabel(p)"
|
:aria-label="plotLabel(p)"
|
||||||
:aria-pressed="plot === p.type"
|
:aria-pressed="plot === p.type"
|
||||||
@click.stop="pick(p.type)"
|
@click.stop="pressPlot(p.type)"
|
||||||
@keydown.enter.prevent="pick(p.type)"
|
@keydown.enter.prevent="pick(p.type)"
|
||||||
@keydown.space.prevent="pick(p.type)"
|
@keydown.space.prevent="pick(p.type)"
|
||||||
>
|
>
|
||||||
|
|
@ -173,7 +211,7 @@ const timers = computed(() => {
|
||||||
v-bind="scene.wallBand.ring"
|
v-bind="scene.wallBand.ring"
|
||||||
:stroke-width="scene.wallBand.width"
|
:stroke-width="scene.wallBand.width"
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
@click.stop="toggle(scene.wallBand.id)"
|
@click.stop="press(scene.wallBand.id)"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<template v-for="obj in scene.objects" :key="obj.key">
|
<template v-for="obj in scene.objects" :key="obj.key">
|
||||||
|
|
@ -189,7 +227,7 @@ const timers = computed(() => {
|
||||||
:aria-pressed="obj.building.focusable ? selected === obj.building.id : undefined"
|
:aria-pressed="obj.building.focusable ? selected === obj.building.id : undefined"
|
||||||
stroke-width="0.6"
|
stroke-width="0.6"
|
||||||
stroke-linejoin="round"
|
stroke-linejoin="round"
|
||||||
@click.stop="toggle(obj.building.id)"
|
@click.stop="press(obj.building.id)"
|
||||||
@keydown.enter.prevent="toggle(obj.building.id)"
|
@keydown.enter.prevent="toggle(obj.building.id)"
|
||||||
@keydown.space.prevent="toggle(obj.building.id)"
|
@keydown.space.prevent="toggle(obj.building.id)"
|
||||||
>
|
>
|
||||||
|
|
@ -258,22 +296,43 @@ const timers = computed(() => {
|
||||||
<VillageBird v-for="(b, i) in scene.birds" :key="`bird-${i}`" :d="b.d" :dur="b.dur" :begin="b.begin" :size="1.6" />
|
<VillageBird v-for="(b, i) in scene.birds" :key="`bird-${i}`" :d="b.d" :dur="b.dur" :begin="b.begin" :size="1.6" />
|
||||||
</g>
|
</g>
|
||||||
|
|
||||||
<!-- Level badges and countdowns. Flat colours only. -->
|
<!-- Building tags (level and what it does now) and countdowns. Flat colours only. -->
|
||||||
<g class="pointer-events-none" font-family="ui-sans-serif, system-ui, sans-serif" text-anchor="middle">
|
<g class="pointer-events-none" :font-family="FONT" text-anchor="middle">
|
||||||
<g
|
<g
|
||||||
v-for="{ b, x, y } in badges"
|
v-for="{ b, info, x, y, w } in badges"
|
||||||
:key="`badge-${b.id}`"
|
:key="`badge-${b.id}`"
|
||||||
class="pointer-events-auto cursor-pointer"
|
class="pointer-events-auto cursor-pointer"
|
||||||
:transform="`translate(${x} ${y})`"
|
:transform="`translate(${x - w / 2} ${y}) scale(${k})`"
|
||||||
@click.stop="toggle(b.id)"
|
@click.stop="press(b.id)"
|
||||||
>
|
>
|
||||||
<circle
|
<title>{{ tagTitle(b, info) }}</title>
|
||||||
:r="12 * k"
|
<rect
|
||||||
:fill="b.upgrading ? '#c49a2c' : '#f3e7c9'"
|
:width="w / k"
|
||||||
:stroke="selected === b.id ? '#7b1e16' : '#57391f'"
|
:height="TAG.h"
|
||||||
:stroke-width="1.6 * k"
|
:y="-TAG.h / 2"
|
||||||
|
:fill="TONES[info?.tone ?? 'plain'].fill"
|
||||||
|
:stroke="selected === b.id ? '#7b1e16' : TONES[info?.tone ?? 'plain'].stroke"
|
||||||
|
:stroke-width="selected === b.id ? 2.4 : 1.4"
|
||||||
/>
|
/>
|
||||||
<text :y="4.6 * k" :font-size="13 * k" font-weight="700" :fill="b.upgrading ? '#1f150c' : '#2f2013'">{{ b.level }}</text>
|
<rect :width="TAG.chip" :height="TAG.h" :y="-TAG.h / 2" :fill="b.upgrading ? '#c49a2c' : '#57391f'" />
|
||||||
|
<text :x="TAG.chip / 2" :y="4.3" :font-size="TAG.font" font-weight="700" :fill="b.upgrading ? '#1f150c' : '#f3e7c9'">{{ b.level }}</text>
|
||||||
|
<template v-if="info">
|
||||||
|
<g v-if="info.icon" :transform="`translate(${TAG.chip + TAG.pad} ${-TAG.icon / 2})`" :style="{ color: TONES[info.tone].icon }">
|
||||||
|
<IconResource v-if="info.icon.kind === 'resource'" :resource="info.icon.name" :width="TAG.icon" :height="TAG.icon" />
|
||||||
|
<IconUnit v-else-if="info.icon.kind === 'unit'" :unit="info.icon.name" :width="TAG.icon" :height="TAG.icon" />
|
||||||
|
<IconUi v-else :name="info.icon.name" :width="TAG.icon" :height="TAG.icon" />
|
||||||
|
</g>
|
||||||
|
<text
|
||||||
|
:x="TAG.chip + TAG.pad + (info.icon ? TAG.icon + TAG.gap : 0)"
|
||||||
|
:y="4.3"
|
||||||
|
text-anchor="start"
|
||||||
|
:font-size="TAG.font"
|
||||||
|
font-weight="700"
|
||||||
|
:fill="TONES[info.tone].text"
|
||||||
|
>
|
||||||
|
{{ info.text }}
|
||||||
|
</text>
|
||||||
|
</template>
|
||||||
</g>
|
</g>
|
||||||
|
|
||||||
<g
|
<g
|
||||||
|
|
@ -281,7 +340,7 @@ const timers = computed(() => {
|
||||||
:key="`timer-${tm.orderId}`"
|
:key="`timer-${tm.orderId}`"
|
||||||
:class="tm.buildingId ? 'pointer-events-auto cursor-pointer' : ''"
|
:class="tm.buildingId ? 'pointer-events-auto cursor-pointer' : ''"
|
||||||
:transform="`translate(${tm.x} ${tm.y})`"
|
:transform="`translate(${tm.x} ${tm.y})`"
|
||||||
@click.stop="tm.buildingId && toggle(tm.buildingId)"
|
@click.stop="tm.buildingId && press(tm.buildingId)"
|
||||||
>
|
>
|
||||||
<rect :x="-39 * k" :y="-11.5 * k" :width="78 * k" :height="22 * k" :rx="2 * k" fill="#2f2013" stroke="#c49a2c" :stroke-width="1.2 * k" />
|
<rect :x="-39 * k" :y="-11.5 * k" :width="78 * k" :height="22 * k" :rx="2 * k" fill="#2f2013" stroke="#c49a2c" :stroke-width="1.2 * k" />
|
||||||
<g :transform="`translate(${-27.5 * k} ${-0.5 * k}) scale(${1.15 * k})`" fill="none" stroke="#d9b44a" stroke-width="1.4" stroke-linecap="round">
|
<g :transform="`translate(${-27.5 * k} ${-0.5 * k}) scale(${1.15 * k})`" fill="none" stroke="#d9b44a" stroke-width="1.4" stroke-linecap="round">
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,150 @@
|
||||||
|
import type { UiIconName } from '~/components/icon/Ui.vue'
|
||||||
|
import type { Building, Resource, Resources, UnitType, VillageState } from '~/types/game'
|
||||||
|
|
||||||
|
type Translate = (key: string, values?: Record<string, unknown>) => string
|
||||||
|
|
||||||
|
/** The fixed tag over a building in the village: the one number that tells what it does now. */
|
||||||
|
export interface BuildingTag {
|
||||||
|
icon: { kind: 'resource'; name: Resource } | { kind: 'unit'; name: UnitType } | { kind: 'ui'; name: UiIconName } | null
|
||||||
|
text: string
|
||||||
|
/** warn: worth a look soon (storage nearly full); alarm: act now (storage full, under attack). */
|
||||||
|
tone: 'plain' | 'warn' | 'alarm'
|
||||||
|
/** The longer version, for the tooltip. */
|
||||||
|
title: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const STOCK = ['wood', 'clay', 'iron', 'food'] as const
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What a building's tag says, from the village state and the projected stock: a camp its
|
||||||
|
* production, the storage its fullest resource against the limit, the farm the free
|
||||||
|
* villagers, the headquarters the free building space, a military building what it
|
||||||
|
* trains, the rally point the troops in the village, the wall its bonus. Nothing is
|
||||||
|
* computed beyond projecting the stock and counting down server timestamps.
|
||||||
|
*/
|
||||||
|
export function buildingTag(
|
||||||
|
village: VillageState,
|
||||||
|
b: Building,
|
||||||
|
resources: Resources,
|
||||||
|
secondsUntil: (iso: string) => number,
|
||||||
|
t: Translate,
|
||||||
|
): BuildingTag | null {
|
||||||
|
const effect = (key: string) => b.effects.find((e) => e.key === key)?.value ?? 0
|
||||||
|
|
||||||
|
switch (b.type) {
|
||||||
|
case 'timber_camp':
|
||||||
|
case 'clay_pit':
|
||||||
|
case 'iron_mine': {
|
||||||
|
if (!b.production) return null
|
||||||
|
const rate = Math.round(b.production.per_hour)
|
||||||
|
const short = b.staffing < 1
|
||||||
|
return {
|
||||||
|
icon: { kind: 'resource', name: b.production.resource },
|
||||||
|
text: t('village.tags.per_hour', { rate }),
|
||||||
|
tone: short ? 'warn' : 'plain',
|
||||||
|
title: [
|
||||||
|
t('village.tags.production', { rate, resource: t(`resources.${b.production.resource}`) }),
|
||||||
|
short ? t('village.tags.understaffed', b.workers) : null,
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(' · '),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'storage': {
|
||||||
|
const cap = village.storage_cap
|
||||||
|
const fullest = [...STOCK].sort((p, q) => resources[q] - resources[p])[0]!
|
||||||
|
const amount = Math.min(cap, Math.floor(resources[fullest]))
|
||||||
|
const share = cap > 0 ? amount / cap : 1
|
||||||
|
const rate = village.rates[fullest]
|
||||||
|
const fullIn = rate > 0 && share < 1 ? ((cap - amount) / rate) * 3600 : null
|
||||||
|
return {
|
||||||
|
icon: { kind: 'resource', name: fullest },
|
||||||
|
text: t('village.tags.stock', { amount, cap }),
|
||||||
|
tone: share >= 1 ? 'alarm' : share >= 0.85 ? 'warn' : 'plain',
|
||||||
|
title: [
|
||||||
|
t('village.tags.fullest', { resource: t(`resources.${fullest}`), amount, cap }),
|
||||||
|
share >= 1 ? t('village.resources.full') : fullIn !== null ? t('village.resources.full_in', { time: formatDuration(fullIn) }) : null,
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(' · '),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'farm': {
|
||||||
|
const p = village.population
|
||||||
|
const free = Math.max(0, p.villagers - p.workers - village.levy.militia)
|
||||||
|
const wanted = village.buildings.reduce((n, x) => n + x.workers.required, 0)
|
||||||
|
const short = wanted > p.workers
|
||||||
|
return {
|
||||||
|
icon: { kind: 'ui', name: 'users' },
|
||||||
|
text: t('village.tags.free', { free, villagers: p.villagers }),
|
||||||
|
tone: short ? 'warn' : 'plain',
|
||||||
|
title: [
|
||||||
|
t('village.tags.workforce', { free, villagers: p.villagers, workers: p.workers }),
|
||||||
|
short ? t('village.tags.short', { missing: wanted - p.workers }) : null,
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(' · '),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'headquarters': {
|
||||||
|
const free = village.space.max - village.space.used
|
||||||
|
return {
|
||||||
|
icon: { kind: 'ui', name: 'hammer' },
|
||||||
|
text: t('village.tags.space', { used: village.space.used, max: village.space.max }),
|
||||||
|
tone: free <= 0 ? 'alarm' : free < 4 ? 'warn' : 'plain',
|
||||||
|
title: t('village.tags.space_title', { free: Math.max(0, free), used: village.space.used, max: village.space.max }),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'barracks':
|
||||||
|
case 'stable':
|
||||||
|
case 'workshop':
|
||||||
|
case 'academy': {
|
||||||
|
const queue = village.military.find((m) => m.building_id === b.id)?.queue ?? []
|
||||||
|
// Units still to come per order, counted down from its finishing time.
|
||||||
|
const left = queue.map((o) => ({ o, n: Math.min(o.count, Math.ceil(Math.max(0, secondsUntil(o.finishes_at)) / o.seconds_per_unit)) })).filter((x) => x.n > 0)
|
||||||
|
if (!left.length) return { icon: null, text: t('village.tags.idle'), tone: 'plain', title: t('village.tags.idle_title') }
|
||||||
|
const units = left.reduce((n, x) => n + x.n, 0)
|
||||||
|
const done = formatDuration(secondsUntil(left[left.length - 1]!.o.finishes_at))
|
||||||
|
return {
|
||||||
|
icon: { kind: 'unit', name: left[0]!.o.unit },
|
||||||
|
text: t('village.tags.training', { units, time: done }),
|
||||||
|
tone: 'plain',
|
||||||
|
title: t('village.tags.training_title', { units, time: done }),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'rally_point': {
|
||||||
|
const count = (units: Partial<Record<string, number>>) => Object.values(units).reduce((n: number, c) => n + (c ?? 0), 0)
|
||||||
|
const own = count(village.troops)
|
||||||
|
const support = village.support.here.reduce((n, g) => n + count(g.units), 0)
|
||||||
|
const attacks = village.movements.filter((m) => m.direction === 'in' && m.type === 'attack').length
|
||||||
|
return {
|
||||||
|
icon: { kind: 'ui', name: attacks ? 'attack' : 'users' },
|
||||||
|
text: attacks ? t('village.tags.troops_attacked', { troops: own + support, attacks }) : t('village.tags.troops', { troops: own + support }),
|
||||||
|
tone: attacks ? 'alarm' : 'plain',
|
||||||
|
title: [t('village.tags.troops_title', { own, support }), attacks ? t('village.incoming', { count: attacks }) : null].filter(Boolean).join(' · '),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'wall':
|
||||||
|
return {
|
||||||
|
icon: { kind: 'ui', name: 'support' },
|
||||||
|
text: t('village.tags.percent', { value: effect('wall_bonus') }),
|
||||||
|
tone: 'plain',
|
||||||
|
title: t('village.tags.wall', { bonus: effect('wall_bonus'), defense: effect('wall_defense') }),
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'hiding_place':
|
||||||
|
return { icon: { kind: 'ui', name: 'eye' }, text: String(effect('hides')), tone: 'plain', title: t('village.tags.hides', { amount: effect('hides') }) }
|
||||||
|
|
||||||
|
case 'watchtower':
|
||||||
|
return { icon: { kind: 'ui', name: 'eye' }, text: t('village.tags.fields', { fields: effect('detection') }), tone: 'plain', title: t('village.tags.detection', { fields: effect('detection') }) }
|
||||||
|
|
||||||
|
default:
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -57,6 +57,30 @@ export default {
|
||||||
space: "Building space",
|
space: "Building space",
|
||||||
recruit_speed: "Training speed",
|
recruit_speed: "Training speed",
|
||||||
},
|
},
|
||||||
|
tags: {
|
||||||
|
per_hour: '+{rate}/h',
|
||||||
|
production: '{rate} {resource} per hour',
|
||||||
|
understaffed: 'short of workers: {assigned} of {required}',
|
||||||
|
stock: '{amount}/{cap}',
|
||||||
|
fullest: 'Fullest: {resource}, {amount} of {cap}',
|
||||||
|
free: '{free} free',
|
||||||
|
workforce: '{free} of {villagers} villagers free, {workers} at work',
|
||||||
|
short: 'the buildings want {missing} more workers',
|
||||||
|
space: '{used}/{max}',
|
||||||
|
space_title: 'Building space: {used} of {max} taken, {free} free',
|
||||||
|
idle: 'idle',
|
||||||
|
idle_title: 'Nothing in training',
|
||||||
|
training: '{units} · {time}',
|
||||||
|
training_title: '{units} units in training, all done in {time}',
|
||||||
|
troops: '{troops}',
|
||||||
|
troops_attacked: '{troops} · {attacks} incoming',
|
||||||
|
troops_title: '{own} own troops and {support} support in the village',
|
||||||
|
percent: '+{value}%',
|
||||||
|
wall: 'Defenders fight {bonus}% harder, plus {defense} defence',
|
||||||
|
hides: 'Hides {amount} of each resource from raiders',
|
||||||
|
fields: '{fields} fields',
|
||||||
|
detection: 'Spots incoming troops {fields} fields further out',
|
||||||
|
},
|
||||||
season: {
|
season: {
|
||||||
title: 'Season',
|
title: 'Season',
|
||||||
crowns_in: "Crown forts appear round 0{'|'}0 in {time}.",
|
crowns_in: "Crown forts appear round 0{'|'}0 in {time}.",
|
||||||
|
|
@ -95,10 +119,11 @@ export default {
|
||||||
points: '{points} points',
|
points: '{points} points',
|
||||||
resources: {
|
resources: {
|
||||||
title: 'Resources',
|
title: 'Resources',
|
||||||
cap: 'Storage cap',
|
|
||||||
per_hour: '{rate}/h',
|
per_hour: '{rate}/h',
|
||||||
full: 'storage full',
|
full: 'storage full',
|
||||||
full_in: 'full in {time}',
|
full_in: 'full in {time}',
|
||||||
|
full_short: 'full',
|
||||||
|
free: '{free} free',
|
||||||
},
|
},
|
||||||
population: {
|
population: {
|
||||||
title: 'Population',
|
title: 'Population',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue