From a6ec817150d71c610c2d3a9d11537c9b554140fb Mon Sep 17 00:00:00 2001 From: Axel Meyer Date: Mon, 11 May 2026 02:49:02 +0200 Subject: [PATCH] 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 '.' 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. --- init.lua | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/init.lua b/init.lua index 4f55977..666a28d 100644 --- a/init.lua +++ b/init.lua @@ -16,12 +16,17 @@ local current_map_id = nil -- Internal helpers -- ===================================================================== --- Splits "lib-x.foo" -> "lib-x", "foo" (split at FIRST dot only). --- Returns (nil, full_id) if no dot present. -local function split_namespaced_id(full_id) - local dot = string.find(full_id, ".", 1, true) - if not dot then return nil, full_id end - return string.sub(full_id, 1, dot-1), string.sub(full_id, dot+1) +-- Checks whether `full_id` is a tilemap belonging to the current module. +-- Module-IDs can themselves contain dots (e.g. `lib-core.maps-test`), so a +-- naive first-dot-split is wrong. Match by prefix `.`. +-- Returns (is_local, local_name) — local_name is nil if not local. +local function split_local_tilemap(full_id) + 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 -- "demo_tilemap" -> ".demo_tilemap" @@ -82,12 +87,11 @@ local function load_tilemap(full_id) if tilemap_registry[full_id] then return tilemap_registry[full_id] end - local lib_id, local_name = split_namespaced_id(full_id) - local current_lib = engine.module.id() - if lib_id ~= current_lib then + local is_local, local_name = split_local_tilemap(full_id) + if not is_local then -- 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'", - full_id, current_lib)) + full_id, engine.module.id())) end local path = "assets/tiles/" .. local_name .. ".tilemap.json" local raw = engine.asset.load_json(path)