feat: Die Stämme-style village: clean overview with a side column, building screens, clickable empty plots
The overview is the village and a column of boxes (production, units, population, construction); the stock sits in one line on every screen. Construction, recruiting and the workforce table move to their own screens. Types that don't stand yet keep an invisible plot that opens a build card. Buildings no longer lift or light up on hover; a click outlines the ground under them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
bb3796f22b
commit
a1f0dc445b
|
|
@ -8,8 +8,9 @@ This is the Nuxt client for a browser strategy game in the style of Tribal Wars.
|
|||
- **`ssr: false` for every target**, so one static build serves both the web and Steam. Code must not rely on Nuxt server routes or SSR-only APIs.
|
||||
- **Transport** is WS-first through the `ws` singleton from `@blax-software/networking`, the same as learn-atc. HTTP is only for login and register, which return the bearer token. Load the `blax-websockets` skill before you write `ws.send` or `ws.listen` code.
|
||||
- **Light Tailwind UI** (Tailwind 4, theme and component classes like `.panel`, `.btn` in `app/assets/css/main.css`) with simple hand-written inline SVG graphics (`app/components/icon/`, colours in `app/utils/palette.ts`). No paid, hosted or licensed assets: no icon packs, web fonts or images from outside the repo.
|
||||
- **The village is a ground-level land view** (`app/components/village/Diorama.vue`, geometry in `app/diorama/`): isometric low-poly, drawn as inline SVG, no WebGL. The land fills the frame edge to edge (no island, no sky), cut to the container's shape; narrow screens scroll sideways. There are no tiles or positions: the server only sends each building's `space` and the village's `space.used/max`, and the client lays everything out deterministically in id order. The village core sits in the middle (headquarters on the plaza, storage, hiding places and rally point around it, inside the wall ring when there is one, a dirt edge without). Resource sites stand outside in their zones: iron mines at the rocky hill (upper left), clay pits on clay ground (lower left), timber camps at the forest edge (lower right), farms with fields (right); dirt roads lead from the gates to each zone and forest fills the rest. Each type has a model per level tier (0, 1–4, 5–14, 15+); the wall goes stakes → timber → stone with towers. Buildings are focusable buttons that open their details card.
|
||||
- **The village is a ground-level land view** (`app/components/village/Diorama.vue`, geometry in `app/diorama/`): isometric low-poly, drawn as inline SVG, no WebGL. The land fills the frame edge to edge (no island, no sky), cut to the container's shape; narrow screens scroll sideways. There are no tiles or positions: the server only sends each building's `space` and the village's `space.used/max`, and the client lays everything out deterministically in id order. The village core sits in the middle (headquarters on the plaza, storage, hiding places and rally point around it, inside the wall ring when there is one, a dirt edge without). Resource sites stand outside in their zones: iron mines at the rocky hill (upper left), clay pits on clay ground (lower left), timber camps at the forest edge (lower right), farms with fields (right); dirt roads lead from the gates to each zone and forest fills the rest. Each type has a model per level tier (0, 1–4, 5–14, 15+); the wall goes stakes → timber → stone with towers. Buildings are focusable buttons that open their details card; a type that doesn't stand yet keeps an invisible empty plot that opens its build card. Buildings never move or light up on hover: only a click outlines the ground under them.
|
||||
- **Flat medieval colours only**, in the diorama and everywhere else: no gradients (CSS or SVG), no blur or backdrop-blur, no SVG filters or glows, no translucent overlays. Depth comes from the three flat shades per face in `app/diorama/iso.ts`, solid borders and hard shadows. Keep components small and typed, with state in composables (`useVillage`, `useWorld`).
|
||||
- **The village page is laid out like Die Stämme**: a compact strip with the stock and the screens (Overview, Headquarters, Recruit, Workforce), each a child route of `pages/village/[id].vue` sharing one `useVillage()` through `useVillageContext()`. The overview stays clean: the village and a narrow column of boxes (production, units, population, construction); tables live on the building screens.
|
||||
- All user-facing text goes through i18n keys, with `en` as the first locale. Sources are `i18n/locales/` and `i18n/pages/` (`@blax-software/i18n` layout); register a new page file in `i18n/messageloader.ts`.
|
||||
|
||||
## Mock server
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<script setup lang="ts">
|
||||
import type { RouteLocationRaw } from 'vue-router'
|
||||
import type { Building, Cost, Resources } from '~/types/game'
|
||||
|
||||
defineProps<{
|
||||
|
|
@ -6,14 +7,13 @@ defineProps<{
|
|||
resources: Resources
|
||||
canAfford: (cost: Cost) => boolean
|
||||
busy: boolean
|
||||
/** Whether it trains units, so the card links to its recruit tab. */
|
||||
trains?: boolean
|
||||
/** The building's own screen, e.g. construction for the headquarters, recruiting for a barracks. */
|
||||
link?: { to: RouteLocationRaw; label: string } | null
|
||||
}>()
|
||||
const emit = defineEmits<{
|
||||
upgrade: [buildingId: number]
|
||||
demolish: [buildingId: number]
|
||||
priority: [buildingId: number, priority: number]
|
||||
recruit: [buildingId: number]
|
||||
close: []
|
||||
}>()
|
||||
</script>
|
||||
|
|
@ -77,9 +77,7 @@ const emit = defineEmits<{
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<button v-if="trains" type="button" class="btn btn-outline w-full" @click="emit('recruit', building.id)">
|
||||
{{ $t('village.buildings.recruit') }}
|
||||
</button>
|
||||
<NuxtLink v-if="link" :to="link.to" class="btn btn-outline w-full">{{ link.label }}</NuxtLink>
|
||||
|
||||
<div v-if="building.upgrade" class="space-y-1.5 rounded-sm border border-wood-600/50 bg-parchment-100 p-3">
|
||||
<div class="flex items-center justify-between gap-2 text-xs text-ink-500">
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<script setup lang="ts">
|
||||
import type { VillageState } from '~/types/game'
|
||||
import { buildScene, type SceneBuilding } from '~/diorama/scene'
|
||||
import type { BuildingType, VillageState } from '~/types/game'
|
||||
import { buildScene, type SceneBuilding, type ScenePlot } from '~/diorama/scene'
|
||||
|
||||
const props = defineProps<{
|
||||
village: VillageState
|
||||
|
|
@ -9,6 +9,8 @@ const props = defineProps<{
|
|||
}>()
|
||||
/** Id of the building whose details are open. */
|
||||
const selected = defineModel<number | null>('selected', { default: null })
|
||||
/** Type whose empty plot was picked, to build it. */
|
||||
const plot = defineModel<BuildingType | null>('plot', { default: null })
|
||||
const { t } = useI18n()
|
||||
|
||||
// The scene is cut to the stage's shape, so the land always fills it edge to edge.
|
||||
|
|
@ -18,7 +20,6 @@ const stage = ref<HTMLElement | null>(null)
|
|||
const size = ref({ w: 1200, h: 520 })
|
||||
const aspect = computed(() => Math.round((size.value.w / Math.max(1, size.value.h)) * 10) / 10)
|
||||
const scene = computed(() => buildScene(props.village, aspect.value))
|
||||
const hovered = ref<number | null>(null)
|
||||
|
||||
function measure() {
|
||||
const el = stage.value
|
||||
|
|
@ -37,15 +38,25 @@ onBeforeUnmount(() => observer?.disconnect())
|
|||
|
||||
const name = (b: SceneBuilding) => t(`buildings.${b.type}`)
|
||||
const label = (b: SceneBuilding) => t('village.diorama.label', { name: name(b), level: b.level })
|
||||
const isActive = (id: number) => selected.value === id || hovered.value === id
|
||||
const plotLabel = (p: ScenePlot) => t(p.another ? 'village.diorama.plot_another' : 'village.diorama.plot', { name: t(`buildings.${p.type}`) })
|
||||
|
||||
// Buildings stand still: hovering changes nothing but the cursor and the tooltip.
|
||||
// A click opens the details and marks the ground under it.
|
||||
function toggle(id: number) {
|
||||
plot.value = null
|
||||
selected.value = selected.value === id ? null : id
|
||||
}
|
||||
function pick(type: BuildingType) {
|
||||
selected.value = null
|
||||
plot.value = plot.value === type ? null : type
|
||||
}
|
||||
function clear() {
|
||||
selected.value = null
|
||||
plot.value = null
|
||||
}
|
||||
|
||||
/** 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 pillWidth = (b: SceneBuilding) => (name(b).length * 6.6 + 18) * k.value
|
||||
|
||||
// Badges that would overlap move up above the one in front, nearest buildings first.
|
||||
const badges = computed(() => {
|
||||
|
|
@ -61,8 +72,8 @@ const badges = computed(() => {
|
|||
return placed
|
||||
})
|
||||
|
||||
// Countdowns sit right above what is being built: over the level badge (and its name
|
||||
// tag while that is showing), or over the scaffold of a new building.
|
||||
// Countdowns sit right above what is being built: over the level badge, or over the
|
||||
// scaffold of a new building.
|
||||
// A timer that would cover another timer or a level badge moves up until it is clear.
|
||||
const timers = computed(() => {
|
||||
const K = k.value
|
||||
|
|
@ -74,7 +85,7 @@ const timers = computed(() => {
|
|||
return scene.value.timers
|
||||
.map((tm) => {
|
||||
const badge = tm.buildingId !== null ? badges.value.find((p) => p.b.id === tm.buildingId) : undefined
|
||||
const lift = badge ? (isActive(badge.b.id) ? 52 : 25) : 2
|
||||
const lift = badge ? 25 : 2
|
||||
return { ...tm, x: badge?.x ?? tm.at[0], y: (badge?.y ?? tm.at[1]) - lift * K }
|
||||
})
|
||||
.sort((a, b) => b.y - a.y)
|
||||
|
|
@ -89,26 +100,44 @@ const timers = computed(() => {
|
|||
|
||||
<template>
|
||||
<div ref="scroller" class="h-full w-full overflow-x-auto overflow-y-hidden bg-[#74864a]">
|
||||
<div ref="stage" class="h-full min-w-[760px]">
|
||||
<div ref="stage" class="h-full min-w-[640px]">
|
||||
<svg
|
||||
class="block h-full w-full select-none"
|
||||
:viewBox="scene.viewBox"
|
||||
preserveAspectRatio="xMidYMid slice"
|
||||
role="group"
|
||||
:aria-label="$t('village.diorama.title')"
|
||||
@click="selected = null"
|
||||
@click="clear"
|
||||
>
|
||||
<g stroke-width="0.6" stroke-linejoin="round">
|
||||
<polygon v-for="(p, i) in scene.terrain" :key="`t${i}`" :points="p.points" :fill="p.fill" :stroke="p.stroke" />
|
||||
<polygon v-for="(p, i) in scene.decals" :key="`d${i}`" :points="p.points" :fill="p.fill" :stroke="p.stroke" />
|
||||
</g>
|
||||
|
||||
<!-- Empty plots: nothing to see, but each opens its building type's build card. -->
|
||||
<ellipse
|
||||
v-for="p in scene.plots"
|
||||
:key="p.key"
|
||||
class="plot"
|
||||
:class="{ 'is-selected': plot === p.type }"
|
||||
v-bind="p.ring"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
:aria-label="plotLabel(p)"
|
||||
:aria-pressed="plot === p.type"
|
||||
@click.stop="pick(p.type)"
|
||||
@keydown.enter.prevent="pick(p.type)"
|
||||
@keydown.space.prevent="pick(p.type)"
|
||||
>
|
||||
<title>{{ plotLabel(p) }}</title>
|
||||
</ellipse>
|
||||
|
||||
<template v-for="obj in scene.objects" :key="obj.key">
|
||||
<g
|
||||
v-if="obj.building"
|
||||
v-memo="[obj, isActive(obj.building.id), selected === obj.building.id]"
|
||||
v-memo="[obj, selected === obj.building.id]"
|
||||
class="bld"
|
||||
:class="{ 'is-active': isActive(obj.building.id), 'is-selected': selected === obj.building.id }"
|
||||
:class="{ 'is-selected': selected === obj.building.id }"
|
||||
:role="obj.building.focusable ? 'button' : undefined"
|
||||
:tabindex="obj.building.focusable ? 0 : -1"
|
||||
:aria-hidden="obj.building.focusable ? undefined : 'true'"
|
||||
|
|
@ -119,10 +148,6 @@ const timers = computed(() => {
|
|||
@click.stop="toggle(obj.building.id)"
|
||||
@keydown.enter.prevent="toggle(obj.building.id)"
|
||||
@keydown.space.prevent="toggle(obj.building.id)"
|
||||
@mouseenter="hovered = obj.building.id"
|
||||
@mouseleave="hovered = null"
|
||||
@focus="hovered = obj.building.id"
|
||||
@blur="hovered = null"
|
||||
>
|
||||
<ellipse v-if="obj.building.ring.rx" class="ring" v-bind="obj.building.ring" />
|
||||
<polygon v-for="(p, i) in obj.polys" :key="i" :points="p.points" :fill="p.fill" :stroke="p.stroke" />
|
||||
|
|
@ -134,26 +159,13 @@ const timers = computed(() => {
|
|||
</g>
|
||||
</template>
|
||||
|
||||
<!-- Level badges and, for the hovered or selected building, its name. Flat colours only. -->
|
||||
<!-- Level badges and countdowns. Flat colours only. -->
|
||||
<g class="pointer-events-none" font-family="ui-sans-serif, system-ui, sans-serif" text-anchor="middle">
|
||||
<g v-for="{ b, x, y } in badges" :key="`badge-${b.id}`" :transform="`translate(${x} ${y})`">
|
||||
<g v-if="isActive(b.id)">
|
||||
<rect
|
||||
:x="-pillWidth(b) / 2"
|
||||
:y="-33 * k"
|
||||
:width="pillWidth(b)"
|
||||
:height="20 * k"
|
||||
:rx="3 * k"
|
||||
fill="#2f2013"
|
||||
stroke="#9c7a1f"
|
||||
:stroke-width="1 * k"
|
||||
/>
|
||||
<text :y="-19 * k" :font-size="12 * k" font-weight="600" fill="#f3e7c9">{{ name(b) }}</text>
|
||||
</g>
|
||||
<circle
|
||||
:r="10 * k"
|
||||
:fill="b.upgrading ? '#c49a2c' : '#f3e7c9'"
|
||||
:stroke="isActive(b.id) ? '#7b1e16' : '#57391f'"
|
||||
:stroke="selected === b.id ? '#7b1e16' : '#57391f'"
|
||||
:stroke-width="1.6 * k"
|
||||
/>
|
||||
<text :y="4 * k" :font-size="11 * k" font-weight="700" :fill="b.upgrading ? '#1f150c' : '#2f2013'">{{ b.level }}</text>
|
||||
|
|
@ -176,33 +188,25 @@ const timers = computed(() => {
|
|||
</template>
|
||||
|
||||
<style scoped>
|
||||
.bld {
|
||||
/* Buildings are massive and stay put: no lift, no glow, nothing on hover. Only a click
|
||||
(or keyboard focus) outlines the ground they stand on. */
|
||||
.bld,
|
||||
.plot {
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
transition: transform 0.15s ease;
|
||||
}
|
||||
.bld.is-active {
|
||||
transform: translateY(-3px);
|
||||
}
|
||||
.ring {
|
||||
.ring,
|
||||
.plot {
|
||||
fill: transparent;
|
||||
stroke: transparent;
|
||||
}
|
||||
.bld.is-active .ring {
|
||||
fill: #c4a676;
|
||||
stroke: #9c7a1f;
|
||||
stroke-width: 1.2;
|
||||
}
|
||||
.bld.is-selected .ring {
|
||||
fill: #d9b44a;
|
||||
.bld.is-selected .ring,
|
||||
.plot.is-selected {
|
||||
stroke: #7b1e16;
|
||||
stroke-width: 2;
|
||||
}
|
||||
.bld.is-selected polygon {
|
||||
stroke: #7b1e16;
|
||||
stroke-width: 1;
|
||||
}
|
||||
.bld:focus-visible .ring {
|
||||
.bld:focus-visible .ring,
|
||||
.plot:focus-visible {
|
||||
stroke: #7b1e16;
|
||||
stroke-width: 2;
|
||||
stroke-dasharray: 4 3;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,117 @@
|
|||
<script setup lang="ts">
|
||||
import type { BuildOrder, UnitType, VillageState } from '~/types/game'
|
||||
|
||||
const props = defineProps<{
|
||||
village: VillageState
|
||||
/** The village page path, for the links to its screens. */
|
||||
base: string
|
||||
secondsUntil: (iso: string) => number
|
||||
}>()
|
||||
const { t } = useI18n()
|
||||
|
||||
const production = computed(() => (['wood', 'clay', 'iron', 'food'] as const).map((r) => ({ r, rate: props.village.rates[r] })))
|
||||
const troops = computed(() => (Object.entries(props.village.troops) as [UnitType, number][]).filter(([, n]) => n > 0))
|
||||
const idle = computed(() => props.village.population.villagers - props.village.population.workers - props.village.levy.militia)
|
||||
const spaceShare = computed(() => props.village.space.used / props.village.space.max)
|
||||
|
||||
function order(o: BuildOrder) {
|
||||
const type = t(`buildings.${o.type}`)
|
||||
if (o.action === 'build') return type
|
||||
return `${type} ${o.target_level < 0 ? '×' : `→ ${o.target_level}`}`
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- The column beside the village: small boxes with the numbers that matter at a glance. -->
|
||||
<template>
|
||||
<aside class="space-y-3 bg-parchment-100 p-3 text-sm">
|
||||
<section class="side-box">
|
||||
<h2 class="side-title">{{ $t('village.side.production') }}</h2>
|
||||
<ul class="side-body">
|
||||
<li v-for="{ r, rate } in production" :key="r" class="flex items-center gap-2">
|
||||
<IconResource :resource="r" class="size-4" />
|
||||
<span class="flex-1">{{ $t(`resources.${r}`) }}</span>
|
||||
<span class="font-semibold tabular-nums" :class="rate < 0 ? 'text-blood-700' : ''">
|
||||
{{ $t('village.resources.per_hour', { rate: formatRate(rate) }) }}
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section class="side-box">
|
||||
<h2 class="side-title">{{ $t('village.side.units') }}</h2>
|
||||
<div class="side-body">
|
||||
<ul v-if="troops.length || village.levy.militia">
|
||||
<li v-for="[unit, count] in troops" :key="unit" class="flex items-center gap-2">
|
||||
<IconUnit :unit="unit" class="size-4 text-wood-800" />
|
||||
<span class="font-semibold tabular-nums">{{ count }}</span>
|
||||
<span class="truncate">{{ $t(`units.${unit}`) }}</span>
|
||||
</li>
|
||||
<li v-if="village.levy.militia" class="flex items-center gap-2">
|
||||
<IconUnit unit="militia" class="size-4 text-wood-800" />
|
||||
<span class="font-semibold tabular-nums">{{ village.levy.militia }}</span>
|
||||
<span>{{ $t('village.levy.militia') }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else class="text-ink-500">{{ $t('village.troops.none') }}</p>
|
||||
<p v-if="village.population.training" class="text-xs text-ink-500">{{ $t('village.troops.training', { count: village.population.training }) }}</p>
|
||||
<NuxtLink :to="`${base}/recruit`" class="side-link">» {{ $t('village.side.recruit') }}</NuxtLink>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="side-box">
|
||||
<h2 class="side-title">{{ $t('village.population.title') }}</h2>
|
||||
<dl class="grid grid-cols-[1fr_auto] gap-x-2 gap-y-1 px-2.5 py-1.5">
|
||||
<dt>{{ $t('village.population.villagers') }}</dt>
|
||||
<dd class="text-right font-semibold tabular-nums">{{ village.population.villagers }}</dd>
|
||||
<dt>{{ $t('village.population.workers') }}</dt>
|
||||
<dd class="text-right tabular-nums">{{ village.population.workers }}</dd>
|
||||
<dt>{{ $t('village.population.idle') }}</dt>
|
||||
<dd class="text-right tabular-nums">{{ idle }}</dd>
|
||||
<dt>{{ $t('village.population.upkeep') }}</dt>
|
||||
<dd class="text-right tabular-nums">{{ village.population.upkeep }}/{{ village.population.food_budget }}</dd>
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<section class="side-box">
|
||||
<h2 class="side-title">{{ $t('village.side.construction') }}</h2>
|
||||
<div class="side-body">
|
||||
<ol v-if="village.queue.length">
|
||||
<li v-for="o in village.queue" :key="o.id" class="flex items-center gap-2">
|
||||
<IconBuilding :type="o.type" class="size-4 text-wood-800" />
|
||||
<span class="min-w-0 flex-1 truncate">{{ order(o) }}</span>
|
||||
<span class="tabular-nums" :class="o.finishes_at ? 'font-semibold' : 'text-ink-500'">
|
||||
{{ o.finishes_at ? formatDuration(secondsUntil(o.finishes_at)) : $t('village.queue.waiting') }}
|
||||
</span>
|
||||
</li>
|
||||
</ol>
|
||||
<p v-else class="text-ink-500">{{ $t('village.queue.empty') }}</p>
|
||||
<div class="pt-1">
|
||||
<div class="mb-1 flex justify-between text-xs text-ink-500">
|
||||
<span>{{ $t('village.diorama.space') }}</span>
|
||||
<span class="tabular-nums">{{ village.space.used }}/{{ village.space.max }}</span>
|
||||
</div>
|
||||
<UiBar :value="spaceShare" :tone="spaceShare >= 1 ? 'rose' : 'emerald'" />
|
||||
</div>
|
||||
<NuxtLink :to="`${base}/build`" class="side-link">» {{ $t('village.screens.build') }}</NuxtLink>
|
||||
</div>
|
||||
</section>
|
||||
</aside>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
@reference "~/assets/css/main.css";
|
||||
|
||||
.side-box {
|
||||
@apply rounded-sm border-2 border-wood-700 bg-parchment-50;
|
||||
}
|
||||
.side-title {
|
||||
@apply border-b border-wood-700 bg-parchment-200 px-2.5 py-1 font-display text-sm font-semibold text-wood-900;
|
||||
font-variant: small-caps;
|
||||
}
|
||||
.side-body {
|
||||
@apply space-y-1 px-2.5 py-1.5;
|
||||
}
|
||||
.side-link {
|
||||
@apply block pt-0.5 text-sm font-semibold text-blood-700 hover:underline;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
<script setup lang="ts">
|
||||
import type { BuildOption, BuildingType, Cost, Resources } from '~/types/game'
|
||||
|
||||
const props = defineProps<{
|
||||
option: BuildOption
|
||||
resources: Resources
|
||||
canAfford: (cost: Cost) => boolean
|
||||
busy: boolean
|
||||
/** One of this type already stands; this plot is for another. */
|
||||
another: boolean
|
||||
/** The headquarters screen with every building. */
|
||||
allLink: string
|
||||
}>()
|
||||
const emit = defineEmits<{ build: [type: BuildingType]; close: [] }>()
|
||||
const { t } = useI18n()
|
||||
|
||||
/** Why it can't be built now, or '' when the button shows. */
|
||||
const reason = computed(() => {
|
||||
if (props.option.blocked) return t(`village.blocked.${props.option.blocked}`)
|
||||
if (!props.canAfford(props.option.cost)) return t('village.blocked.resources')
|
||||
return ''
|
||||
})
|
||||
</script>
|
||||
|
||||
<!-- An empty plot picked in the village: what would stand there, and building it. -->
|
||||
<template>
|
||||
<section class="panel" :aria-label="$t(`buildings.${option.type}`)">
|
||||
<div class="flex items-center gap-3 border-b-2 border-wood-700 bg-parchment-200 px-4 py-3">
|
||||
<IconBuildingTile :type="option.type" class="size-11 opacity-70" />
|
||||
<div class="min-w-0 flex-1">
|
||||
<h2 class="truncate font-display text-lg font-semibold text-wood-900" style="font-variant: small-caps">{{ $t(`buildings.${option.type}`) }}</h2>
|
||||
<p class="text-xs text-ink-500">
|
||||
{{ another ? $t('village.plot.another') : $t('village.build.not_built') }}
|
||||
<template v-if="option.space"> · {{ $t('village.build.space', { space: option.space }) }}</template>
|
||||
</p>
|
||||
</div>
|
||||
<button type="button" class="btn btn-ghost p-1.5" :aria-label="$t('common.close')" :title="$t('common.close')" @click="emit('close')">
|
||||
<IconUi name="close" class="size-4" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="space-y-3 px-4 py-3">
|
||||
<div v-if="option.requires.length" class="space-y-1 text-sm">
|
||||
<p class="text-xs text-ink-500">{{ $t('village.build.requires') }}</p>
|
||||
<p v-for="r in option.requires" :key="r.type" class="flex items-center gap-1.5">
|
||||
<IconBuildingTile :type="r.type" class="size-5" />
|
||||
{{ $t('village.build.requirement', { type: $t(`buildings.${r.type}`), level: r.level }) }}
|
||||
</p>
|
||||
</div>
|
||||
<div v-else class="space-y-1.5 rounded-sm border border-wood-600/50 bg-parchment-100 p-3">
|
||||
<div class="flex items-center justify-between gap-2 text-xs text-ink-500">
|
||||
<UiCost :cost="option.cost" :have="resources" />
|
||||
<span class="flex items-center gap-1 tabular-nums">
|
||||
<IconUi name="clock" class="size-3" />
|
||||
{{ formatDuration(option.seconds) }}
|
||||
</span>
|
||||
</div>
|
||||
<button v-if="!reason" type="button" class="btn btn-primary w-full" :disabled="busy" @click="emit('build', option.type)">
|
||||
<IconUi name="hammer" class="size-3.5" />
|
||||
{{ $t('village.build.submit') }}
|
||||
</button>
|
||||
<p v-else class="text-center text-xs font-semibold text-blood-700">{{ reason }}</p>
|
||||
</div>
|
||||
<NuxtLink :to="allLink" class="block text-sm font-semibold text-blood-700 hover:underline">» {{ $t('village.plot.all') }}</NuxtLink>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
|
@ -6,43 +6,26 @@ defineProps<{ village: VillageState; resources: Resources }>()
|
|||
const list: Resource[] = ['wood', 'clay', 'iron', 'food']
|
||||
</script>
|
||||
|
||||
<!-- Projected stock per resource, its rate, and how full storage is. -->
|
||||
<!-- Stock in storage, one line like the Die Stämme header; rates live in the overview's production box. -->
|
||||
<template>
|
||||
<div class="border-b-2 border-wood-700 bg-parchment-200">
|
||||
<div class="grid grid-cols-4 gap-x-3 px-4 py-2 sm:px-6 sm:grid-cols-[repeat(4,minmax(0,1fr))_auto] sm:gap-x-5">
|
||||
<div
|
||||
<div class="flex flex-wrap items-center gap-x-4 gap-y-1 text-sm tabular-nums">
|
||||
<span
|
||||
v-for="r in list"
|
||||
:key="r"
|
||||
class="flex min-w-0 items-center gap-2"
|
||||
:title="`${$t(`resources.${r}`)}, ${$t('village.resources.cap')} ${village.storage_cap}`"
|
||||
class="inline-flex items-center gap-1.5 font-semibold"
|
||||
:class="resources[r] >= village.storage_cap ? 'text-blood-700' : 'text-ink-900'"
|
||||
:title="`${$t(`resources.${r}`)}: ${$t('village.resources.per_hour', { rate: formatRate(village.rates[r]) })}`"
|
||||
>
|
||||
<IconResource :resource="r" class="hidden size-7 sm:block" />
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex flex-wrap items-baseline justify-between gap-x-1">
|
||||
<span class="flex items-center gap-1 font-semibold tabular-nums">
|
||||
<IconResource :resource="r" class="size-4 sm:hidden" />
|
||||
<span class="sr-only">{{ $t(`resources.${r}`) }}</span>
|
||||
<IconResource :resource="r" class="size-5" />
|
||||
{{ formatAmount(resources[r]) }}
|
||||
</span>
|
||||
<span
|
||||
class="text-[11px] tabular-nums sm:text-xs"
|
||||
:class="village.rates[r] < 0 ? 'text-blood-700' : village.rates[r] > 0 ? 'text-moss-700' : 'text-ink-400'"
|
||||
>
|
||||
{{ $t('village.resources.per_hour', { rate: formatRate(village.rates[r]) }) }}
|
||||
<span class="inline-flex items-center gap-1.5 text-ink-700" :title="$t('village.resources.cap')">
|
||||
<IconBuilding type="storage" class="size-4" />
|
||||
{{ village.storage_cap }}
|
||||
</span>
|
||||
<span class="inline-flex items-center gap-1.5 text-ink-700" :title="$t('village.population.villagers')">
|
||||
<IconUi name="users" class="size-4" />
|
||||
{{ village.population.villagers }}
|
||||
</span>
|
||||
</div>
|
||||
<UiBar
|
||||
class="mt-1"
|
||||
:value="resources[r] / village.storage_cap"
|
||||
:tone="resources[r] >= village.storage_cap ? 'rose' : 'amber'"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hidden items-center justify-end gap-1.5 text-xs text-ink-500 sm:flex">
|
||||
<IconBuilding type="storage" class="size-4" />
|
||||
{{ $t('village.resources.cap') }}
|
||||
<span class="font-semibold text-ink-700 tabular-nums">{{ village.storage_cap }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
<script setup lang="ts">
|
||||
import type { Levy, MilitaryBuilding, UnitType } from '~/types/game'
|
||||
import type { Levy, UnitType } from '~/types/game'
|
||||
|
||||
const props = defineProps<{
|
||||
troops: Partial<Record<UnitType, number>>
|
||||
military: MilitaryBuilding[]
|
||||
training: number
|
||||
levy: Levy
|
||||
/** Villagers a new levy can draft. */
|
||||
|
|
@ -11,7 +10,7 @@ const props = defineProps<{
|
|||
secondsUntil: (iso: string) => number
|
||||
busy: boolean
|
||||
}>()
|
||||
const emit = defineEmits<{ recruit: []; levy: [count: number]; endLevy: [] }>()
|
||||
const emit = defineEmits<{ levy: [count: number]; endLevy: [] }>()
|
||||
|
||||
const home = computed(() => (Object.entries(props.troops) as [UnitType, number][]).filter(([, n]) => n > 0))
|
||||
|
||||
|
|
@ -49,10 +48,6 @@ function submitLevy() {
|
|||
</li>
|
||||
</ul>
|
||||
<p v-else class="py-2 text-center text-sm text-ink-500">{{ $t('village.troops.none') }}</p>
|
||||
<button v-if="military.length" type="button" class="btn btn-outline mt-3 w-full" @click="emit('recruit')">
|
||||
{{ $t('village.troops.recruit') }}
|
||||
</button>
|
||||
<p v-else class="mt-1 text-center text-xs text-ink-500">{{ $t('village.troops.hint') }}</p>
|
||||
|
||||
<!-- Levy: draft villagers as militia for a fixed time. -->
|
||||
<div class="mt-4 border-t-2 border-parchment-300 pt-3">
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import type { BuildingType, Cost, Resource, Resources, UnitType, VillageState, VillageUpdated } from '~/types/game'
|
||||
import type { InjectionKey } from 'vue'
|
||||
|
||||
const RESOURCES: Resource[] = ['wood', 'clay', 'iron', 'food']
|
||||
|
||||
|
|
@ -102,3 +103,17 @@ export function useVillage(villageId: number) {
|
|||
endLevy: () => run('village.endLevy'),
|
||||
}
|
||||
}
|
||||
|
||||
export type VillageContext = ReturnType<typeof useVillage>
|
||||
const VILLAGE: InjectionKey<VillageContext> = Symbol('village')
|
||||
|
||||
/** The village page shares its one useVillage() with every screen in it. */
|
||||
export function provideVillage(context: VillageContext) {
|
||||
provide(VILLAGE, context)
|
||||
}
|
||||
|
||||
export function useVillageContext(): VillageContext {
|
||||
const context = inject(VILLAGE)
|
||||
if (!context) throw new Error('useVillageContext() needs the village page around it.')
|
||||
return context
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,6 +62,19 @@ export interface SceneObject {
|
|||
planned?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Ground kept free for a building type that doesn't stand yet: nothing is drawn there,
|
||||
* but the spot opens that type's build card, like the empty plots in Die Stämme.
|
||||
*/
|
||||
export interface ScenePlot {
|
||||
key: string
|
||||
type: BuildingType
|
||||
/** Room for one more of a type that already stands (zone plots). */
|
||||
another: boolean
|
||||
/** Screen ellipse of the plot, the click target. */
|
||||
ring: { cx: number; cy: number; rx: number; ry: number }
|
||||
}
|
||||
|
||||
/** A running build order's countdown, anchored above what it works on. */
|
||||
export interface SceneTimer {
|
||||
orderId: number
|
||||
|
|
@ -80,6 +93,7 @@ export interface Scene {
|
|||
terrain: Poly[]
|
||||
decals: Poly[]
|
||||
objects: SceneObject[]
|
||||
plots: ScenePlot[]
|
||||
timers: SceneTimer[]
|
||||
}
|
||||
|
||||
|
|
@ -315,10 +329,17 @@ export function buildScene(village: VillageState, aspect = 2.2): Scene {
|
|||
const activeZones = ZONE_NAMES.filter((z) => members[z].length)
|
||||
const roads = [FRONT, ...activeZones.map((z) => ZONES[z].angle)]
|
||||
|
||||
// Types with no building and no queued one keep an empty plot: inside the village
|
||||
// after everything that stands, so building there moves nothing that already exists.
|
||||
const present = new Set([...village.buildings.map((b) => b.type), ...village.queue.filter((o) => o.action === 'build').map((o) => o.type)])
|
||||
const unbuilt = village.buildable.filter((o) => !present.has(o.type))
|
||||
const corePlots = unbuilt.filter((o) => o.type !== 'headquarters' && o.type !== 'wall' && !isZone(o.type))
|
||||
|
||||
const coreItems = [
|
||||
{ key: 'well', space: 1.4 },
|
||||
...village.buildings.filter((b) => b.type !== 'headquarters' && b.type !== 'wall' && b.space > 0 && !isZone(b.type)).map((b) => ({ key: `b${b.id}`, space: b.space })),
|
||||
...planned.filter((o) => !isZone(o.type)).map((o) => ({ key: `o${o.id}`, space: o.space })),
|
||||
...corePlots.map((o) => ({ key: `p:${o.type}`, space: Math.max(o.space, 1) })),
|
||||
]
|
||||
const core = layoutCore(coreItems, hqRadius, roads)
|
||||
const Rv = Math.max(U * 5.2, ...core.map((s) => Math.hypot(s.x, s.y) + s.r + U * 0.9))
|
||||
|
|
@ -326,12 +347,22 @@ export function buildScene(village: VillageState, aspect = 2.2): Scene {
|
|||
const zoneSlots: Record<Zone, Slot[]> = { iron: [], clay: [], timber: [], farm: [] }
|
||||
for (const zone of ZONE_NAMES) {
|
||||
const space = members[zone][0]?.space ?? 4
|
||||
// Show at least two plots of each zone's ground, built on or not.
|
||||
const slots = layoutZone(zone, space, Math.max(members[zone].length, 2), Rv)
|
||||
// Each zone shows one free plot of its ground past its buildings, two when empty.
|
||||
const slots = layoutZone(zone, space, Math.max(members[zone].length + 1, 2), Rv)
|
||||
members[zone].forEach((m, i) => (slots[i]!.key = m.key))
|
||||
zoneSlots[zone] = slots
|
||||
}
|
||||
const allSlots = [...core, ...ZONE_NAMES.flatMap((z) => zoneSlots[z].slice(0, members[z].length))]
|
||||
const allSlots = [...core, ...ZONE_NAMES.flatMap((z) => zoneSlots[z])]
|
||||
|
||||
const plots: ScenePlot[] = corePlots.map((o) => {
|
||||
const s = core.find((c) => c.key === `p:${o.type}`)!
|
||||
return { key: `p:${o.type}`, type: o.type, another: false, ring: screenRing(s.x, s.y, s.r) }
|
||||
})
|
||||
for (const zone of ZONE_NAMES) {
|
||||
const type = (Object.keys(ZONE_OF) as BuildingType[]).find((t) => ZONE_OF[t] === zone)!
|
||||
const free = zoneSlots[zone][members[zone].length]
|
||||
if (free && village.buildable.some((o) => o.type === type)) plots.push({ key: `p:${type}`, type, another: present.has(type), ring: screenRing(free.x, free.y, free.r) })
|
||||
}
|
||||
const slotOf = (key: string) => allSlots.find((s) => s.key === key)!
|
||||
const zoneEnd = (zone: Zone) => Math.max(Rv + U * 3, ...zoneSlots[zone].map((s) => Math.hypot(s.x, s.y) + s.r))
|
||||
|
||||
|
|
@ -398,6 +429,12 @@ export function buildScene(village: VillageState, aspect = 2.2): Scene {
|
|||
})
|
||||
}
|
||||
|
||||
// Without a wall, its plot is the stretch of village edge where its badge would sit.
|
||||
if (!wall && !wallPlanned && unbuilt.some((o) => o.type === 'wall')) {
|
||||
const gateSide = FRONT + deg(24)
|
||||
plots.push({ key: 'p:wall', type: 'wall', another: false, ring: screenRing(Math.cos(gateSide) * Rv, Math.sin(gateSide) * Rv, U * 0.9) })
|
||||
}
|
||||
|
||||
// The frame: the village and every zone, with room for labels; then widened or
|
||||
// heightened to the container's shape, where more land and forest show.
|
||||
const Rz = Math.max(Rv + U * 4.5, ...ZONE_NAMES.map(zoneEnd))
|
||||
|
|
@ -526,6 +563,7 @@ export function buildScene(village: VillageState, aspect = 2.2): Scene {
|
|||
// One at a time, so the layers keep the order they were added in.
|
||||
decals: decalFaces.flatMap((face) => toPolys([face])),
|
||||
objects: objects.map(({ key, polys, building, planned }) => ({ key, polys, building, planned })),
|
||||
plots,
|
||||
timers,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,160 +1,74 @@
|
|||
<script setup lang="ts">
|
||||
const route = useRoute()
|
||||
const v = useVillage(Number(route.params.id))
|
||||
const { village, resources, error, busy } = v
|
||||
|
||||
/** Building selected in the diorama, by id; dropped when the building is gone. */
|
||||
const selected = ref<number | null>(null)
|
||||
const selectedBuilding = computed(() => village.value?.buildings.find((b) => b.id === selected.value) ?? null)
|
||||
watch(selectedBuilding, (b) => {
|
||||
if (!b) selected.value = null
|
||||
})
|
||||
|
||||
const spaceShare = computed(() => (village.value ? village.value.space.used / village.value.space.max : 0))
|
||||
const id = Number(route.params.id)
|
||||
const v = useVillage(id)
|
||||
const { village, resources, error } = v
|
||||
provideVillage(v)
|
||||
|
||||
const { enter } = useCurrentWorld()
|
||||
watch(village, (v) => {
|
||||
if (v) enter(v.world_id, v.id)
|
||||
watch(village, (state) => {
|
||||
if (state) enter(state.world_id, state.id)
|
||||
})
|
||||
|
||||
v.refresh()
|
||||
|
||||
function showInVillage(id: number) {
|
||||
selected.value = id
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}
|
||||
|
||||
/** Military building whose recruit tab is open. */
|
||||
const recruitAt = ref<number | null>(null)
|
||||
const trains = (buildingId: number) => !!village.value?.military.some((m) => m.building_id === buildingId)
|
||||
|
||||
function openRecruit(buildingId?: number) {
|
||||
if (buildingId !== undefined) recruitAt.value = buildingId
|
||||
nextTick(() => document.getElementById('recruit')?.scrollIntoView({ behavior: 'smooth', block: 'start' }))
|
||||
}
|
||||
// The screens of a village, like the building links along the top in Die Stämme.
|
||||
const screens = [
|
||||
{ name: 'overview', path: '', icon: 'headquarters' },
|
||||
{ name: 'build', path: '/build', icon: 'storage' },
|
||||
{ name: 'recruit', path: '/recruit', icon: 'barracks' },
|
||||
{ name: 'workforce', path: '/workforce', icon: 'farm' },
|
||||
] as const
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="village && resources">
|
||||
<VillageResourceBar class="sticky top-0 z-30" :village="village" :resources="resources" />
|
||||
|
||||
<section class="border-b-2 border-wood-700">
|
||||
<!-- Village header: a flat parchment strip above the land, so nothing covers the view. -->
|
||||
<div class="flex flex-wrap items-center gap-x-6 gap-y-2 border-b-2 border-wood-700 bg-parchment-200 px-4 py-2.5 sm:px-6">
|
||||
<div class="min-w-0">
|
||||
<p class="text-xs font-semibold tracking-wide text-ink-500 uppercase">{{ $t('village.title') }}</p>
|
||||
<h1 class="truncate font-display text-xl font-semibold text-wood-900 sm:text-2xl" style="font-variant: small-caps">
|
||||
{{ village.name }}
|
||||
</h1>
|
||||
</div>
|
||||
<header class="sticky top-0 z-30 border-b-2 border-wood-700 bg-parchment-200">
|
||||
<div class="flex flex-wrap items-center gap-x-5 gap-y-2 px-4 py-2 sm:px-6">
|
||||
<div class="flex min-w-0 items-baseline gap-2">
|
||||
<h1 class="truncate font-display text-lg font-semibold text-wood-900" style="font-variant: small-caps">{{ village.name }}</h1>
|
||||
<NuxtLink
|
||||
:to="{ path: `/map/${village.world_id}`, query: { x: village.x, y: village.y } }"
|
||||
class="inline-flex items-center gap-1 rounded-sm border border-wood-600/50 bg-parchment-50 px-2 py-1 text-sm text-ink-700 hover:border-blood-700 hover:text-blood-700"
|
||||
class="text-sm whitespace-nowrap text-ink-700 tabular-nums hover:text-blood-700 hover:underline"
|
||||
:title="$t('village.on_map')"
|
||||
>
|
||||
<IconUi name="pin" class="size-3.5" />
|
||||
<span class="font-semibold tabular-nums">{{ village.x }}|{{ village.y }}</span>
|
||||
<span class="text-ink-500">· {{ village.continent }} · {{ $t('village.points', { points: village.points }) }}</span>
|
||||
({{ village.x }}|{{ village.y }}) {{ village.continent }}
|
||||
</NuxtLink>
|
||||
<div class="w-full sm:ml-auto sm:w-64">
|
||||
<div class="mb-1 flex justify-between gap-3 text-xs">
|
||||
<span class="font-semibold text-ink-700">{{ $t('village.diorama.space') }}</span>
|
||||
<span class="font-semibold tabular-nums">
|
||||
{{ $t('village.diorama.space_value', { used: village.space.used, max: village.space.max }) }}
|
||||
</span>
|
||||
<span class="hidden text-xs whitespace-nowrap text-ink-500 sm:inline">{{ $t('village.points', { points: village.points }) }}</span>
|
||||
</div>
|
||||
<UiBar :value="spaceShare" :tone="spaceShare >= 1 ? 'rose' : 'emerald'" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<VillageFoodWarning :starvation="village.starvation" :levy="village.levy" :seconds-until="v.secondsUntil" />
|
||||
|
||||
<div class="relative">
|
||||
<div class="h-[clamp(260px,82vw,460px)] sm:h-[clamp(340px,62vh,760px)]">
|
||||
<VillageDiorama v-model:selected="selected" :village="village" :seconds-until="v.secondsUntil" />
|
||||
</div>
|
||||
|
||||
<p
|
||||
class="pointer-events-none absolute bottom-3 left-1/2 hidden -translate-x-1/2 rounded-sm border border-wood-700 bg-parchment-50 px-3 py-1 text-xs text-ink-700 sm:block"
|
||||
<nav class="flex items-center gap-0.5" :aria-label="$t('village.screens.label')">
|
||||
<NuxtLink
|
||||
v-for="s in screens"
|
||||
:key="s.name"
|
||||
:to="`/village/${id}${s.path}`"
|
||||
class="screen-link"
|
||||
:class="{ 'screen-link-active': route.path === `/village/${id}${s.path}` }"
|
||||
>
|
||||
{{ $t('village.diorama.hint') }}
|
||||
</p>
|
||||
<IconBuilding :type="s.icon" class="size-4" />
|
||||
<span :class="s.name === 'overview' ? 'hidden sm:inline' : ''">{{ $t(`village.screens.${s.name}`) }}</span>
|
||||
</NuxtLink>
|
||||
</nav>
|
||||
<VillageResourceBar class="lg:ml-auto" :village="village" :resources="resources" />
|
||||
</div>
|
||||
<VillageFoodWarning :starvation="village.starvation" :levy="village.levy" :seconds-until="v.secondsUntil" />
|
||||
</header>
|
||||
|
||||
<VillageBuildingCard
|
||||
v-if="selectedBuilding"
|
||||
class="mx-4 my-4 lg:absolute lg:top-4 lg:right-6 lg:z-10 lg:m-0 lg:w-80"
|
||||
:building="selectedBuilding"
|
||||
:resources="resources"
|
||||
:can-afford="v.canAfford"
|
||||
:busy="busy"
|
||||
:trains="trains(selectedBuilding.id)"
|
||||
@upgrade="v.upgrade"
|
||||
@demolish="v.demolish"
|
||||
@priority="v.setPriority"
|
||||
@recruit="openRecruit"
|
||||
@close="selected = null"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="space-y-6 px-4 py-6 sm:px-6">
|
||||
<p v-if="error" class="alert" role="alert">{{ error }}</p>
|
||||
|
||||
<div class="grid gap-6 lg:grid-cols-[minmax(0,1fr)_22rem] 2xl:grid-cols-[minmax(0,1fr)_26rem]">
|
||||
<div class="min-w-0 space-y-6">
|
||||
<VillageBuildForm
|
||||
:options="village.buildable"
|
||||
:buildings="village.buildings"
|
||||
:space="village.space"
|
||||
:resources="resources"
|
||||
:can-afford="v.canAfford"
|
||||
:busy="busy"
|
||||
@build="v.build"
|
||||
@upgrade="v.upgrade"
|
||||
@demolish="v.demolish"
|
||||
@select="showInVillage"
|
||||
/>
|
||||
<VillageRecruit
|
||||
v-model:selected="recruitAt"
|
||||
:military="village.military"
|
||||
:troops="village.troops"
|
||||
:villagers="village.population.villagers - village.levy.militia"
|
||||
:resources="resources"
|
||||
:seconds-until="v.secondsUntil"
|
||||
:busy="busy"
|
||||
:recruit="v.recruit"
|
||||
@cancel="v.cancelRecruit"
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-6">
|
||||
<VillageBuildQueue
|
||||
:queue="village.queue"
|
||||
:builders="village.builders"
|
||||
:seconds-until="v.secondsUntil"
|
||||
:busy="busy"
|
||||
@cancel="v.cancel"
|
||||
/>
|
||||
<VillagePopulationPanel :population="village.population" :militia="village.levy.militia" />
|
||||
<VillageTroopsPanel
|
||||
:troops="village.troops"
|
||||
:military="village.military"
|
||||
:training="village.population.training"
|
||||
:levy="village.levy"
|
||||
:villagers="village.population.villagers"
|
||||
:seconds-until="v.secondsUntil"
|
||||
:busy="busy"
|
||||
@recruit="openRecruit()"
|
||||
@levy="v.levy"
|
||||
@end-levy="v.endLevy"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<VillageBuildingTable :buildings="village.buildings" :busy="busy" @select="showInVillage" @priority="v.setPriority" />
|
||||
</div>
|
||||
<p v-if="error" class="alert mx-4 mt-3 sm:mx-6" role="alert">{{ error }}</p>
|
||||
<NuxtPage />
|
||||
</div>
|
||||
<div v-else class="px-4 py-16 text-center">
|
||||
<p v-if="error" class="alert inline-block" role="alert">{{ error }}</p>
|
||||
<p v-else class="text-sm text-ink-500">{{ $t('common.loading') }}</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
@reference "~/assets/css/main.css";
|
||||
|
||||
.screen-link {
|
||||
@apply inline-flex items-center gap-1.5 rounded-sm border border-transparent px-2 py-1 text-sm font-semibold text-wood-900 hover:border-wood-600;
|
||||
}
|
||||
.screen-link-active {
|
||||
@apply border-wood-700 bg-parchment-50 text-blood-700;
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
<script setup lang="ts">
|
||||
const route = useRoute()
|
||||
const v = useVillageContext()
|
||||
const village = computed(() => v.village.value!)
|
||||
const resources = computed(() => v.resources.value!)
|
||||
|
||||
/** Show a building in the village overview, with its card open. */
|
||||
const showInVillage = (id: number) => navigateTo({ path: `/village/${route.params.id}`, query: { b: id } })
|
||||
</script>
|
||||
|
||||
<!-- The headquarters screen: every building to construct, upgrade or tear down, and the queue. -->
|
||||
<template>
|
||||
<div class="grid gap-6 px-4 py-6 sm:px-6 lg:grid-cols-[minmax(0,1fr)_22rem] 2xl:grid-cols-[minmax(0,1fr)_26rem]">
|
||||
<VillageBuildForm
|
||||
:options="village.buildable"
|
||||
:buildings="village.buildings"
|
||||
:space="village.space"
|
||||
:resources="resources"
|
||||
:can-afford="v.canAfford"
|
||||
:busy="v.busy.value"
|
||||
@build="v.build"
|
||||
@upgrade="v.upgrade"
|
||||
@demolish="v.demolish"
|
||||
@select="showInVillage"
|
||||
/>
|
||||
<VillageBuildQueue
|
||||
:queue="village.queue"
|
||||
:builders="village.builders"
|
||||
:seconds-until="v.secondsUntil"
|
||||
:busy="v.busy.value"
|
||||
@cancel="v.cancel"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
<script setup lang="ts">
|
||||
import type { BuildingType } from '~/types/game'
|
||||
|
||||
const route = useRoute()
|
||||
const v = useVillageContext()
|
||||
const village = computed(() => v.village.value!)
|
||||
const resources = computed(() => v.resources.value!)
|
||||
const base = `/village/${route.params.id}`
|
||||
const { t } = useI18n()
|
||||
|
||||
/** Building picked in the village (by id), or an empty plot (by type); `?b=` opens one. */
|
||||
const selected = ref<number | null>(Number(route.query.b) || null)
|
||||
const plot = ref<BuildingType | null>(null)
|
||||
const selectedBuilding = computed(() => village.value.buildings.find((b) => b.id === selected.value) ?? null)
|
||||
const plotOption = computed(() => village.value.buildable.find((o) => o.type === plot.value) ?? null)
|
||||
watch(selectedBuilding, (b) => {
|
||||
if (!b) selected.value = null
|
||||
})
|
||||
|
||||
/** Where the card of the selected building leads: its own screen, if it has one. */
|
||||
const screenLink = computed(() => {
|
||||
const b = selectedBuilding.value
|
||||
if (!b) return null
|
||||
if (b.type === 'headquarters') return { to: `${base}/build`, label: t('village.screens.build') }
|
||||
if (village.value.military.some((m) => m.building_id === b.id)) {
|
||||
return { to: { path: `${base}/recruit`, query: { at: b.id } }, label: t('village.buildings.recruit') }
|
||||
}
|
||||
return null
|
||||
})
|
||||
|
||||
async function build(type: BuildingType) {
|
||||
await v.build(type)
|
||||
if (!v.error.value) plot.value = null
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- The village overview, laid out like Die Stämme's: the village, and a narrow column beside it. -->
|
||||
<template>
|
||||
<div class="lg:grid lg:grid-cols-[minmax(0,1fr)_17rem] xl:grid-cols-[minmax(0,1fr)_19rem]">
|
||||
<div class="relative">
|
||||
<div class="h-[clamp(260px,82vw,460px)] sm:h-[clamp(380px,calc(100dvh-9rem),880px)]">
|
||||
<VillageDiorama v-model:selected="selected" v-model:plot="plot" :village="village" :seconds-until="v.secondsUntil" />
|
||||
</div>
|
||||
|
||||
<VillageBuildingCard
|
||||
v-if="selectedBuilding"
|
||||
class="mx-4 my-4 lg:absolute lg:top-4 lg:right-4 lg:z-10 lg:m-0 lg:w-80"
|
||||
:building="selectedBuilding"
|
||||
:resources="resources"
|
||||
:can-afford="v.canAfford"
|
||||
:busy="v.busy.value"
|
||||
:link="screenLink"
|
||||
@upgrade="v.upgrade"
|
||||
@demolish="v.demolish"
|
||||
@priority="v.setPriority"
|
||||
@close="selected = null"
|
||||
/>
|
||||
<VillagePlotCard
|
||||
v-else-if="plotOption"
|
||||
class="mx-4 my-4 lg:absolute lg:top-4 lg:right-4 lg:z-10 lg:m-0 lg:w-80"
|
||||
:option="plotOption"
|
||||
:resources="resources"
|
||||
:can-afford="v.canAfford"
|
||||
:busy="v.busy.value"
|
||||
:another="village.buildings.some((b) => b.type === plotOption!.type)"
|
||||
:all-link="`${base}/build`"
|
||||
@build="build"
|
||||
@close="plot = null"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<VillageOverviewSidebar
|
||||
class="border-t-2 border-wood-700 lg:border-t-0 lg:border-l-2"
|
||||
:village="village"
|
||||
:base="base"
|
||||
:seconds-until="v.secondsUntil"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<script setup lang="ts">
|
||||
const route = useRoute()
|
||||
const v = useVillageContext()
|
||||
const village = computed(() => v.village.value!)
|
||||
const resources = computed(() => v.resources.value!)
|
||||
|
||||
/** Military building whose tab is open; `?at=` picks one. */
|
||||
const recruitAt = ref<number | null>(Number(route.query.at) || null)
|
||||
watch(
|
||||
() => route.query.at,
|
||||
(at) => (recruitAt.value = Number(at) || recruitAt.value),
|
||||
)
|
||||
</script>
|
||||
|
||||
<!-- Recruiting at every military building, the troops at home and the levy. -->
|
||||
<template>
|
||||
<div class="grid gap-6 px-4 py-6 sm:px-6 lg:grid-cols-[minmax(0,1fr)_22rem] 2xl:grid-cols-[minmax(0,1fr)_26rem]">
|
||||
<VillageRecruit
|
||||
v-if="village.military.length"
|
||||
v-model:selected="recruitAt"
|
||||
:military="village.military"
|
||||
:troops="village.troops"
|
||||
:villagers="village.population.villagers - village.levy.militia"
|
||||
:resources="resources"
|
||||
:seconds-until="v.secondsUntil"
|
||||
:busy="v.busy.value"
|
||||
:recruit="v.recruit"
|
||||
@cancel="v.cancelRecruit"
|
||||
/>
|
||||
<section v-else class="panel">
|
||||
<div class="panel-body py-8 text-center text-sm text-ink-500">{{ $t('village.troops.hint') }}</div>
|
||||
</section>
|
||||
<VillageTroopsPanel
|
||||
:troops="village.troops"
|
||||
:training="village.population.training"
|
||||
:levy="village.levy"
|
||||
:villagers="village.population.villagers"
|
||||
:seconds-until="v.secondsUntil"
|
||||
:busy="v.busy.value"
|
||||
@levy="v.levy"
|
||||
@end-levy="v.endLevy"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<script setup lang="ts">
|
||||
const route = useRoute()
|
||||
const v = useVillageContext()
|
||||
const village = computed(() => v.village.value!)
|
||||
|
||||
const showInVillage = (id: number) => navigateTo({ path: `/village/${route.params.id}`, query: { b: id } })
|
||||
</script>
|
||||
|
||||
<!-- Who works where: staffing and priorities per building, and the population behind it. -->
|
||||
<template>
|
||||
<div class="grid gap-6 px-4 py-6 sm:px-6 lg:grid-cols-[minmax(0,1fr)_22rem] 2xl:grid-cols-[minmax(0,1fr)_26rem]">
|
||||
<VillageBuildingTable :buildings="village.buildings" :busy="v.busy.value" @select="showInVillage" @priority="v.setPriority" />
|
||||
<VillagePopulationPanel :population="village.population" :militia="village.levy.militia" />
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -5,6 +5,23 @@ export default {
|
|||
village: {
|
||||
title: 'Village',
|
||||
on_map: 'Show on the world map',
|
||||
screens: {
|
||||
label: 'Village screens',
|
||||
overview: 'Overview',
|
||||
build: 'Headquarters',
|
||||
recruit: 'Recruit',
|
||||
workforce: 'Workforce',
|
||||
},
|
||||
side: {
|
||||
production: 'Production',
|
||||
units: 'Units',
|
||||
construction: 'Construction',
|
||||
recruit: 'Recruit',
|
||||
},
|
||||
plot: {
|
||||
all: 'All buildings in the headquarters',
|
||||
another: 'Room for another',
|
||||
},
|
||||
points: '{points} points',
|
||||
resources: {
|
||||
title: 'Resources',
|
||||
|
|
@ -83,9 +100,10 @@ export default {
|
|||
},
|
||||
diorama: {
|
||||
title: 'Village overview',
|
||||
hint: 'Select a building to see what it does and upgrade it.',
|
||||
label: '{name}, level {level}',
|
||||
planned: 'Under construction',
|
||||
plot: '{name}: not built yet',
|
||||
plot_another: '{name}: room for another',
|
||||
space: 'Building space',
|
||||
space_value: '{used} / {max}',
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue