From 2fa5314b7d00a56e15d4d29762cb6f08b6d7dd7d Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Wed, 28 Oct 2026 19:04:21 +0100 Subject: [PATCH] feat: styled village view with resource bar, tile grid and build cards Co-Authored-By: Claude Opus 5.5 --- app/components/village/BuildForm.vue | 98 ++++++++----- app/components/village/BuildQueue.vue | 78 ++++++---- app/components/village/BuildingTable.vue | 138 ++++++++++++------ app/components/village/Grid.vue | 160 ++++++++++++--------- app/components/village/PopulationPanel.vue | 77 ++++++---- app/components/village/ResourceBar.vue | 58 +++++--- app/pages/village/[id].vue | 87 +++++++---- i18n/pages/village.ts | 10 +- 8 files changed, 449 insertions(+), 257 deletions(-) diff --git a/app/components/village/BuildForm.vue b/app/components/village/BuildForm.vue index b3e2489..55192cf 100644 --- a/app/components/village/BuildForm.vue +++ b/app/components/village/BuildForm.vue @@ -1,13 +1,14 @@ diff --git a/app/components/village/BuildQueue.vue b/app/components/village/BuildQueue.vue index fa743ef..5c31093 100644 --- a/app/components/village/BuildQueue.vue +++ b/app/components/village/BuildQueue.vue @@ -1,7 +1,7 @@ diff --git a/app/components/village/BuildingTable.vue b/app/components/village/BuildingTable.vue index 8e0c830..112f003 100644 --- a/app/components/village/BuildingTable.vue +++ b/app/components/village/BuildingTable.vue @@ -1,8 +1,9 @@ diff --git a/app/components/village/Grid.vue b/app/components/village/Grid.vue index e6d9794..101ffd9 100644 --- a/app/components/village/Grid.vue +++ b/app/components/village/Grid.vue @@ -3,39 +3,52 @@ import type { BuildingType, VillageState } from '~/types/game' const props = defineProps<{ village: VillageState }>() const selected = defineModel<{ x: number; y: number } | null>('selected', { default: null }) +const { t } = useI18n() -interface Item { +interface Tile { key: string type: BuildingType level: number + x: number + y: number w: number h: number planned: boolean } -type Cell = { key: string; item: Item } | { key: string; item: null; x: number; y: number } -// A plain table: each building is one cell spanning its footprint, queued new buildings -// show as planned, and the remaining cells can be picked as the next build position. -const rows = computed(() => { - const { w, h } = props.village.grid - const slots: (Item | 'covered' | null)[][] = Array.from({ length: h }, () => Array(w).fill(null)) - const items = [ - ...props.village.buildings.map((b) => ({ ...b, key: `b${b.id}`, planned: false })), - ...props.village.queue - .filter((o) => o.action === 'build') - .map((o) => ({ ...o, key: `o${o.id}`, level: 0, planned: true })), - ] - for (const it of items) { - const [fw, fh] = it.footprint - if (fw === 0 || fh === 0) continue - for (let dy = 0; dy < fh; dy++) for (let dx = 0; dx < fw; dx++) slots[it.y + dy]![it.x + dx] = 'covered' - slots[it.y]![it.x] = { key: it.key, type: it.type, level: it.level, w: fw, h: fh, planned: it.planned } - } - return slots.map((row, y) => - row.flatMap((slot, x): Cell[] => - slot === 'covered' ? [] : slot ? [{ key: slot.key, item: slot }] : [{ key: `${x},${y}`, item: null, x, y }], - ), - ) +// Buildings and queued new buildings as tiles spanning their footprint. The wall takes +// no cells; it shows as the frame around the grid instead. +const tiles = computed(() => [ + ...props.village.buildings.map((b) => ({ ...b, key: `b${b.id}`, planned: false })), + ...props.village.queue + .filter((o) => o.action === 'build') + .map((o) => ({ ...o, key: `o${o.id}`, level: 0, planned: true })), +].flatMap((it) => { + const [w, h] = it.footprint + return w && h ? [{ key: it.key, type: it.type, level: it.level, x: it.x, y: it.y, w, h, planned: it.planned }] : [] +})) + +const freeCells = computed(() => { + const taken = new Set() + for (const t of tiles.value) + for (let dy = 0; dy < t.h; dy++) for (let dx = 0; dx < t.w; dx++) taken.add(`${t.x + dx},${t.y + dy}`) + const cells: { x: number; y: number }[] = [] + for (let y = 0; y < props.village.grid.h; y++) + for (let x = 0; x < props.village.grid.w; x++) if (!taken.has(`${x},${y}`)) cells.push({ x, y }) + return cells +}) + +const hasWall = computed(() => props.village.buildings.some((b) => b.type === 'wall')) + +const gridStyle = computed(() => ({ + gridTemplateColumns: `repeat(${props.village.grid.w}, minmax(0, 1fr))`, + gridTemplateRows: `repeat(${props.village.grid.h}, minmax(0, 1fr))`, + aspectRatio: `${props.village.grid.w} / ${props.village.grid.h}`, +})) + +const place = (x: number, y: number, w = 1, h = 1) => ({ + gridColumn: `${x + 1} / span ${w}`, + gridRow: `${y + 1} / span ${h}`, }) const isSelected = (x: number, y: number) => selected.value?.x === x && selected.value?.y === y @@ -43,50 +56,65 @@ const isSelected = (x: number, y: number) => selected.value?.x === x && selected function toggle(x: number, y: number) { selected.value = isSelected(x, y) ? null : { x, y } } + +function tileTitle(tile: Tile) { + const name = t(`buildings.${tile.type}`) + return tile.planned ? `${name} (${t('village.grid.planned')})` : `${name}, ${t('village.buildings.level_n', { level: tile.level })}` +} - - diff --git a/app/components/village/PopulationPanel.vue b/app/components/village/PopulationPanel.vue index e8daa2c..264a440 100644 --- a/app/components/village/PopulationPanel.vue +++ b/app/components/village/PopulationPanel.vue @@ -1,39 +1,54 @@ diff --git a/app/components/village/ResourceBar.vue b/app/components/village/ResourceBar.vue index 458a2c4..8bbca69 100644 --- a/app/components/village/ResourceBar.vue +++ b/app/components/village/ResourceBar.vue @@ -6,25 +6,43 @@ defineProps<{ village: VillageState; resources: Resources }>() const list: Resource[] = ['wood', 'clay', 'iron', 'food'] + diff --git a/app/pages/village/[id].vue b/app/pages/village/[id].vue index 8e38f89..440b2a8 100644 --- a/app/pages/village/[id].vue +++ b/app/pages/village/[id].vue @@ -17,36 +17,61 @@ async function build(type: BuildingType) { diff --git a/i18n/pages/village.ts b/i18n/pages/village.ts index 3f7efc5..bf392eb 100644 --- a/i18n/pages/village.ts +++ b/i18n/pages/village.ts @@ -3,6 +3,7 @@ import type { TranslationFile } from '@blax-software/i18n' export default { en: { village: { + title: 'Village', resources: { title: 'Resources', cap: 'Storage cap', @@ -16,6 +17,7 @@ export default { workers: 'Working', idle: 'Idle', soldiers: 'Soldiers', + workforce: 'Villagers at work', food_per_hour: '{value} food/h', }, buildings: { @@ -29,14 +31,18 @@ export default { output: 'Output', priority: 'Priority', actions: 'Actions', + level_n: 'Level {level}', + priority_down: 'Lower priority', + priority_up: 'Raise priority', upgrade: 'Upgrade to {level}', demolish: 'Demolish', - refund: 'refund', + refund: 'Refund', }, grid: { title: 'Village grid', hint: 'Click a free cell to choose where the next building goes.', planned: 'planned', + free_cell: 'Free cell', }, build: { title: 'New building', @@ -48,6 +54,7 @@ export default { position: 'Position', auto: 'First free slot', at_cell: 'Selected cell', + surrounds: 'Around the village', submit: 'Build', }, queue: { @@ -56,6 +63,7 @@ export default { empty: 'Nothing queued.', order: 'Order', builder: 'Builder', + builder_n: 'Builder {n}', remaining: 'Done in', waiting: 'Waiting', cancel: 'Cancel',