feat: pan and zoom the village over the land round it: drag, wheel, pinch, + − and "Whole village"; surroundings sized to the village so phones only grow sideways; no camera or extra land for the landing picture

The camera itself (useDioramaCamera) and the first cut of the surroundings went out
inside 62d9673, which another session committed while this work was in progress.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-30 11:27:18 +01:00
parent 5415ea01ea
commit 5de40ad5d7
3 changed files with 19 additions and 12 deletions

File diff suppressed because one or more lines are too long

View File

@ -11,7 +11,7 @@ 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
/** A picture only (the landing page): no zoom controls. */ /** A picture only (the landing page): no pan, zoom or land beyond the view. */
still?: boolean still?: boolean
/** With `fill`: pixels at the edges that windows cover; the whole village fits into the rest. */ /** With `fill`: pixels at the edges that windows cover; the whole village fits into the rest. */
inset?: SceneInset inset?: SceneInset
@ -33,7 +33,7 @@ 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(() => const scene = computed(() =>
props.fill ? buildScene(props.village, { width: size.value.w, height: size.value.h, inset: props.inset }) : buildScene(props.village, aspect.value), props.fill ? buildScene(props.village, { width: size.value.w, height: size.value.h, inset: props.inset, surroundings: !props.still }) : buildScene(props.village, aspect.value),
) )
function measure() { function measure() {
@ -58,7 +58,7 @@ const { view, viewBox, panning, zoomIn, zoomOut, reset, canZoomIn, canZoomOut, a
home: () => scene.value.home, home: () => scene.value.home,
bounds: () => scene.value.bounds, bounds: () => scene.value.bounds,
inset: () => props.inset ?? { top: 0, right: 0, bottom: 0, left: 0 }, inset: () => props.inset ?? { top: 0, right: 0, bottom: 0, left: 0 },
enabled: () => !!props.fill, enabled: () => !!props.fill && !props.still,
}) })
/** The zoom buttons sit in the bottom right corner of the part no window covers. */ /** The zoom buttons sit in the bottom right corner of the part no window covers. */
const controlsAt = computed(() => ({ right: `${(props.inset?.right ?? 0) + 8}px`, bottom: `${(props.inset?.bottom ?? 0) + 8}px` })) const controlsAt = computed(() => ({ right: `${(props.inset?.right ?? 0) + 8}px`, bottom: `${(props.inset?.bottom ?? 0) + 8}px` }))
@ -164,7 +164,7 @@ const timers = computed(() => {
<template> <template>
<div ref="scroller" class="relative h-full w-full overflow-y-hidden bg-[#6a7049]" :class="fill ? 'overflow-x-hidden' : 'overflow-x-auto'"> <div ref="scroller" class="relative h-full w-full overflow-y-hidden bg-[#6a7049]" :class="fill ? 'overflow-x-hidden' : 'overflow-x-auto'">
<div ref="stage" class="h-full" :class="[fill ? 'pan touch-none' : 'min-w-[640px]', { panning }]"> <div ref="stage" class="h-full" :class="[fill ? (still ? '' : 'pan touch-none') : 'min-w-[640px]', { panning }]">
<svg <svg
class="block h-full w-full select-none" class="block h-full w-full select-none"
:viewBox="viewBox" :viewBox="viewBox"

View File

@ -504,8 +504,13 @@ export function wallSegments(Rv: number, level: number, gates: number[]): { face
return out return out
} }
/** How much land a stage's scene draws round its home view, as a multiple of its size. */ /**
* How much land a stage's scene draws round the village: its view grown this much, but no
* more than the village's own size grown by AT_MOST, so a tall phone stage, already full of
* land above and below, only grows sideways.
*/
const SURROUNDINGS = 1.6 const SURROUNDINGS = 1.6
const AT_MOST = 2.6
/** Smooth value noise in world units: neighbouring points get similar values, so it comes in patches. */ /** Smooth value noise in world units: neighbouring points get similar values, so it comes in patches. */
function patches(x: number, y: number, size: number, seed: number): number { function patches(x: number, y: number, size: number, seed: number): number {
@ -535,7 +540,7 @@ export interface SceneInset {
* part and land and forest run on under the windows to every edge. A stage's scene also * part and land and forest run on under the windows to every edge. A stage's scene also
* draws the land round that view (`bounds`), for the camera to pan over and zoom out to. * draws the land round that view (`bounds`), for the camera to pan over and zoom out to.
*/ */
export function buildScene(village: VillageState, frame: number | { width: number; height: number; inset?: SceneInset } = 2.2): Scene { export function buildScene(village: VillageState, frame: number | { width: number; height: number; inset?: SceneInset; surroundings?: boolean } = 2.2): Scene {
const aspect = typeof frame === 'number' ? frame : frame.width / Math.max(1, frame.height) 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')
@ -698,6 +703,7 @@ export function buildScene(village: VillageState, frame: number | { width: numbe
let h = maxY - minY let h = maxY - minY
const midX = (minX + maxX) / 2 const midX = (minX + maxX) / 2
const midY = (minY + maxY) / 2 const midY = (minY + maxY) / 2
const most = { w: w * AT_MOST, h: h * AT_MOST }
if (typeof frame !== 'number') { if (typeof frame !== 'number') {
// Fit the village into the free part of the stage; the view spans the whole stage. // 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 inset = frame.inset ?? { top: 0, right: 0, bottom: 0, left: 0 }
@ -720,12 +726,13 @@ export function buildScene(village: VillageState, frame: number | { width: numbe
maxX = minX + w maxX = minX + w
maxY = minY + h maxY = minY + h
const view: View = { x: minX, y: minY, w, h } const view: View = { x: minX, y: minY, w, h }
// On a stage the land runs on round the view, centred on the village, never less than the view. // On a stage the land runs on round the village, never less than the view.
let bounds = view let bounds = view
if (typeof frame !== 'number') { if (typeof frame !== 'number' && frame.surroundings !== false) {
const bx = Math.min(view.x, midX - (w * SURROUNDINGS) / 2) const around = { w: Math.min(w * SURROUNDINGS, most.w), h: Math.min(h * SURROUNDINGS, most.h) }
const by = Math.min(view.y, midY - (h * SURROUNDINGS) / 2) const bx = Math.min(view.x, midX - around.w / 2)
bounds = { x: bx, y: by, w: Math.max(maxX, midX + (w * SURROUNDINGS) / 2) - bx, h: Math.max(maxY, midY + (h * SURROUNDINGS) / 2) - by } const by = Math.min(view.y, midY - around.h / 2)
bounds = { x: bx, y: by, w: Math.max(maxX, midX + around.w / 2) - bx, h: Math.max(maxY, midY + around.h / 2) - by }
} }
const { x: bX, y: bY, w: bW, h: bH } = bounds const { x: bX, y: bY, w: bW, h: bH } = bounds
// The main road runs on out of the land, wherever its edge is. // The main road runs on out of the land, wherever its edge is.