feat: full-width village page around the diorama, no tiles or cell picking

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-28 19:54:29 +01:00
parent c7322c51db
commit 6bc2d44419
7 changed files with 97 additions and 75 deletions

View File

@ -24,7 +24,7 @@ useHead({ title: () => t('app.title') })
<template> <template>
<div class="min-h-dvh"> <div class="min-h-dvh">
<header class="border-b border-parchment-300/70 bg-parchment-50/90"> <header class="border-b border-parchment-300/70 bg-parchment-50/90">
<div class="mx-auto flex max-w-6xl items-center gap-2 px-4 py-2.5 sm:gap-3"> <div class="flex items-center gap-2 px-4 py-2.5 sm:gap-3 sm:px-6">
<NuxtLink to="/" class="flex min-w-0 items-center gap-2"> <NuxtLink to="/" class="flex min-w-0 items-center gap-2">
<span class="grid size-8 shrink-0 place-items-center rounded-lg bg-amber-700 text-amber-50 shadow-sm"> <span class="grid size-8 shrink-0 place-items-center rounded-lg bg-amber-700 text-amber-50 shadow-sm">
<IconBuilding type="headquarters" class="size-5" /> <IconBuilding type="headquarters" class="size-5" />

View File

@ -3,12 +3,12 @@ import type { BuildOption, BuildingType, Cost, Resources } from '~/types/game'
const props = defineProps<{ const props = defineProps<{
options: BuildOption[] options: BuildOption[]
selected: { x: number; y: number } | null space: { used: number; max: number }
resources: Resources resources: Resources
canAfford: (cost: Cost) => boolean canAfford: (cost: Cost) => boolean
busy: boolean busy: boolean
}>() }>()
const emit = defineEmits<{ build: [type: BuildingType]; clear: [] }>() const emit = defineEmits<{ build: [type: BuildingType] }>()
const { t } = useI18n() const { t } = useI18n()
function status(o: BuildOption) { function status(o: BuildOption) {
@ -22,27 +22,11 @@ function status(o: BuildOption) {
<section class="panel"> <section class="panel">
<div class="panel-head"> <div class="panel-head">
<h2 class="panel-title">{{ $t('village.build.title') }}</h2> <h2 class="panel-title">{{ $t('village.build.title') }}</h2>
<div class="flex items-center gap-1.5 text-sm"> <span class="badge bg-parchment-200 text-ink-700">
<span class="text-ink-500">{{ $t('village.build.position') }}</span> {{ $t('village.build.free_space', { free: space.max - space.used }) }}
<template v-if="selected">
<span class="badge bg-amber-100 text-amber-800">
<IconUi name="pin" class="size-3.5" />
{{ selected.x }}|{{ selected.y }}
</span> </span>
<button
type="button"
class="btn btn-ghost p-1"
:title="$t('common.clear')"
:aria-label="$t('common.clear')"
@click="emit('clear')"
>
<IconUi name="close" class="size-3.5" />
</button>
</template>
<span v-else class="badge bg-parchment-200 text-ink-700">{{ $t('village.build.auto') }}</span>
</div> </div>
</div> <div class="panel-body grid gap-3 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
<div class="panel-body grid gap-3 sm:grid-cols-2 xl:grid-cols-3">
<article <article
v-for="o in options" v-for="o in options"
:key="o.type" :key="o.type"
@ -55,7 +39,7 @@ function status(o: BuildOption) {
<h3 class="truncate font-medium">{{ $t(`buildings.${o.type}`) }}</h3> <h3 class="truncate font-medium">{{ $t(`buildings.${o.type}`) }}</h3>
<p class="flex flex-wrap items-center gap-x-1.5 text-xs text-ink-500"> <p class="flex flex-wrap items-center gap-x-1.5 text-xs text-ink-500">
<span class="whitespace-nowrap"> <span class="whitespace-nowrap">
{{ o.footprint[0] ? `${o.footprint[0]}×${o.footprint[1]}` : $t('village.build.surrounds') }} {{ o.space ? $t('village.build.space', { space: o.space }) : $t('village.build.surrounds') }}
</span> </span>
<span class="flex items-center gap-1 whitespace-nowrap tabular-nums"> <span class="flex items-center gap-1 whitespace-nowrap tabular-nums">
<IconUi name="clock" class="size-3" /> <IconUi name="clock" class="size-3" />

View File

@ -8,6 +8,7 @@ defineProps<{
busy: boolean busy: boolean
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{
select: [buildingId: number]
upgrade: [buildingId: number] upgrade: [buildingId: number]
demolish: [buildingId: number] demolish: [buildingId: number]
priority: [buildingId: number, priority: number] priority: [buildingId: number, priority: number]
@ -33,10 +34,17 @@ const demolishTitle = (b: Building) =>
<div class="flex min-w-0 items-center gap-3"> <div class="flex min-w-0 items-center gap-3">
<IconBuildingTile :type="b.type" class="size-11" /> <IconBuildingTile :type="b.type" class="size-11" />
<div class="min-w-0"> <div class="min-w-0">
<p class="truncate font-medium">{{ $t(`buildings.${b.type}`) }}</p> <button
type="button"
class="block max-w-full truncate text-left font-medium hover:text-amber-800 hover:underline"
:title="$t('village.buildings.show')"
@click="emit('select', b.id)"
>
{{ $t(`buildings.${b.type}`) }}
</button>
<p class="text-xs text-ink-500"> <p class="text-xs text-ink-500">
{{ $t('village.buildings.level_n', { level: b.level }) }} {{ $t('village.buildings.level_n', { level: b.level }) }}
<template v-if="b.footprint[0]"> · {{ b.x }}|{{ b.y }}</template> <template v-if="b.space"> · {{ $t('village.build.space', { space: b.space }) }}</template>
</p> </p>
</div> </div>
</div> </div>

View File

@ -9,7 +9,7 @@ const list: Resource[] = ['wood', 'clay', 'iron', 'food']
<!-- Projected stock per resource, its rate, and how full storage is. --> <!-- Projected stock per resource, its rate, and how full storage is. -->
<template> <template>
<div class="border-b border-parchment-300/70 bg-parchment-50/95 shadow-sm backdrop-blur"> <div class="border-b border-parchment-300/70 bg-parchment-50/95 shadow-sm backdrop-blur">
<div class="mx-auto grid max-w-6xl grid-cols-4 gap-x-3 px-4 py-2 sm:grid-cols-[repeat(4,minmax(0,1fr))_auto] sm:gap-x-5"> <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
v-for="r in list" v-for="r in list"
:key="r" :key="r"

View File

@ -1,18 +1,22 @@
<script setup lang="ts"> <script setup lang="ts">
import type { BuildingType } from '~/types/game'
const route = useRoute() const route = useRoute()
const v = useVillage(Number(route.params.id)) const v = useVillage(Number(route.params.id))
const { village, resources, error, busy } = v const { village, resources, error, busy } = v
/** Grid cell the next new building goes to; null lets the server pick. */ /** Building selected in the diorama, by id; dropped when the building is gone. */
const selected = ref<{ x: number; y: number } | null>(null) 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))
v.refresh() v.refresh()
async function build(type: BuildingType) { function showInVillage(id: number) {
await v.build(type, selected.value) selected.value = id
if (!error.value) selected.value = null window.scrollTo({ top: 0, behavior: 'smooth' })
} }
</script> </script>
@ -20,33 +24,63 @@ async function build(type: BuildingType) {
<div v-if="village && resources"> <div v-if="village && resources">
<VillageResourceBar class="sticky top-0 z-30" :village="village" :resources="resources" /> <VillageResourceBar class="sticky top-0 z-30" :village="village" :resources="resources" />
<div class="mx-auto max-w-6xl space-y-6 px-4 py-6"> <section class="relative border-b border-parchment-300/70">
<header class="flex flex-wrap items-end justify-between gap-2"> <div class="px-4 pt-4 sm:pointer-events-none sm:absolute sm:top-5 sm:left-6 sm:z-10 sm:p-0">
<div class="min-w-0"> <div class="rounded-xl bg-white/85 px-4 py-3 shadow-sm ring-1 ring-parchment-300/70 backdrop-blur sm:pointer-events-auto">
<p class="text-xs font-medium tracking-wide text-ink-500 uppercase">{{ $t('village.title') }}</p> <p class="text-xs font-medium tracking-wide text-ink-500 uppercase">{{ $t('village.title') }}</p>
<h1 class="truncate font-display text-2xl font-semibold sm:text-3xl">{{ village.name }}</h1> <h1 class="font-display text-xl font-semibold sm:text-2xl">{{ village.name }}</h1>
</div> <p class="mt-0.5 flex items-center gap-1 text-xs text-ink-500">
<span class="badge bg-parchment-200 text-ink-700">
<IconUi name="pin" class="size-3.5" /> <IconUi name="pin" class="size-3.5" />
{{ village.x }}|{{ village.y }} {{ village.x }}|{{ village.y }}
</p>
<div class="mt-2.5 sm:w-52">
<div class="mb-1 flex justify-between gap-3 text-xs">
<span class="text-ink-500">{{ $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>
</header> </div>
<UiBar :value="spaceShare" :tone="spaceShare >= 1 ? 'rose' : 'emerald'" />
</div>
</div>
</div>
<p v-if="error" class="alert" role="alert">{{ error }}</p> <div class="h-[clamp(240px,74vw,440px)] sm:h-[clamp(320px,64vh,780px)]">
<VillageDiorama v-model:selected="selected" :village="village" />
</div>
<div class="grid gap-6 lg:grid-cols-3"> <p
<div class="space-y-6 lg:col-span-2"> class="pointer-events-none absolute bottom-3 left-1/2 hidden -translate-x-1/2 rounded-full bg-white/75 px-3 py-1 text-xs text-ink-500 shadow-sm sm:block"
<VillageGrid v-model:selected="selected" :village="village" /> >
<VillageBuildForm {{ $t('village.diorama.hint') }}
:options="village.buildable" </p>
:selected="selected"
<VillageBuildingCard
v-if="selectedBuilding"
class="mx-4 mb-4 lg:absolute lg:top-5 lg:right-6 lg:z-10 lg:m-0 lg:w-80"
:building="selectedBuilding"
:resources="resources" :resources="resources"
:can-afford="v.canAfford" :can-afford="v.canAfford"
:busy="busy" :busy="busy"
@build="build" @upgrade="v.upgrade"
@clear="selected = null" @demolish="v.demolish"
@priority="v.setPriority"
@close="selected = null"
/>
</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]">
<VillageBuildForm
:options="village.buildable"
:space="village.space"
:resources="resources"
:can-afford="v.canAfford"
:busy="busy"
@build="v.build"
/> />
</div>
<div class="space-y-6"> <div class="space-y-6">
<VillageBuildQueue <VillageBuildQueue
:queue="village.queue" :queue="village.queue"
@ -64,13 +98,14 @@ async function build(type: BuildingType) {
:resources="resources" :resources="resources"
:can-afford="v.canAfford" :can-afford="v.canAfford"
:busy="busy" :busy="busy"
@select="showInVillage"
@upgrade="v.upgrade" @upgrade="v.upgrade"
@demolish="v.demolish" @demolish="v.demolish"
@priority="v.setPriority" @priority="v.setPriority"
/> />
</div> </div>
</div> </div>
<div v-else class="mx-auto max-w-6xl px-4 py-16 text-center"> <div v-else class="px-4 py-16 text-center">
<p v-if="error" class="alert inline-block" role="alert">{{ error }}</p> <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> <p v-else class="text-sm text-ink-500">{{ $t('common.loading') }}</p>
</div> </div>

View File

@ -9,7 +9,7 @@ export default {
}, },
common: { common: {
loading: 'Loading…', loading: 'Loading…',
clear: 'Clear', close: 'Close',
}, },
resources: { resources: {
wood: 'Wood', wood: 'Wood',
@ -34,7 +34,7 @@ export default {
invalid_credentials: 'Wrong email or password.', invalid_credentials: 'Wrong email or password.',
email_taken: 'This email is already registered.', email_taken: 'This email is already registered.',
not_found: 'Not found.', not_found: 'Not found.',
no_space: 'That spot is taken or outside the village.', no_space: 'Not enough building space.',
max_per_village: 'Only one of these per village.', max_per_village: 'Only one of these per village.',
max_level: 'Already at max level.', max_level: 'Already at max level.',
resources: 'Not enough resources.', resources: 'Not enough resources.',

View File

@ -24,8 +24,6 @@ export default {
title: 'Buildings', title: 'Buildings',
type: 'Building', type: 'Building',
level: 'Level', level: 'Level',
position: 'Position',
size: 'Size',
workers: 'Workers', workers: 'Workers',
staffing: 'Staffing', staffing: 'Staffing',
output: 'Output', output: 'Output',
@ -37,23 +35,20 @@ export default {
upgrade: 'Upgrade to {level}', upgrade: 'Upgrade to {level}',
demolish: 'Demolish', demolish: 'Demolish',
refund: 'Refund', refund: 'Refund',
show: 'Show in the village',
}, },
grid: { diorama: {
title: 'Village grid', title: 'Village overview',
hint: 'Click a free cell to choose where the next building goes.', hint: 'Select a building to see what it does and upgrade it.',
planned: 'planned', label: '{name}, level {level}',
free_cell: 'Free cell', planned: 'Under construction',
space: 'Building space',
space_value: '{used} / {max}',
}, },
build: { build: {
title: 'New building', title: 'New building',
type: 'Building', space: 'Space {space}',
size: 'Size', free_space: '{free} space free',
cost: 'Cost',
time: 'Time',
status: 'Status',
position: 'Position',
auto: 'First free slot',
at_cell: 'Selected cell',
surrounds: 'Around the village', surrounds: 'Around the village',
submit: 'Build', submit: 'Build',
}, },
@ -74,7 +69,7 @@ export default {
}, },
blocked: { blocked: {
max_per_village: 'Only one per village', max_per_village: 'Only one per village',
no_space: 'No free space', no_space: 'Not enough building space',
max_level: 'Max level', max_level: 'Max level',
resources: 'Not enough resources', resources: 'Not enough resources',
requires: 'Needs a bigger headquarters', requires: 'Needs a bigger headquarters',