feat(map-editor): paint actions + LMB/RMB routing for Cell-Tile
paint_cell_material_at and erase_cell_material_at wrap maps.set_cell_material with a mark_dirty. The canvas-click dispatch in M.handle_click and the per-frame drag handler both route through these actions when state.mode == "cell-tile". Self- test t10 confirms a paint round-trips through maps.get_cell_material. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
37
init.lua
37
init.lua
@@ -305,6 +305,19 @@ local actions = (function()
|
|||||||
state.mark_dirty()
|
state.mark_dirty()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- 0.3.1: Cell-Tile mode paint actions. Write the per-cell material
|
||||||
|
-- flag via lib-core.maps; the renderer's 47-blob branch picks the
|
||||||
|
-- slot.
|
||||||
|
function M.paint_cell_material_at(cell_x, cell_y)
|
||||||
|
maps.set_cell_material(state.get_active_layer(), cell_x, cell_y, true)
|
||||||
|
state.mark_dirty()
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.erase_cell_material_at(cell_x, cell_y)
|
||||||
|
maps.set_cell_material(state.get_active_layer(), cell_x, cell_y, false)
|
||||||
|
state.mark_dirty()
|
||||||
|
end
|
||||||
|
|
||||||
-- =====================================================================
|
-- =====================================================================
|
||||||
-- Hotkey-driven actions
|
-- Hotkey-driven actions
|
||||||
-- =====================================================================
|
-- =====================================================================
|
||||||
@@ -1586,6 +1599,21 @@ local function self_test()
|
|||||||
engine.test.equals(state.get_mode(), "direct", "t12: cycle cell -> direct")
|
engine.test.equals(state.get_mode(), "direct", "t12: cycle cell -> direct")
|
||||||
state.cycle_mode()
|
state.cycle_mode()
|
||||||
engine.test.equals(state.get_mode(), "auto-tile", "t12: cycle direct -> auto")
|
engine.test.equals(state.get_mode(), "auto-tile", "t12: cycle direct -> auto")
|
||||||
|
|
||||||
|
-- t10: paint_cell_material_at writes the flag readable by
|
||||||
|
-- maps.get_cell_material; cell-tile mode dispatches LMB to it.
|
||||||
|
state.set_mode("cell-tile")
|
||||||
|
local layer = state.get_active_layer()
|
||||||
|
-- Clear first to avoid pollution from earlier tests
|
||||||
|
if maps.get_cell_material(layer, 5, 5) then
|
||||||
|
maps.set_cell_material(layer, 5, 5, false)
|
||||||
|
end
|
||||||
|
actions.paint_cell_material_at(5, 5)
|
||||||
|
engine.test.equals(maps.get_cell_material(layer, 5, 5), true,
|
||||||
|
"t10: paint_cell_material_at sets the flag")
|
||||||
|
actions.erase_cell_material_at(5, 5)
|
||||||
|
engine.test.equals(maps.get_cell_material(layer, 5, 5), false,
|
||||||
|
"t10: erase_cell_material_at clears the flag")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- =====================================================================
|
-- =====================================================================
|
||||||
@@ -1723,6 +1751,15 @@ function update(ctx, dt)
|
|||||||
if snap then
|
if snap then
|
||||||
actions.paint_vertex_at(snap.vx, snap.vy, dp == "paint")
|
actions.paint_vertex_at(snap.vx, snap.vy, dp == "paint")
|
||||||
end
|
end
|
||||||
|
elseif state.get_mode() == "cell-tile" then
|
||||||
|
local cell = state.get_mouse_cell()
|
||||||
|
if cell then
|
||||||
|
if dp == "paint" then
|
||||||
|
actions.paint_cell_material_at(cell.x, cell.y)
|
||||||
|
else
|
||||||
|
actions.erase_cell_material_at(cell.x, cell.y)
|
||||||
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
local cell = state.get_mouse_cell()
|
local cell = state.get_mouse_cell()
|
||||||
if cell then
|
if cell then
|
||||||
|
|||||||
Reference in New Issue
Block a user