This commit is contained in:
Your Name 2026-08-06 23:54:49 -04:00
parent 7c7f76b188
commit a9af97925e
12 changed files with 329 additions and 30 deletions

View file

@ -556,39 +556,86 @@ function Room:getCellFromMousePos(mouseX, mouseY)
return cell
end
function Room:attemptDelete(mouseX, mouseY)
function Room:attemptDelete(mouseX, mouseY, color)
local cell = self:getCellFromMousePos(mouseX, mouseY)
for color, player in pairs(self.player) do
if player:occupiesCell(cell) then
self.player[color] = nil
self.colorsPlayerHas[color] = false
end
-- "white" (or nil) deletes every channel; otherwise just the picked one
local colors
if not color or color == "white" then
colors = {"red", "green", "blue"}
else
colors = {color}
end
local entities = {}
for color, entityArray in pairs(self.collideables) do
for index, entity in pairs(entityArray) do
if entity:occupiesCell(cell) then
table.remove(self.collideables[color], index)
for _, c in ipairs(colors) do
-- player
if self.player[c] and self.player[c]:occupiesCell(cell) then
self.player[c] = nil
self.colorsPlayerHas[c] = false
end
-- collidables (iterate backwards so table.remove is safe)
local entityArray = self.collideables[c]
for index = #entityArray, 1, -1 do
if entityArray[index]:occupiesCell(cell) then
table.remove(entityArray, index)
end
end
end
for color, switches in pairs(self.switches) do
for index, switch in pairs(switches) do
if switch:occupiesCell(cell) then
print("assssss occupied scellsll")
table.remove(self.switches[color], index)
-- switches
local switchArray = self.switches[c]
for index = #switchArray, 1, -1 do
if switchArray[index]:occupiesCell(cell) then
table.remove(switchArray, index)
end
end
end
self:tick()
end
function Room:attemptPlace()
local placeImageCache = {}
local function loadPlaceImage(path)
if not placeImageCache[path] then
placeImageCache[path] = love.graphics.newImage(path)
end
return placeImageCache[path]
end
function Room:attemptPlace(name, props, mouseX, mouseY, color)
if not props or not props.sprites then return end
local cell = self:getCellFromMousePos(mouseX, mouseY)
-- "white" (or nil) means every channel; otherwise just the picked channel
local colors
if not color or color == "white" then
colors = {"red", "green", "blue"}
else
colors = {color}
end
-- one generic entity per placed channel; each lives on its own collision
-- layer and the additive blend combines them into full color
for _, c in ipairs(colors) do
local path = props.sprites[c]
if path then
local sprite = loadPlaceImage(path)
local entity
if props.class == "moveable" then
entity = GenericMoveable:new(cell.x, cell.y, c, sprite, name)
else
entity = GenericUnmoveable:new(cell.x, cell.y, c, sprite)
end
self:registerCollidable(entity, {c})
end
end
self:tick()
end
function Room:load(name)
local room = love.filesystem.read("rooms/" .. name .. ".sav")
if not room then
-- no save yet: start with a blank room to build in the editor
print("no save for '" .. name .. "', starting blank")
return
end
self:deserialize(TSerial.unpack(room))
end