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:
parent
c7322c51db
commit
6bc2d44419
|
|
@ -24,7 +24,7 @@ useHead({ title: () => t('app.title') })
|
|||
<template>
|
||||
<div class="min-h-dvh">
|
||||
<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">
|
||||
<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" />
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ import type { BuildOption, BuildingType, Cost, Resources } from '~/types/game'
|
|||
|
||||
const props = defineProps<{
|
||||
options: BuildOption[]
|
||||
selected: { x: number; y: number } | null
|
||||
space: { used: number; max: number }
|
||||
resources: Resources
|
||||
canAfford: (cost: Cost) => boolean
|
||||
busy: boolean
|
||||
}>()
|
||||
const emit = defineEmits<{ build: [type: BuildingType]; clear: [] }>()
|
||||
const emit = defineEmits<{ build: [type: BuildingType] }>()
|
||||
const { t } = useI18n()
|
||||
|
||||
function status(o: BuildOption) {
|
||||
|
|
@ -22,27 +22,11 @@ function status(o: BuildOption) {
|
|||
<section class="panel">
|
||||
<div class="panel-head">
|
||||
<h2 class="panel-title">{{ $t('village.build.title') }}</h2>
|
||||
<div class="flex items-center gap-1.5 text-sm">
|
||||
<span class="text-ink-500">{{ $t('village.build.position') }}</span>
|
||||
<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>
|
||||
<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>
|
||||
<span class="badge bg-parchment-200 text-ink-700">
|
||||
{{ $t('village.build.free_space', { free: space.max - space.used }) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="panel-body grid gap-3 sm:grid-cols-2 xl:grid-cols-3">
|
||||
<div class="panel-body grid gap-3 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
|
||||
<article
|
||||
v-for="o in options"
|
||||
:key="o.type"
|
||||
|
|
@ -55,7 +39,7 @@ function status(o: BuildOption) {
|
|||
<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">
|
||||
<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 class="flex items-center gap-1 whitespace-nowrap tabular-nums">
|
||||
<IconUi name="clock" class="size-3" />
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ defineProps<{
|
|||
busy: boolean
|
||||
}>()
|
||||
const emit = defineEmits<{
|
||||
select: [buildingId: number]
|
||||
upgrade: [buildingId: number]
|
||||
demolish: [buildingId: number]
|
||||
priority: [buildingId: number, priority: number]
|
||||
|
|
@ -33,10 +34,17 @@ const demolishTitle = (b: Building) =>
|
|||
<div class="flex min-w-0 items-center gap-3">
|
||||
<IconBuildingTile :type="b.type" class="size-11" />
|
||||
<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">
|
||||
{{ $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>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ const list: Resource[] = ['wood', 'clay', 'iron', 'food']
|
|||
<!-- Projected stock per resource, its rate, and how full storage is. -->
|
||||
<template>
|
||||
<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
|
||||
v-for="r in list"
|
||||
:key="r"
|
||||
|
|
|
|||
|
|
@ -1,18 +1,22 @@
|
|||
<script setup lang="ts">
|
||||
import type { BuildingType } from '~/types/game'
|
||||
|
||||
const route = useRoute()
|
||||
const v = useVillage(Number(route.params.id))
|
||||
const { village, resources, error, busy } = v
|
||||
|
||||
/** Grid cell the next new building goes to; null lets the server pick. */
|
||||
const selected = ref<{ x: number; y: number } | null>(null)
|
||||
/** 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))
|
||||
|
||||
v.refresh()
|
||||
|
||||
async function build(type: BuildingType) {
|
||||
await v.build(type, selected.value)
|
||||
if (!error.value) selected.value = null
|
||||
function showInVillage(id: number) {
|
||||
selected.value = id
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
@ -20,33 +24,63 @@ async function build(type: BuildingType) {
|
|||
<div v-if="village && 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">
|
||||
<header class="flex flex-wrap items-end justify-between gap-2">
|
||||
<div class="min-w-0">
|
||||
<section class="relative border-b border-parchment-300/70">
|
||||
<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="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>
|
||||
<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>
|
||||
<p class="mt-0.5 flex items-center gap-1 text-xs text-ink-500">
|
||||
<IconUi name="pin" class="size-3.5" />
|
||||
{{ 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>
|
||||
</div>
|
||||
<UiBar :value="spaceShare" :tone="spaceShare >= 1 ? 'rose' : 'emerald'" />
|
||||
</div>
|
||||
</div>
|
||||
<span class="badge bg-parchment-200 text-ink-700">
|
||||
<IconUi name="pin" class="size-3.5" />
|
||||
{{ village.x }}|{{ village.y }}
|
||||
</span>
|
||||
</header>
|
||||
</div>
|
||||
|
||||
<div class="h-[clamp(240px,74vw,440px)] sm:h-[clamp(320px,64vh,780px)]">
|
||||
<VillageDiorama v-model:selected="selected" :village="village" />
|
||||
</div>
|
||||
|
||||
<p
|
||||
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"
|
||||
>
|
||||
{{ $t('village.diorama.hint') }}
|
||||
</p>
|
||||
|
||||
<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"
|
||||
:can-afford="v.canAfford"
|
||||
:busy="busy"
|
||||
@upgrade="v.upgrade"
|
||||
@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-3">
|
||||
<div class="space-y-6 lg:col-span-2">
|
||||
<VillageGrid v-model:selected="selected" :village="village" />
|
||||
<VillageBuildForm
|
||||
:options="village.buildable"
|
||||
:selected="selected"
|
||||
:resources="resources"
|
||||
:can-afford="v.canAfford"
|
||||
:busy="busy"
|
||||
@build="build"
|
||||
@clear="selected = null"
|
||||
/>
|
||||
</div>
|
||||
<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 class="space-y-6">
|
||||
<VillageBuildQueue
|
||||
:queue="village.queue"
|
||||
|
|
@ -64,13 +98,14 @@ async function build(type: BuildingType) {
|
|||
:resources="resources"
|
||||
:can-afford="v.canAfford"
|
||||
:busy="busy"
|
||||
@select="showInVillage"
|
||||
@upgrade="v.upgrade"
|
||||
@demolish="v.demolish"
|
||||
@priority="v.setPriority"
|
||||
/>
|
||||
</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-else class="text-sm text-ink-500">{{ $t('common.loading') }}</p>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ export default {
|
|||
},
|
||||
common: {
|
||||
loading: 'Loading…',
|
||||
clear: 'Clear',
|
||||
close: 'Close',
|
||||
},
|
||||
resources: {
|
||||
wood: 'Wood',
|
||||
|
|
@ -34,7 +34,7 @@ export default {
|
|||
invalid_credentials: 'Wrong email or password.',
|
||||
email_taken: 'This email is already registered.',
|
||||
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_level: 'Already at max level.',
|
||||
resources: 'Not enough resources.',
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@ export default {
|
|||
title: 'Buildings',
|
||||
type: 'Building',
|
||||
level: 'Level',
|
||||
position: 'Position',
|
||||
size: 'Size',
|
||||
workers: 'Workers',
|
||||
staffing: 'Staffing',
|
||||
output: 'Output',
|
||||
|
|
@ -37,23 +35,20 @@ export default {
|
|||
upgrade: 'Upgrade to {level}',
|
||||
demolish: 'Demolish',
|
||||
refund: 'Refund',
|
||||
show: 'Show in the village',
|
||||
},
|
||||
grid: {
|
||||
title: 'Village grid',
|
||||
hint: 'Click a free cell to choose where the next building goes.',
|
||||
planned: 'planned',
|
||||
free_cell: 'Free cell',
|
||||
diorama: {
|
||||
title: 'Village overview',
|
||||
hint: 'Select a building to see what it does and upgrade it.',
|
||||
label: '{name}, level {level}',
|
||||
planned: 'Under construction',
|
||||
space: 'Building space',
|
||||
space_value: '{used} / {max}',
|
||||
},
|
||||
build: {
|
||||
title: 'New building',
|
||||
type: 'Building',
|
||||
size: 'Size',
|
||||
cost: 'Cost',
|
||||
time: 'Time',
|
||||
status: 'Status',
|
||||
position: 'Position',
|
||||
auto: 'First free slot',
|
||||
at_cell: 'Selected cell',
|
||||
space: 'Space {space}',
|
||||
free_space: '{free} space free',
|
||||
surrounds: 'Around the village',
|
||||
submit: 'Build',
|
||||
},
|
||||
|
|
@ -74,7 +69,7 @@ export default {
|
|||
},
|
||||
blocked: {
|
||||
max_per_village: 'Only one per village',
|
||||
no_space: 'No free space',
|
||||
no_space: 'Not enough building space',
|
||||
max_level: 'Max level',
|
||||
resources: 'Not enough resources',
|
||||
requires: 'Needs a bigger headquarters',
|
||||
|
|
|
|||
Loading…
Reference in New Issue