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:
24
init.lua
24
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 `<current-module-id>.`.
|
||||
-- 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" -> "<current-module-id>.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)
|
||||
|
||||
@@ -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"}
|
||||
|
||||
Reference in New Issue
Block a user