From af096c6d08ec8771a823fb6b9017215862e8e302 Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Wed, 28 Oct 2026 21:03:51 +0100 Subject: [PATCH] feat: countdown above every building under construction in the village view Co-Authored-By: Claude Opus 5.5 --- app/components/village/Diorama.vue | 42 +++++++++++++++++++++++++++++- app/diorama/scene.ts | 28 ++++++++++++++++++++ app/pages/village/[id].vue | 2 +- 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/app/components/village/Diorama.vue b/app/components/village/Diorama.vue index 5b0186c..c184fec 100644 --- a/app/components/village/Diorama.vue +++ b/app/components/village/Diorama.vue @@ -2,7 +2,11 @@ import type { VillageState } from '~/types/game' import { buildScene, type SceneBuilding } from '~/diorama/scene' -const props = defineProps<{ village: VillageState }>() +const props = defineProps<{ + village: VillageState + /** Whole seconds until a server timestamp, on the server's clock. */ + secondsUntil: (iso: string) => number +}>() /** Id of the building whose details are open. */ const selected = defineModel('selected', { default: null }) const { t } = useI18n() @@ -56,6 +60,31 @@ const badges = computed(() => { } return placed }) + +// Countdowns sit right above what is being built: over the level badge (and its name +// tag while that is showing), or over the scaffold of a new building. +// A timer that would cover another timer or a level badge moves up until it is clear. +const timers = computed(() => { + const K = k.value + const half = { w: 36 * K, h: 11 * K } + const placed: { x: number; y: number }[] = [] + const hits = (x: number, y: number) => + placed.some((p) => Math.abs(p.x - x) < half.w * 2 && Math.abs(p.y - y) < half.h * 2) || + badges.value.some((p) => Math.abs(p.x - x) < half.w + 11 * K && Math.abs(p.y - y) < half.h + 11 * K) + return scene.value.timers + .map((tm) => { + const badge = tm.buildingId !== null ? badges.value.find((p) => p.b.id === tm.buildingId) : undefined + const lift = badge ? (isActive(badge.b.id) ? 52 : 25) : 2 + return { ...tm, x: badge?.x ?? tm.at[0], y: (badge?.y ?? tm.at[1]) - lift * K } + }) + .sort((a, b) => b.y - a.y) + .map((tm) => { + let y = tm.y + for (let n = 0; n < 8 && hits(tm.x, y); n++) y -= half.h * 2.1 + placed.push({ x: tm.x, y }) + return { ...tm, y } + }) +})