multiselecting entities!

This commit is contained in:
lustlion 2022-03-13 10:38:20 +01:00
parent 5bcf25a461
commit ef632d50ee
2 changed files with 30 additions and 19 deletions

View File

@ -15,10 +15,11 @@ editor = {
} }
function stepEditor() function stepEditor()
animateTiles() animateTiles()
local osweep = editor.multiselect.sweeping local osweep = editor.multiselect.sweeping
editor.multiselect.sweeping = love.mouse.isDown(2) editor.multiselect.sweeping = Keybind:checkDown(Keybind.editor.entity_select)
frameDebug("sweeping: "..tostring(editor.multiselect.sweeping)) frameDebug("sweeping: "..tostring(editor.multiselect.sweeping))
if editor.multiselect.sweeping and not editor.multiselect.active then if editor.multiselect.sweeping and not editor.multiselect.active then
print("multiselect enabled") print("multiselect enabled")
@ -30,7 +31,7 @@ function stepEditor()
if editor.multiselect.active then if editor.multiselect.active then
doEditorMultiselect() doEditorMultiselect()
end end
if Keybind:checkPressed(Keybind.editor.room_mode) then if Keybind:checkPressed(Keybind.editor.room_mode) then
if love.keyboard.isDown("lshift") then if love.keyboard.isDown("lshift") then
editor.room_mode = "delete" editor.room_mode = "delete"
@ -220,7 +221,9 @@ function doEditorEdit()
else else
if Keybind:checkDown(Keybind.editor.entity_select) then if Keybind:checkDown(Keybind.editor.entity_select) then
deselectSpawns() deselectSpawns()
selectSpawns(mouse_x,mouse_y) if editor.multiselect.box then
selectSpawns(editor.multiselect.box)
end
end end
if Keybind:checkDown(Keybind.editor.entity_move) then if Keybind:checkDown(Keybind.editor.entity_move) then
moveSpawns(mouse_x,mouse_y) moveSpawns(mouse_x,mouse_y)
@ -369,14 +372,14 @@ end
function drawEditorRooms() function drawEditorRooms()
for _, room in pairs(LoadedObjects.Rooms) do for _, room in pairs(LoadedObjects.Rooms) do
love.graphics.setColor(0,0,100,1) love.graphics.setColor(0,0,1,1)
room:asRect():draw("line") room:asRect():draw("line")
end end
end end
function drawEditorMultiselect() function drawEditorMultiselect()
love.graphics.setColor(100,100,50,1) love.graphics.setColor(0,1,1,1)
editor.multiselect.box:draw("line") editor.multiselect.box:draw("line")
end end
function doEditorMultiselect() function doEditorMultiselect()
@ -387,4 +390,3 @@ function doEditorMultiselect()
editor.multiselect.box.max = mousept editor.multiselect.box.max = mousept
end end
end end

View File

@ -20,7 +20,10 @@ function deselectSpawns()
end end
end end
function selectSpawns(x,y) function selectSpawns(rect)
local select_rect = rect:clone()
select_rect:fix()
for _, spawn in pairs(LoadedObjects.Spawns) do for _, spawn in pairs(LoadedObjects.Spawns) do
local offset_x, offset_y = spawn.archetype.display:getCenteredOffset() local offset_x, offset_y = spawn.archetype.display:getCenteredOffset()
@ -28,9 +31,9 @@ function selectSpawns(x,y)
local top = spawn.args[2] - Camera.pos.y - offset_y local top = spawn.args[2] - Camera.pos.y - offset_y
local right = spawn.args[1] - Camera.pos.x + offset_x local right = spawn.args[1] - Camera.pos.x + offset_x
local bottom = spawn.args[2] - Camera.pos.y + offset_y local bottom = spawn.args[2] - Camera.pos.y + offset_y
local x = (x / game.scale)
local y = (y / game.scale) local spawn_rect = Rect:fromCoords(left, top, right, bottom)
if x >= left and y >= top and x <= right and y <= bottom then if spawn_rect:overlapsRect(select_rect) then
spawn.selected = true spawn.selected = true
end end
@ -47,16 +50,22 @@ function selectSpawns(x,y)
end end
function moveSpawns(x,y) function moveSpawns(x,y)
local difference_x = nil local move_x = nil
local difference_y = nil local move_y = nil
for _, spawn in pairs(LoadedObjects.Spawns) do for _, spawn in pairs(LoadedObjects.Spawns) do
if spawn.selected then if spawn.selected then
if difference_x == nil then local difference_x = math.floor((x/game.scale)+Camera.pos.x) - spawn.args[1]
difference_x = math.floor((x/game.scale)+Camera.pos.x) - spawn.args[1] local difference_y = math.floor((y/game.scale)+Camera.pos.y) - spawn.args[2]
difference_y = math.floor((y/game.scale)+Camera.pos.y) - spawn.args[2] if move_x == nil or Point.abs({x=difference_x,y=difference_y}) < Point.abs({x=move_x,y=move_y}) then
move_x = difference_x
move_y = difference_y
end end
spawn.args[1] = spawn.args[1] + difference_x end
spawn.args[2] = spawn.args[2] + difference_y end
for _, spawn in pairs(LoadedObjects.Spawns) do
if spawn.selected then
spawn.args[1] = spawn.args[1] + move_x
spawn.args[2] = spawn.args[2] + move_y
end end
end end
end end