fix: the whole village fits into the screen space the windows leave free; land and forest fill the rest
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
3e374c9ec9
commit
5da7c1f512
|
|
@ -10,7 +10,7 @@ This is the Nuxt client for a browser strategy game in the style of Tribal Wars.
|
||||||
- **Dense and plain, like the old browser strategy games** (the reference is Die Stämme; notes and screenshots in the sibling repo `game-village-politics-research` (`../game-village-politics-research/die-staemme/`), kept out of this repo). A 14 px base, square frames with thin lines, tan header bands, tight table rows (`.grid-table`), small squared buttons (`.btn-primary` dark wood, `.btn-attack` red for attacks only), thin notice bars. No rounded cards, pills, big padding or decorative icons: an icon only where it carries meaning. Theme and component classes live in `app/assets/css/main.css`; hand-written inline SVG graphics in `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, and nothing copied from Die Stämme.
|
- **Dense and plain, like the old browser strategy games** (the reference is Die Stämme; notes and screenshots in the sibling repo `game-village-politics-research` (`../game-village-politics-research/die-staemme/`), kept out of this repo). A 14 px base, square frames with thin lines, tan header bands, tight table rows (`.grid-table`), small squared buttons (`.btn-primary` dark wood, `.btn-attack` red for attacks only), thin notice bars. No rounded cards, pills, big padding or decorative icons: an icon only where it carries meaning. Theme and component classes live in `app/assets/css/main.css`; hand-written inline SVG graphics in `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, and nothing copied from Die Stämme.
|
||||||
- **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. Levels start at 1. Each type has a model per level tier (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. Ambient life is welcome and stays out of the way: flat ground shadows, smoke from chimneys, forges and kilns, villagers walking the roads to the zones they work in; all motion stops under `prefers-reduced-motion`. The same models draw the building portraits on screen headers, the HQ list and the building cards (`VillageBuildingPortrait`). The world map groups forests, lakes and rocky hills by smooth noise of the coordinates, and village markers grow in five sizes with points. Map coordinates run around 0|0, negative included (−500 to 499 on a 1000-field map, lowest value from `map.view`'s `min`); continents are named from the top-left like Die Stämme, so 0|0 is the corner of K44, K45, K54 and K55. Use `app/utils/map.ts` for bounds and continents, never `0` or `500` literals.
|
- **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. Levels start at 1. Each type has a model per level tier (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. Ambient life is welcome and stays out of the way: flat ground shadows, smoke from chimneys, forges and kilns, villagers walking the roads to the zones they work in; all motion stops under `prefers-reduced-motion`. The same models draw the building portraits on screen headers, the HQ list and the building cards (`VillageBuildingPortrait`). The world map groups forests, lakes and rocky hills by smooth noise of the coordinates, and village markers grow in five sizes with points. Map coordinates run around 0|0, negative included (−500 to 499 on a 1000-field map, lowest value from `map.view`'s `min`); continents are named from the top-left like Die Stämme, so 0|0 is the corner of K44, K45, K54 and K55. Use `app/utils/map.ts` for bounds and continents, never `0` or `500` literals.
|
||||||
- **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`).
|
- **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 fills the screen.** On the village's own screens (`/village/<id>/…`) `GameVillageFrame` draws the diorama fixed across the whole browser window and docks everything over it, solid and opaque: the menu and the village bar along the top, the overview boxes in a right column (on phones a bottom sheet on the overview), and the open screen (headquarters, recruit, rally point, workforce) in a `UiWindow` on the left that folds and closes back to the overview; on the overview the left slot holds the card of the building picked in the village (`useVillageSelection`). Screen grids inside a window use container queries (`@4xl:`), not viewport breakpoints. The village scales to fit, no pan; on wide screens it is shifted by half the right column so it centres in the free area. Windows are docked now and meant to become draggable later, so `UiWindow` holds no position logic. This is where the game deliberately leaves Die Stämme's look behind.
|
- **The village fills the screen.** On the village's own screens (`/village/<id>/…`) `GameVillageFrame` draws the diorama fixed across the whole browser window and docks everything over it, solid and opaque: the menu and the village bar along the top, the overview boxes in a right column (on phones a bottom sheet on the overview), and the open screen (headquarters, recruit, rally point, workforce) in a `UiWindow` on the left that folds and closes back to the overview; on the overview the left slot holds the card of the building picked in the village (`useVillageSelection`). Screen grids inside a window use container queries (`@4xl:`), not viewport breakpoints. The village scales to fit, no pan: the frame measures what the bars, the right column, the phone tab bar and the bottom sheet cover (`inset`), `buildScene` fits the whole village into the rest, and ground and forest are generated for the whole stage, so nothing of the village is ever cut off. Windows are docked now and meant to become draggable later, so `UiWindow` holds no position logic. This is where the game deliberately leaves Die Stämme's look behind.
|
||||||
- **One game shell for the rest.** The map and reports sit in one centred column (1100 px). All world pages use `layouts/game.vue` (on village screens `GameVillageFrame` draws the same parts over the village): the dark main menu (`GameMenuBar`: village, map, reports with its count inline, each with a hover dropdown of its sub-pages; server clock; account dropdown), then the village header (`GameVillageBar`: a quick bar with the village's screens, and one row with the village, its stock in thin cells and incoming troops), thin notices, and the content in a `.frame`. On phones the screens move to a bottom tab bar (`GameTabBar`). The header's village is the URL's on village screens and the last opened one elsewhere; `GameVillageFrame` holds its one `useVillage()` and shares it through `useVillageContext()`. Pages outside a world use `layouts/default.vue` (menu only). A page has one of two shapes: a title with box tabs (`UiSubTabs`: buildings like the rally point) or a title with a sub-menu on the left (`UiSideMenu`: lists like reports). One key per screen (`useShortcuts`): V overview, H headquarters, T recruit, P rally point, W workforce, M map, R reports. The overview stays clean: the village and a narrow column of boxes (incoming attacks, production, units, population, construction); tables live on the building screens. The map shows a popup over a hovered village and actions under a clicked one. The village row starts with the quest book (`QuestBook`, a native `<dialog>` without a veil): it opens by itself when `quests.claimable` goes up, and a goal's "show me" opens its screen, a building goal the headquarters with `?hint=<type>` marking that row.
|
- **One game shell for the rest.** The map and reports sit in one centred column (1100 px). All world pages use `layouts/game.vue` (on village screens `GameVillageFrame` draws the same parts over the village): the dark main menu (`GameMenuBar`: village, map, reports with its count inline, each with a hover dropdown of its sub-pages; server clock; account dropdown), then the village header (`GameVillageBar`: a quick bar with the village's screens, and one row with the village, its stock in thin cells and incoming troops), thin notices, and the content in a `.frame`. On phones the screens move to a bottom tab bar (`GameTabBar`). The header's village is the URL's on village screens and the last opened one elsewhere; `GameVillageFrame` holds its one `useVillage()` and shares it through `useVillageContext()`. Pages outside a world use `layouts/default.vue` (menu only). A page has one of two shapes: a title with box tabs (`UiSubTabs`: buildings like the rally point) or a title with a sub-menu on the left (`UiSideMenu`: lists like reports). One key per screen (`useShortcuts`): V overview, H headquarters, T recruit, P rally point, W workforce, M map, R reports. The overview stays clean: the village and a narrow column of boxes (incoming attacks, production, units, population, construction); tables live on the building screens. The map shows a popup over a hovered village and actions under a clicked one. The village row starts with the quest book (`QuestBook`, a native `<dialog>` without a veil): it opens by itself when `quests.claimable` goes up, and a goal's "show me" opens its screen, a building goal the headquarters with `?hint=<type>` marking that row.
|
||||||
- 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`. vue-i18n reads a bare `|` as a plural separator and drops what follows, so coordinates in messages are written `"{x}{'|'}{y}"` inside a double-quoted string.
|
- 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`. vue-i18n reads a bare `|` as a plural separator and drops what follows, so coordinates in messages are written `"{x}{'|'}{y}"` inside a double-quoted string.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import type { SceneInset } from '~/diorama/scene'
|
||||||
const props = defineProps<{ villageId: number }>()
|
const props = defineProps<{ villageId: number }>()
|
||||||
|
|
||||||
// One village state for every screen in the world: the village header, the village's
|
// One village state for every screen in the world: the village header, the village's
|
||||||
|
|
@ -50,6 +51,42 @@ const screenTitle = computed(() => {
|
||||||
})
|
})
|
||||||
const picked = computed(() => !!(selected.value || plot.value))
|
const picked = computed(() => !!(selected.value || plot.value))
|
||||||
|
|
||||||
|
|
||||||
|
// What the bars, the right column and the phone tab bar cover, so the whole village fits
|
||||||
|
// into the rest of the screen while land and forest run on beneath them.
|
||||||
|
const topBars = ref<HTMLElement | null>(null)
|
||||||
|
const sideColumn = ref<HTMLElement | null>(null)
|
||||||
|
const inset = ref<SceneInset>({ top: 0, right: 0, bottom: 0, left: 0 })
|
||||||
|
const snap = (n: number) => Math.round(n / 8) * 8
|
||||||
|
function measureInset() {
|
||||||
|
const W = window.innerWidth
|
||||||
|
const H = window.innerHeight
|
||||||
|
const top = topBars.value?.getBoundingClientRect().bottom ?? 0
|
||||||
|
const side = sideColumn.value?.getBoundingClientRect()
|
||||||
|
const shown = side && side.width > 0 && side.height > 0
|
||||||
|
// A column on the right takes its width; on phones the boxes sit at the bottom instead.
|
||||||
|
const right = shown && side.left > W / 2 ? W - side.left : 0
|
||||||
|
const sheet = shown && side.left <= W / 2 ? H - side.top : 0
|
||||||
|
const tabBar = W < 768 ? 56 : 0
|
||||||
|
const next = { top: snap(top), right: snap(right), bottom: snap(Math.max(sheet, tabBar)), left: 0 }
|
||||||
|
if (JSON.stringify(next) !== JSON.stringify(inset.value)) inset.value = next
|
||||||
|
}
|
||||||
|
let insetObserver: ResizeObserver | undefined
|
||||||
|
onMounted(() => {
|
||||||
|
insetObserver = new ResizeObserver(measureInset)
|
||||||
|
window.addEventListener('resize', measureInset)
|
||||||
|
})
|
||||||
|
watch([topBars, sideColumn, picked, overview], async () => {
|
||||||
|
await nextTick()
|
||||||
|
insetObserver?.disconnect()
|
||||||
|
for (const el of [topBars.value, sideColumn.value]) if (el) insetObserver?.observe(el)
|
||||||
|
measureInset()
|
||||||
|
}, { flush: 'post' })
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
insetObserver?.disconnect()
|
||||||
|
window.removeEventListener('resize', measureInset)
|
||||||
|
})
|
||||||
|
|
||||||
// One key per screen of the world, as the menu and quick bar titles show.
|
// One key per screen of the world, as the menu and quick bar titles show.
|
||||||
useShortcuts(() => {
|
useShortcuts(() => {
|
||||||
const base = `/village/${props.villageId}`
|
const base = `/village/${props.villageId}`
|
||||||
|
|
@ -65,20 +102,19 @@ useShortcuts(() => {
|
||||||
<template>
|
<template>
|
||||||
<!-- The village's own screens: the village fills the screen, bars and windows dock over it. -->
|
<!-- The village's own screens: the village fills the screen, bars and windows dock over it. -->
|
||||||
<div v-if="stage">
|
<div v-if="stage">
|
||||||
<!-- One column's width wider than the screen, starting off its left edge: the village
|
<div class="fixed inset-0 z-0">
|
||||||
centres in the part the right column leaves free, and the land still runs under it. -->
|
|
||||||
<div class="fixed inset-y-0 right-0 left-0 z-0 lg:-left-60">
|
|
||||||
<VillageDiorama
|
<VillageDiorama
|
||||||
v-if="v.village.value"
|
v-if="v.village.value"
|
||||||
v-model:selected="selected"
|
v-model:selected="selected"
|
||||||
v-model:plot="plot"
|
v-model:plot="plot"
|
||||||
fill
|
fill
|
||||||
|
:inset="inset"
|
||||||
:village="v.village.value"
|
:village="v.village.value"
|
||||||
:seconds-until="v.secondsUntil"
|
:seconds-until="v.secondsUntil"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="pointer-events-none fixed inset-0 z-10 flex flex-col">
|
<div class="pointer-events-none fixed inset-0 z-10 flex flex-col">
|
||||||
<div class="pointer-events-auto shrink-0">
|
<div ref="topBars" class="pointer-events-auto shrink-0">
|
||||||
<GameMenuBar in-world wide />
|
<GameMenuBar in-world wide />
|
||||||
<div class="space-y-1 px-1 pt-1 sm:px-2">
|
<div class="space-y-1 px-1 pt-1 sm:px-2">
|
||||||
<GameVillageBar v-if="v.village.value && v.resources.value" :village="v.village.value" :resources="v.resources.value" />
|
<GameVillageBar v-if="v.village.value && v.resources.value" :village="v.village.value" :resources="v.resources.value" />
|
||||||
|
|
@ -110,6 +146,7 @@ useShortcuts(() => {
|
||||||
<!-- Right: the boxes with the numbers that matter at a glance. -->
|
<!-- Right: the boxes with the numbers that matter at a glance. -->
|
||||||
<div
|
<div
|
||||||
v-if="v.village.value"
|
v-if="v.village.value"
|
||||||
|
ref="sideColumn"
|
||||||
class="pointer-events-auto ml-auto max-h-full w-60 shrink-0 overflow-y-auto"
|
class="pointer-events-auto ml-auto max-h-full w-60 shrink-0 overflow-y-auto"
|
||||||
:class="overview && !picked ? 'max-lg:w-full max-lg:self-end max-lg:max-h-[45dvh]' : 'hidden lg:block'"
|
:class="overview && !picked ? 'max-lg:w-full max-lg:self-end max-lg:max-h-[45dvh]' : 'hidden lg:block'"
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { BuildingType, VillageState } from '~/types/game'
|
import type { BuildingType, VillageState } from '~/types/game'
|
||||||
import { buildScene, type SceneBuilding, type ScenePlot } from '~/diorama/scene'
|
import { buildScene, type SceneBuilding, type SceneInset, type ScenePlot } from '~/diorama/scene'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
village: VillageState
|
village: VillageState
|
||||||
|
|
@ -8,6 +8,8 @@ const props = defineProps<{
|
||||||
secondsUntil: (iso: string) => number
|
secondsUntil: (iso: string) => number
|
||||||
/** Fill the whole stage at any shape, without the sideways scroll of narrow frames. */
|
/** Fill the whole stage at any shape, without the sideways scroll of narrow frames. */
|
||||||
fill?: boolean
|
fill?: boolean
|
||||||
|
/** With `fill`: pixels at the edges that windows cover; the whole village fits into the rest. */
|
||||||
|
inset?: SceneInset
|
||||||
}>()
|
}>()
|
||||||
/** 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 })
|
||||||
|
|
@ -21,7 +23,9 @@ const scroller = ref<HTMLElement | null>(null)
|
||||||
const stage = ref<HTMLElement | null>(null)
|
const stage = ref<HTMLElement | null>(null)
|
||||||
const size = ref({ w: 1200, h: 520 })
|
const size = ref({ w: 1200, h: 520 })
|
||||||
const aspect = computed(() => Math.round((size.value.w / Math.max(1, size.value.h)) * 10) / 10)
|
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 scene = computed(() =>
|
||||||
|
props.fill ? buildScene(props.village, { width: size.value.w, height: size.value.h, inset: props.inset }) : buildScene(props.village, aspect.value),
|
||||||
|
)
|
||||||
|
|
||||||
function measure() {
|
function measure() {
|
||||||
const el = stage.value
|
const el = stage.value
|
||||||
|
|
|
||||||
|
|
@ -337,7 +337,21 @@ function wallSegments(Rv: number, level: number, gates: number[]): { faces: Face
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildScene(village: VillageState, aspect = 2.2): Scene {
|
/** Pixels at the stage's edges that windows cover; the village fits into the rest. */
|
||||||
|
export interface SceneInset {
|
||||||
|
top: number
|
||||||
|
right: number
|
||||||
|
bottom: number
|
||||||
|
left: number
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The scene for a stage: either just its shape (`aspect`, the village filling the frame),
|
||||||
|
* or its size in pixels with the covered edges, so the whole village lands in the free
|
||||||
|
* part and land and forest run on under the windows to every edge.
|
||||||
|
*/
|
||||||
|
export function buildScene(village: VillageState, frame: number | { width: number; height: number; inset?: SceneInset } = 2.2): Scene {
|
||||||
|
const aspect = typeof frame === 'number' ? frame : frame.width / Math.max(1, frame.height)
|
||||||
const isZone = (type: BuildingType) => ZONE_OF[type] !== undefined
|
const isZone = (type: BuildingType) => ZONE_OF[type] !== undefined
|
||||||
const hq = village.buildings.find((b) => b.type === 'headquarters')
|
const hq = village.buildings.find((b) => b.type === 'headquarters')
|
||||||
const hqRadius = footRadius(hq?.space ?? 9)
|
const hqRadius = footRadius(hq?.space ?? 9)
|
||||||
|
|
@ -486,7 +500,19 @@ export function buildScene(village: VillageState, aspect = 2.2): Scene {
|
||||||
maxX += padX
|
maxX += padX
|
||||||
let w = maxX - minX
|
let w = maxX - minX
|
||||||
let h = maxY - minY
|
let h = maxY - minY
|
||||||
if (w / h < aspect) {
|
if (typeof frame !== 'number') {
|
||||||
|
// Fit the village into the free part of the stage; the view spans the whole stage.
|
||||||
|
const inset = frame.inset ?? { top: 0, right: 0, bottom: 0, left: 0 }
|
||||||
|
const freeW = Math.max(120, frame.width - inset.left - inset.right)
|
||||||
|
const freeH = Math.max(120, frame.height - inset.top - inset.bottom)
|
||||||
|
const perUnit = Math.min(freeW / w, freeH / h)
|
||||||
|
const cx = (minX + maxX) / 2
|
||||||
|
const cy = (minY + maxY) / 2
|
||||||
|
w = frame.width / perUnit
|
||||||
|
h = frame.height / perUnit
|
||||||
|
minX = cx - (inset.left + freeW / 2) / perUnit
|
||||||
|
minY = cy - (inset.top + freeH / 2) / perUnit
|
||||||
|
} else if (w / h < aspect) {
|
||||||
const extra = h * aspect - w
|
const extra = h * aspect - w
|
||||||
minX -= extra / 2
|
minX -= extra / 2
|
||||||
w += extra
|
w += extra
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue