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.
This commit is contained in:
Axel Meyer
2026-05-11 02:49:02 +02:00
parent ecc6796b0d
commit db9eb222cb
2 changed files with 15 additions and 11 deletions

View File

@@ -16,12 +16,17 @@ local current_map_id = nil
-- Internal helpers -- Internal helpers
-- ===================================================================== -- =====================================================================
-- Splits "lib-x.foo" -> "lib-x", "foo" (split at FIRST dot only). -- Checks whether `full_id` is a tilemap belonging to the current module.
-- Returns (nil, full_id) if no dot present. -- Module-IDs can themselves contain dots (e.g. `lib-core.maps-test`), so a
local function split_namespaced_id(full_id) -- naive first-dot-split is wrong. Match by prefix `<current-module-id>.`.
local dot = string.find(full_id, ".", 1, true) -- Returns (is_local, local_name) — local_name is nil if not local.
if not dot then return nil, full_id end local function split_local_tilemap(full_id)
return string.sub(full_id, 1, dot-1), string.sub(full_id, dot+1) local mod = engine.module.id()
local prefix = mod .. "."
if string.sub(full_id, 1, #prefix) == prefix then
return true, string.sub(full_id, #prefix + 1)
end
return false, nil
end end
-- "demo_tilemap" -> "<current-module-id>.demo_tilemap" -- "demo_tilemap" -> "<current-module-id>.demo_tilemap"
@@ -82,12 +87,11 @@ local function load_tilemap(full_id)
if tilemap_registry[full_id] then if tilemap_registry[full_id] then
return tilemap_registry[full_id] return tilemap_registry[full_id]
end end
local lib_id, local_name = split_namespaced_id(full_id) local is_local, local_name = split_local_tilemap(full_id)
local current_lib = engine.module.id() if not is_local then
if lib_id ~= current_lib then
-- DEPRECATED-MVP: cross-lib tilemap resolution deferred to render-slice -- DEPRECATED-MVP: cross-lib tilemap resolution deferred to render-slice
error(string.format("maps.load: cross-lib tilemap resolution deferred [DEPRECATED-MVP]; tilemap '%s' not from current module '%s'", error(string.format("maps.load: cross-lib tilemap resolution deferred [DEPRECATED-MVP]; tilemap '%s' not from current module '%s'",
full_id, current_lib)) full_id, engine.module.id()))
end end
local path = "assets/tiles/" .. local_name .. ".tilemap.json" local path = "assets/tiles/" .. local_name .. ".tilemap.json"
local raw = engine.asset.load_json(path) local raw = engine.asset.load_json(path)

View File

@@ -1 +1 @@
{"id":"lib-core.maps","version":"0.1.0","api_min":"0.1"} {"id":"lib-core.maps","version":"0.1.1","api_min":"0.1"}