From caf29b314d07262d28e4798841d034a3e4ea5d58 Mon Sep 17 00:00:00 2001 From: Axel Meyer Date: Thu, 21 May 2026 16:18:34 +0200 Subject: [PATCH] Make load_textures iterate atlases for v2 maps M.load now auto-upgrades v1 maps to v2 shape (no m.tilemap field), but load_textures still dereferenced m.tilemap unconditionally and crashed on every v2 consumer. Extract per-tilemap loop into a helper and dispatch by schema_version. Co-Authored-By: Claude Opus 4.7 (1M context) --- init.lua | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/init.lua b/init.lua index e864a3f..8c6001b 100644 --- a/init.lua +++ b/init.lua @@ -595,13 +595,7 @@ end -- Operates on the current map's tilemap; call after maps.set_current. -- asset_aliases: { [alias-key] = asset-lib-id } from module's manifest. -- ==================================================================== -function M.load_textures(asset_aliases) - local map_id = M.current() - if map_id == nil then - error("maps.load_textures: no current map; call maps.set_current first") - end - local m = map_registry[map_id] - local tm = m.tilemap +local function load_textures_for_tilemap(tm, asset_aliases) if tm.asset_pack == nil then return end -- color-only tilemap, no textures local lib_id = asset_aliases[tm.asset_pack] if lib_id == nil then @@ -627,6 +621,23 @@ function M.load_textures(asset_aliases) end end +function M.load_textures(asset_aliases) + local map_id = M.current() + if map_id == nil then + error("maps.load_textures: no current map; call maps.set_current first") + end + local m = map_registry[map_id] + + if m.schema_version == 2 then + for _, tm in ipairs(m.atlases) do + load_textures_for_tilemap(tm, asset_aliases) + end + return + end + -- v1 legacy: kept for M.create with manual v1 table + load_textures_for_tilemap(m.tilemap, asset_aliases) +end + function M.iterate_layers_pre_entities(fn, map_id) local id = map_id or current_map_id if not id then error("maps.iterate_layers_pre_entities: no current map") end