feat(packages): ludic.minimap - a map's logic: the explored fog over a grid of cells round an origin (revealed within a reach, a version for rebaking, explored as a share of the land over a core square, the grid as text for an older save), the player's marks (a cap, a symbol, a colour, the day, a name; the open one and the followed one, rubbing out, the last symbol reused, the nearest for a compass) and the view (world to window and back, zoom in steps and about a point, a drag, pick and place, the camp, you, a focus that never pulls back out, a scale bar, bounds); the world through a port; seen and marks in its own save section by key

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 09:45:59 +03:00
parent fe9d28bf4e
commit 73a376ac6c
13 changed files with 830 additions and 0 deletions

View file

@ -0,0 +1,61 @@
# view_moves.ludic - moving the view: zoom in steps or about a point (so what is under the pointer
# stays under it), a drag that pans, and a press that picks the mark under it
var mm_panning: bool = false
var mm_drag_rx: float = 0.0
var mm_drag_ry: float = 0.0
var mm_drag_vx: float = 0.0
var mm_drag_vz: float = 0.0
export function minimap_zoom_set(z: float) -> void {
mm_zoom = Math.clamp(z, mm_zoom_min, mm_zoom_max)
minimap_clamp()
}
# a step in (dir > 0) or out, a third at a time
export function minimap_zoom_step(dir: int) -> void {
if dir > 0 { minimap_zoom_set(mm_zoom * 1.3) } else { minimap_zoom_set(mm_zoom / 1.3) }
}
# zoom by `factor` about a point of the window
export function minimap_zoom_about(rx: float, ry: float, factor: float) -> void {
let wx = minimap_wx(rx)
let wz = minimap_wz(ry)
mm_zoom = Math.clamp(mm_zoom * factor, mm_zoom_min, mm_zoom_max)
mm_vx = mm_vx + wx - minimap_wx(rx)
mm_vz = mm_vz + wz - minimap_wz(ry)
minimap_clamp()
}
export function minimap_pan_begin(rx: float, ry: float) -> void {
mm_panning = true
mm_drag_rx = rx
mm_drag_ry = ry
mm_drag_vx = mm_vx
mm_drag_vz = mm_vz
}
# the point pressed follows the pointer
export function minimap_pan_to(rx: float, ry: float) -> void {
if not mm_panning { return }
mm_vx = mm_drag_vx - (rx - mm_drag_rx) / minimap_scale()
mm_vz = mm_drag_vz - (ry - mm_drag_ry) / minimap_scale()
minimap_clamp()
}
export function minimap_pan_end() -> void { mm_panning = false }
export function minimap_panning() -> bool { return mm_panning }
# the mark within r pixels of a point of the window is opened (the last drawn, so the top one);
# -1 and nothing changes when there is none
export function minimap_pick(rx: float, ry: float, r: float) -> int {
let sx = mm_x0 + rx
let sy = mm_y0 + ry
var hit = -1
for i in 0 .. minimap_pin_count() {
let px = minimap_px(mm_pins[i].x)
let py = minimap_py(mm_pins[i].z)
if sx >= px - r and sx < px + r and sy >= py - r and sy < py + r { hit = i }
}
if hit >= 0 { mm_open = hit }
return hit
}