From be6d419061b6d300f57fa54c4ebfd61070d824d8 Mon Sep 17 00:00:00 2001 From: calic Date: Fri, 29 May 2026 01:37:38 +0200 Subject: [PATCH] =?UTF-8?q?feat(maps):=20v0.5.4=20=E2=80=94=20atlas=5Fdiff?= =?UTF-8?q?use=5Fhandle=20+=20atlas=5Ftile=5Fsize=5Fpx=20+=20atlas=5Ftile?= =?UTF-8?q?=5Fuv?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Public accessors for palette-like consumers (map-editor 0.2.0c.2) that need to render real tile thumbnails. All three return nil when the atlas-idx is out of range, the slot has no tile in the atlas, or the texture failed to load (headless test env). atlas_tile_uv resolves the slot via the same `slot_NN_` regex used internally by the v3 vertex/material render path, so callers see the same slot -> tile_id mapping the renderer uses. --- init.lua | 32 ++++++++++++++++++++++++++++++++ manifest.lib | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 5cd0baf..e9ce8ba 100644 --- a/init.lua +++ b/init.lua @@ -1210,6 +1210,38 @@ function M.atlas_id_at(idx, map_id) or m.atlases[idx + 1] and m.atlases[idx + 1].id end +-- 0.5.4: Public accessors for palette-like consumers (map-editor) that +-- need to render real tile thumbnails. All three return nil when the +-- atlas-idx is out of range, the slot has no tile in the atlas, or the +-- texture failed to load (headless test env). +function M.atlas_diffuse_handle(atlas_idx, map_id) + local id = map_id or current_map_id + if not id then error("maps.atlas_diffuse_handle: no current map") end + local m = map_registry[id] + local atlas = m.atlases and m.atlases[atlas_idx + 1] + return atlas and atlas.diffuse_texture_handle or nil +end + +function M.atlas_tile_size_px(atlas_idx, map_id) + local id = map_id or current_map_id + if not id then error("maps.atlas_tile_size_px: no current map") end + local m = map_registry[id] + local atlas = m.atlases and m.atlases[atlas_idx + 1] + return atlas and atlas.tile_size_px or nil +end + +function M.atlas_tile_uv(atlas_idx, slot, map_id) + local id = map_id or current_map_id + if not id then error("maps.atlas_tile_uv: no current map") end + local m = map_registry[id] + local atlas = m.atlases and m.atlases[atlas_idx + 1] + if not atlas or not atlas.tiles then return nil end + local slot_idx = atlas_slot_index(atlas) + local tile_id = slot_idx[slot] + local tile = tile_id and atlas.tiles[tile_id] + return tile and tile.uv or nil +end + function M.has_layer(layer_name, map_id) local id = map_id or current_map_id if not id then error("maps.has_layer: no current map") end diff --git a/manifest.lib b/manifest.lib index 6f71f74..bf04fce 100644 --- a/manifest.lib +++ b/manifest.lib @@ -1 +1 @@ -{"id":"lib-core.maps","version":"0.5.3","api_min":"0.1"} +{"id":"lib-core.maps","version":"0.5.4","api_min":"0.1"}