From 1ee19b4b7f7150263455fc70bb27971573d8c689 Mon Sep 17 00:00:00 2001 From: Axel Meyer Date: Thu, 21 May 2026 23:09:14 +0200 Subject: [PATCH] Migrate test assertions to atlas tile-record shape; bump to 0.3.0 tile.id is now an integer; the stable string identifier is tile.name. Updates all tile-record string-id assertions to use .name. Adds walkable field to stub atlas JSONs so gameplay assertions pass without the legacy tiles dir. Test bootstrap calls maps.load_textures with aliases pointing to the test-lib itself as the asset provider. Moves load_textures calls inline after each set_current (Task 4 and Task 9 blocks) so all tile-record shape and walkability checks use atlas records throughout. Bumps version to 0.3.0, dep on maps 0.3.0. Co-Authored-By: Claude Opus 4.7 (1M context) --- assets/atlases/demo_tilemap/tiles.atlas.json | 2 + assets/atlases/walls_tilemap/tiles.atlas.json | 2 + init.lua | 38 ++++++++++--------- manifest.lib | 4 +- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/assets/atlases/demo_tilemap/tiles.atlas.json b/assets/atlases/demo_tilemap/tiles.atlas.json index 35688da..f6a8ccd 100644 --- a/assets/atlases/demo_tilemap/tiles.atlas.json +++ b/assets/atlases/demo_tilemap/tiles.atlas.json @@ -10,6 +10,7 @@ { "id": 1, "name": "grass", + "walkable": true, "uv": [ 0, 0, @@ -20,6 +21,7 @@ { "id": 2, "name": "stone", + "walkable": false, "uv": [ 32, 0, diff --git a/assets/atlases/walls_tilemap/tiles.atlas.json b/assets/atlases/walls_tilemap/tiles.atlas.json index f7fe07a..539e656 100644 --- a/assets/atlases/walls_tilemap/tiles.atlas.json +++ b/assets/atlases/walls_tilemap/tiles.atlas.json @@ -10,6 +10,7 @@ { "id": 1, "name": "wall_brick", + "walkable": false, "uv": [ 0, 0, @@ -21,6 +22,7 @@ { "id": 2, "name": "wall_wood", + "walkable": false, "uv": [ 32, 0, diff --git a/init.lua b/init.lua index cdd2ad4..371e554 100644 --- a/init.lua +++ b/init.lua @@ -8,6 +8,13 @@ local maps = require("lib-core.maps") local M = {} function M.run_tests(ctx) + -- Asset-aliases for texture-loading (test-libs lack manifest asset_aliases; + -- hard-code the test-lib itself as the asset provider for its own atlases). + local aliases = { + demo_tilemap = "lib-core.maps-test", + walls_tilemap = "lib-core.maps-test", + } + -- ---------- Task 1: GID encode/decode ---------- engine.test.equals(maps.encode_gid(0, 0, 0), 0, "encode_gid(0,0,0) = 0 (empty sentinel)") engine.test.equals(maps.encode_gid(0, 12, 0), 192, "encode_gid(0,12,0) = 192 (= 12<<4)") @@ -101,6 +108,7 @@ function M.run_tests(ctx) local v2_id = maps.load("maps/demo_v2.map.json") engine.test.equals(v2_id, "demo_v2", "v2 map loaded with id 'demo_v2'") maps.set_current(v2_id) + maps.load_textures(aliases) local v2_size = maps.size() engine.test.equals(v2_size.w, 4, "v2 map width = 4") engine.test.equals(v2_size.h, 4, "v2 map height = 4") @@ -138,12 +146,12 @@ function M.run_tests(ctx) -- ---------- Task 6: Per-layer tile_at ---------- -- tile_at_layer returns tile-record from the correct atlas local surface_tile = maps.tile_at_layer("surface", 1, 1) - engine.test.assert(surface_tile ~= nil, "surface (1,1) returns tile") - engine.test.equals(surface_tile.id, "grass", "surface (1,1) = grass") + engine.test.assert(surface_tile ~= nil, "surface (1,1) returns tile") + engine.test.equals(surface_tile.name, "grass", "surface (1,1) name = grass") local wall_tile = maps.tile_at_layer("wall", 0, 0) - engine.test.assert(wall_tile ~= nil, "wall (0,0) returns tile") - engine.test.equals(wall_tile.id, "wall_brick", "wall (0,0) = wall_brick (from walls_tilemap)") + engine.test.assert(wall_tile ~= nil, "wall (0,0) returns tile") + engine.test.equals(wall_tile.name, "wall_brick", "wall (0,0) name = wall_brick (from walls_tilemap)") -- Empty cell returns nil local empty_top = maps.tile_at_layer("topsurface", 0, 0) @@ -154,7 +162,7 @@ function M.run_tests(ctx) -- Legacy tile_at backwards-compat: queries surface layer local legacy = maps.tile_at(1, 1) - engine.test.equals(legacy.id, "grass", "legacy tile_at(x,y) queries surface layer") + engine.test.equals(legacy.name, "grass", "legacy tile_at(x,y) queries surface layer") -- ---------- Task 7: Gameplay queries ---------- -- Surface-only cells (inside, no wall) → walkable @@ -205,36 +213,30 @@ function M.run_tests(ctx) local v1_id = maps.load("maps/demo.map.json") engine.test.equals(v1_id, "demo", "v1 demo map loaded") maps.set_current(v1_id) + maps.load_textures(aliases) engine.test.equals(maps.atlas_count(), 1, "v1 auto-upgrade has 1 atlas") engine.test.equals(maps.atlas_id_at(0), "demo_tilemap", "v1 atlas[0] = demo_tilemap") engine.test.assert(maps.has_layer("surface"), "v1 auto-upgrade has surface layer") engine.test.assert(not maps.has_layer("wall"), "v1 has no wall layer") - -- Walkability via v2-API should match v1-API result + -- Walkability via v2-API should match v1-API result (atlas records now loaded) engine.test.assert(maps.is_walkable(5, 5), "v1 (5,5) walkable (was grass in v1 test)") engine.test.assert(not maps.is_walkable(0, 0), "v1 (0,0) not walkable (was stone in v1 test)") - -- Restore current to v2 map for subsequent tests if any - maps.set_current("demo_v2") - - -- Setup (legacy demo assertions, now using already-loaded demo from Task 9 above) - local demo_map = "demo" - maps.set_current(demo_map) - - -- Geometry assertions + -- Geometry assertions (demo map, already current after load_textures block) local size = maps.size() engine.test.equals(size.w, 16, "map width = 16") engine.test.equals(size.h, 16, "map height = 16") engine.test.equals(maps.tile_size(), 32, "tile_size = 32") - -- Tile lookup + walkability - engine.test.equals(maps.tile_at(0, 0).id, "stone", "tile_at(0,0) is stone") - engine.test.equals(maps.tile_at(5, 5).id, "grass", "tile_at(5,5) is grass") + -- Tile lookup + walkability (post-M.2: tile.id is int, tile.name is string) + engine.test.equals(maps.tile_at(0, 0).name, "stone", "tile_at(0,0) name = stone") + engine.test.equals(maps.tile_at(5, 5).name, "grass", "tile_at(5,5) name = grass") engine.test.assert(not maps.is_walkable(0, 0), "stone border non-walkable") engine.test.assert(maps.is_walkable(5, 5), "grass interior walkable") -- Arity-flex tile_at: 3-arg with nil map_id falls back to current_map (P.2.1) - engine.test.equals(maps.tile_at(nil, 5, 5).id, "grass", "tile_at 3-arg nil-fallback") + engine.test.equals(maps.tile_at(nil, 5, 5).name, "grass", "tile_at 3-arg nil-fallback name = grass") -- Out-of-bounds returns nil engine.test.equals(maps.tile_at(-1, 0), nil, "tile_at OOB negative tx returns nil") diff --git a/manifest.lib b/manifest.lib index 89e7146..659b376 100644 --- a/manifest.lib +++ b/manifest.lib @@ -1,9 +1,9 @@ { "id": "lib-core.maps-test", "role": "test", - "version": "0.2.0", + "version": "0.3.0", "api_min": "0.1", "deps": [ - {"id": "lib-core.maps", "version": "0.2.0"} + {"id": "lib-core.maps", "version": "0.3.0"} ] }