refactor: WorldMap's layer offset computed once

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-11-03 10:23:18 +01:00
parent 03d4e66f72
commit aba98d7b1c
1 changed files with 7 additions and 4 deletions

View File

@ -44,7 +44,7 @@ const lo = computed(() => props.view?.min ?? mapMin(mapSize.value))
const villageAt = computed(() => new Map((props.view?.villages ?? []).map((v) => [`${v.x}|${v.y}`, v])))
// Whole fields touching the visible area, for the rulers.
// Whole fields touching the visible area.
const x0 = computed(() => Math.max(lo.value, Math.floor(props.left)))
const y0 = computed(() => Math.max(lo.value, Math.floor(props.top)))
const x1 = computed(() => Math.min(lo.value + mapSize.value, Math.ceil(props.left + props.cols)))
@ -68,13 +68,16 @@ const shiftY = computed(() => RULER + Math.round(-props.top * props.field))
const layer = computed(() => {
const r = region.value
const F = props.field
/** The region's top-left corner on screen, from where the fields begin. */
const x = shiftX.value - RULER + r.x0 * F
const y = shiftY.value - RULER + r.y0 * F
return {
width: (r.x1 - r.x0) * F,
height: (r.y1 - r.y0) * F,
viewBox: `${r.x0 * F} ${r.y0 * F} ${(r.x1 - r.x0) * F} ${(r.y1 - r.y0) * F}`,
x: shiftX.value - RULER + r.x0 * F,
y: shiftY.value - RULER + r.y0 * F,
transform: `translate3d(${shiftX.value - RULER + r.x0 * F}px, ${shiftY.value - RULER + r.y0 * F}px, 0)`,
x,
y,
transform: `translate3d(${x}px, ${y}px, 0)`,
}
})