Commit Graph

11 Commits

Author SHA1 Message Date
Axel Meyer
15fd68670e Add tile_at_layer and route legacy tile_at to surface layer
Introduces M.tile_at_layer(layer_name, x, y, map_id) for direct per-layer
tile lookup with proper atlas resolution. Refactors the v2 branch of M.tile_at
to delegate to tile_at_layer("surface", ...) instead of duplicating the GID
decode logic inline.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 15:48:07 +02:00
Axel Meyer
880c67fef3 Expose cell_gid query for multi-atlas v2 maps
Adds M.cell_gid(layer_name, x, y, map_id) to read raw GID values from
named layers, enabling callers to decode atlas/tile/rotation from any
layer without going through tile_at().

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 15:43:02 +02:00
Axel Meyer
6af36e9c6e Load schema-v2 maps with multi-layer storage and roof field
Replace the v1-only M.load path with a unified v2 load path that
auto-upgrades v1 JSON on read. Add build_map_v2 to produce map records
with atlases[], layers{}, and roof arrays. Add atlas_count, atlas_id_at,
has_layer, and is_indoor to the public API. Update tile_at to decode GIDs
from the surface layer for v2 maps, keeping M.create/build_map for
programmatic callers that supply a v1-style tilemap_table directly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 15:37:41 +02:00
Axel Meyer
1562ee0068 feat: validate schema-v2 map tables with layer-name whitelist
Adds validate_map_table_v2 — enforces schema_version=2, required
fields (id, size, atlases), non-empty atlases[], per-layer tile-count
check against w*h, and a VALID_LAYER_NAMES whitelist that logs a
warning for unknown layers instead of rejecting them.

Moves require_field before the v2 validator so it is in scope at
call time. engine.warn replaced with engine.print (no warn binding).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 15:26:48 +02:00
Axel Meyer
0985141fb9 feat: add v1->v2 schema auto-upgrade for map tables
Converts legacy single-tilemap maps (tiles[], tile_rotations[]) into the
schema-v2 format (atlases[], layers.surface with packed GID cells).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 15:20:32 +02:00
Axel Meyer
446d37fb0e feat: add packed-u32 GID encoding helpers for schema-v2 maps
encode_gid / decode_gid pack atlas_index (8 bits), tile_id (20 bits), and
rotation (2 bits) into a single u32; gid == 0 is reserved as the empty-cell
sentinel. Lua 5.4 native bitwise operators used throughout.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 15:15:34 +02:00
Axel Meyer
2b5acb5caf feat: v0.1.2 sprite-mode in draw_map + tile_rotations + load_textures
Sprite-mode in draw_map:
- tilemap-tiles with texture atlas-id render via
  engine.render.draw_sprite_transform with rotation pivot at tile center
- tiles without texture continue to render via draw_rect with color
  (Phase 1 mode preserved)

Tile rotation:
- maps support an optional tile_rotations parallel array in the map
  JSON with per-cell 90-degree rotation values (0/90/180/270)
- absent or nil entries default to 0 (no rotation)
- enables 9-segment tile reuse via rotation rather than per-orientation
  sprites

New API:
- maps.load_textures(asset_aliases) resolves the current tilemap's
  tile atlas-ids to texture-handles via the asset-lib indirection
  (asset_aliases[tilemap.asset_pack] -> lib-id -> atlas.json lookup
  per tile)

Schema additions:
- tilemap.asset_pack (alias-key, optional)
- tile.texture (atlas-id, optional)
- map.tile_rotations (parallel array, optional)

All existing Phase 1 color-only tilemaps render unchanged.
2026-05-18 03:21:52 +02:00
Axel Meyer
db9eb222cb fix(P.3.1): split_namespaced_id replaced with current-module-prefix match; v0.1.1
Pre-existing bug: split_namespaced_id used first-dot-split. For modules
with dotted IDs (e.g. lib-core.maps-test), this misclassified
'<dotted-module-id>.<tilemap-name>' as cross-lib reference.

Replaced with split_local_tilemap() that matches by exact current-
module-id prefix. Module-id can now have arbitrary dots.

Surfaced by P.3.1 reference test-module 'lib-core.maps-test' which
has a dotted module-id.
2026-05-11 02:50:32 +02:00
Axel Meyer
ecc6796b0d fix(audit-M1): tile_at 3-arg form accepts nil map_id with current_map fallback 2026-05-10 15:46:35 +02:00
Axel Meyer
94c2197d46 feat: P.0.lib.maps single-tile-grid implementation (replaces trivial-stub) 2026-05-09 18:13:59 +02:00
Axel Meyer
5cf3d0c2fb feat: P.0.module.skeleton trivial-stub for lib-core.maps 2026-05-09 15:42:39 +02:00