feat(map-editor): v0.2.0c.2 — palette uses real tile thumbnails

Replaces the placeholder colour swatches with actual atlas sub-tex
draws via the new lib-core.maps 0.5.4 getters:
 - atlas_diffuse_handle(atlas_idx) -> raylib Texture2D handle
 - atlas_tile_uv(atlas_idx, slot)  -> {x, y, w, h} or nil

Renders each slot 1..14 (lib slot 0..13) scaled to fit the swatch
rect with draw_sprite_transform. Falls back to the legacy colour
square + slot-number label when the atlas isn't loaded (headless,
material missing, etc.).

Drives off state.get_active_atlas() (defaults to 0 — fine for the
single-atlas work map; multi-atlas selector is a future slice).

Also bumps lib-core.maps dep 0.5.3 -> 0.5.4.
This commit is contained in:
calic
2026-05-29 01:37:45 +02:00
parent c0a1bcf162
commit 70b841c8d6
2 changed files with 34 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
-- sporel-module-map-editor v0.2.0c.1
-- sporel-module-map-editor v0.2.0c.2
-- Interactive map editor — Rev 4 UX architecture (see design paper
-- 2026-05-28-autotile-blob-styles-design.md §11 + plan stub
-- 2026-05-28-map-editor-blob-v2.md). 0.2.0b adds the bottom palette
@@ -15,6 +15,9 @@
-- 0.2.0c.1 adds drag-paint: LMB-hold strokes a line of paints, RMB-hold
-- a line of erases (both in Auto-Tile and Direct mode). UI clicks on
-- toolbar / palette / side-panel never enter drag-mode.
-- 0.2.0c.2 makes the palette show real tile thumbnails via the new
-- lib-core.maps 0.5.4 atlas-handle / tile-UV getters. Falls back to
-- the legacy colour swatch when atlas isn't loaded.
-- Decal/Entity sub-selectors + Material-Properties modal land in 0.2.0d.
--
-- All editor logic in this single file: engine sandbox only allows
@@ -626,20 +629,42 @@ local ui = (function()
engine.render.draw_text("Palette (slot 1-14)", p.x + 6, p.y + 4, 11,
rgba(COL_TEXT_MUTED, 0xFF))
-- 0.2.0c.2: real tile thumbnails via maps.atlas_tile_uv. Atlas
-- index 0 (single-atlas maps); falls back to the colour swatch
-- if the atlas / tile UV / texture isn't available.
local atlas_idx = state.get_active_atlas()
local tex = maps.atlas_diffuse_handle(atlas_idx)
local selected_slot = state.get_active_tile()
for _, sw in ipairs(palette_swatches_layout()) do
local is_selected = (sw.slot_id == selected_slot)
local is_hover = in_rect(mx, my, sw.x, sw.y, sw.w, sw.h)
-- Swatch body in the per-slot color.
-- Always draw a dark BG so transparent atlas tiles read.
engine.render.draw_rect(sw.x, sw.y, sw.w, sw.h, rgba(0x282830, 0xFF))
-- Tile thumbnail: scale the atlas sub-tex to fit the swatch.
local uv = tex and maps.atlas_tile_uv(atlas_idx, sw.slot_id - 1)
if tex and uv then
local scale_x = sw.w / uv.w
local scale_y = sw.h / uv.h
engine.render.draw_sprite_transform(
tex,
sw.x + sw.w / 2, sw.y + sw.h / 2,
0, scale_x, scale_y,
uv.w / 2, uv.h / 2,
0xFFFFFFFF,
uv.x, uv.y, uv.w, uv.h
)
else
-- Fallback: legacy coloured placeholder.
engine.render.draw_rect(sw.x, sw.y, sw.w, sw.h,
rgba(SWATCH_COLORS[sw.slot_id] or 0x808080, 0xFF))
-- Border: highlighted gold when selected, dim when not.
end
-- Border + label on top.
local border_col = is_selected and COL_SWATCH_SELECTED
or is_hover and COL_TEXT
or COL_SWATCH_BORDER
engine.render.draw_rect_lines(sw.x, sw.y, sw.w, sw.h,
rgba(border_col, 0xFF))
-- Slot number label in the corner.
engine.render.draw_text(tostring(sw.slot_id), sw.x + 4, sw.y + 4, 11,
rgba(COL_TEXT, 0xE0))
end
@@ -826,7 +851,7 @@ input.bind("toggle_cheatsheet", { "i" }) -- 0.2.0a — `i` for Info/help (no
input.bind("flip", { "h" }) -- 0.2.0c
input.bind("reset_transform", { "0" }) -- 0.2.0c
engine.print("map-editor v0.2.0c.1: ready. Tab=mode, I=help, S=save, E=erase, R=rotate, H=flip, 0=reset, ESC=quit")
engine.print("map-editor v0.2.0c.2: ready. Tab=mode, I=help, S=save, E=erase, R=rotate, H=flip, 0=reset, ESC=quit")
-- =====================================================================
-- Frame hooks

View File

@@ -1,6 +1,6 @@
{
"id": "map-editor",
"version": "0.2.0c.1",
"version": "0.2.0c.2",
"kind": "module",
"api": "^0.1",
"ci_frames": 30,
@@ -9,7 +9,7 @@
"blob_rect_stone": "lib-asset.prototype-blob-geom"
},
"deps": [
{"id":"lib-core.maps","version":"0.5.3"},
{"id":"lib-core.maps","version":"0.5.4"},
{"id":"lib-core.render","version":"0.1.0"},
{"id":"lib-core.camera","version":"0.3.0"},
{"id":"lib-core.input","version":"0.4.0"},