diff --git a/init.lua b/init.lua index 4774566..12d67e0 100644 --- a/init.lua +++ b/init.lua @@ -305,6 +305,19 @@ local actions = (function() state.mark_dirty() 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 -- ===================================================================== @@ -1586,6 +1599,21 @@ local function self_test() engine.test.equals(state.get_mode(), "direct", "t12: cycle cell -> direct") state.cycle_mode() 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 -- ===================================================================== @@ -1723,6 +1751,15 @@ function update(ctx, dt) if snap then actions.paint_vertex_at(snap.vx, snap.vy, dp == "paint") 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 local cell = state.get_mouse_cell() if cell then