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:
parent
fe9d28bf4e
commit
73a376ac6c
13 changed files with 830 additions and 0 deletions
47
packages/ludic.minimap/grid.ludic
Normal file
47
packages/ludic.minimap/grid.ludic
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# grid.ludic - the explored grid: square cells round the origin, and the part of it "explored" is
|
||||
# measured over (a core, so a bigger grid does not change what a share of it means)
|
||||
var mm_cells: int = 128 # per side
|
||||
var mm_cell_m: float = 100.0 # metres per cell
|
||||
var mm_core0: int = 0 # the measured square: from this cell, this many per side
|
||||
var mm_core_n: int = 128
|
||||
var mm_seen: []int = null # 0 / 1 per cell, row by row
|
||||
var mm_version: int = 0 # goes up whenever a cell is revealed or the grid is replaced
|
||||
|
||||
# the grid: `cells` per side of `cell_m` metres, centred on MinimapWorld's origin; the whole of it
|
||||
# is measured until minimap_config_core says otherwise
|
||||
export function minimap_config(cells: int, cell_m: float) -> void {
|
||||
mm_cells = Math.max(cells, 1)
|
||||
mm_cell_m = Math.max(cell_m, 0.001)
|
||||
mm_core0 = 0
|
||||
mm_core_n = mm_cells
|
||||
mm_seen = new []int
|
||||
for i in 0 .. mm_cells * mm_cells { push(mm_seen, 0) }
|
||||
mm_land_n = 0
|
||||
mm_version += 1
|
||||
}
|
||||
|
||||
export function minimap_config_core(from: int, n: int) -> void {
|
||||
mm_core0 = Math.clamp(from, 0, mm_cells - 1)
|
||||
mm_core_n = Math.clamp(n, 1, mm_cells - mm_core0)
|
||||
mm_land_n = 0
|
||||
}
|
||||
|
||||
export function minimap_cells() -> int { return mm_cells }
|
||||
export function minimap_cell_m() -> float { return mm_cell_m }
|
||||
export function minimap_grid_half() -> float { return float(mm_cells) * mm_cell_m * 0.5 }
|
||||
|
||||
# the grid's west and north edges, and a column's or a row's
|
||||
export function minimap_grid_x0() -> float { return MinimapWorld.origin_x() - minimap_grid_half() }
|
||||
export function minimap_grid_z0() -> float { return MinimapWorld.origin_z() - minimap_grid_half() }
|
||||
export function minimap_cell_x(i: int) -> float { return minimap_grid_x0() + float(i) * mm_cell_m }
|
||||
export function minimap_cell_z(j: int) -> float { return minimap_grid_z0() + float(j) * mm_cell_m }
|
||||
|
||||
# the cell a point is in, -1 off the grid
|
||||
export function minimap_cell(x: float, z: float) -> int {
|
||||
let i = int(Math.floor((x - minimap_grid_x0()) / mm_cell_m))
|
||||
let j = int(Math.floor((z - minimap_grid_z0()) / mm_cell_m))
|
||||
if i < 0 or j < 0 or i >= mm_cells or j >= mm_cells { return -1 }
|
||||
return j * mm_cells + i
|
||||
}
|
||||
|
||||
function mm_grid() -> void { if mm_seen == null { minimap_config(mm_cells, mm_cell_m) } }
|
||||
Loading…
Add table
Add a link
Reference in a new issue