Document v0.2.0 API and schema-v2 map format
Update README.md to version 0.2.0: add API entries for the 16 new public functions (encode_gid, decode_gid, upgrade_v1_to_v2, validate_map_table_v2, atlas_count, atlas_id_at, has_layer, is_indoor, cell_gid, tile_at_layer, blocks_walk, blocks_sight, iterate_layers_pre_entities, iterate_layers_post_entities, draw_map_pre_entities, draw_map_post_entities), add the schema-v2 reference section documenting layer-stack, packed-u32 GID bit layout, auto-migration, and a v0.2.0 changelog entry. Fix tile-id OOB validation regression in build_map_v2: after v1->v2 upgrade, packed GIDs were not checked against atlas palette sizes. Restore the check in build_map_v2 so loading a map with an out-of-range tile_id still produces a fatal error with the same message pattern. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
21
init.lua
21
init.lua
@@ -275,6 +275,25 @@ end
|
||||
|
||||
local function build_map_v2(t_map, resolved_atlases)
|
||||
local size = t_map.size
|
||||
-- Validate that each non-zero GID references a tile_id within its atlas's palette.
|
||||
local layers = t_map.layers or {}
|
||||
for layer_name, layer_data in pairs(layers) do
|
||||
if VALID_LAYER_NAMES[layer_name] and layer_data.tiles then
|
||||
for i, gid in ipairs(layer_data.tiles) do
|
||||
if gid ~= 0 then
|
||||
local atlas_idx, tile_id, _rot = decode_gid(gid)
|
||||
local atlas = resolved_atlases[atlas_idx + 1]
|
||||
if atlas then
|
||||
if tile_id < 1 or tile_id > #atlas.tiles then
|
||||
error(string.format(
|
||||
"maps.load: tile-id %d at index %d exceeds palette size %d (in map '%s', layer '%s')",
|
||||
tile_id, i, #atlas.tiles, t_map.id or "<unnamed>", layer_name))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return {
|
||||
id = t_map.id,
|
||||
schema_version = 2,
|
||||
@@ -282,7 +301,7 @@ local function build_map_v2(t_map, resolved_atlases)
|
||||
tile_size = resolved_atlases[1].tile_size, -- assume uniform; first atlas wins
|
||||
atlases = resolved_atlases,
|
||||
atlas_aliases = t_map.atlases, -- alias strings, parallel to atlases
|
||||
layers = t_map.layers or {},
|
||||
layers = layers,
|
||||
roof = t_map.roof,
|
||||
-- DEPRECATED-MVP stubs
|
||||
walls = {},
|
||||
|
||||
Reference in New Issue
Block a user