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) <noreply@anthropic.com>
This commit is contained in:
25
init.lua
25
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
|
||||
|
||||
Reference in New Issue
Block a user