multiselecting entities!
This commit is contained in:
parent
5bcf25a461
commit
ef632d50ee
@ -17,8 +17,9 @@ editor = {
|
||||
function stepEditor()
|
||||
|
||||
animateTiles()
|
||||
|
||||
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))
|
||||
if editor.multiselect.sweeping and not editor.multiselect.active then
|
||||
print("multiselect enabled")
|
||||
@ -220,7 +221,9 @@ function doEditorEdit()
|
||||
else
|
||||
if Keybind:checkDown(Keybind.editor.entity_select) then
|
||||
deselectSpawns()
|
||||
selectSpawns(mouse_x,mouse_y)
|
||||
if editor.multiselect.box then
|
||||
selectSpawns(editor.multiselect.box)
|
||||
end
|
||||
end
|
||||
if Keybind:checkDown(Keybind.editor.entity_move) then
|
||||
moveSpawns(mouse_x,mouse_y)
|
||||
@ -369,13 +372,13 @@ end
|
||||
|
||||
function drawEditorRooms()
|
||||
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")
|
||||
end
|
||||
end
|
||||
|
||||
function drawEditorMultiselect()
|
||||
love.graphics.setColor(100,100,50,1)
|
||||
love.graphics.setColor(0,1,1,1)
|
||||
editor.multiselect.box:draw("line")
|
||||
end
|
||||
|
||||
@ -387,4 +390,3 @@ function doEditorMultiselect()
|
||||
editor.multiselect.box.max = mousept
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -20,7 +20,10 @@ function deselectSpawns()
|
||||
end
|
||||
end
|
||||
|
||||
function selectSpawns(x,y)
|
||||
function selectSpawns(rect)
|
||||
local select_rect = rect:clone()
|
||||
select_rect:fix()
|
||||
|
||||
for _, spawn in pairs(LoadedObjects.Spawns) do
|
||||
|
||||
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 right = spawn.args[1] - Camera.pos.x + offset_x
|
||||
local bottom = spawn.args[2] - Camera.pos.y + offset_y
|
||||
local x = (x / game.scale)
|
||||
local y = (y / game.scale)
|
||||
if x >= left and y >= top and x <= right and y <= bottom then
|
||||
|
||||
local spawn_rect = Rect:fromCoords(left, top, right, bottom)
|
||||
if spawn_rect:overlapsRect(select_rect) then
|
||||
spawn.selected = true
|
||||
end
|
||||
|
||||
@ -47,16 +50,22 @@ function selectSpawns(x,y)
|
||||
end
|
||||
|
||||
function moveSpawns(x,y)
|
||||
local difference_x = nil
|
||||
local difference_y = nil
|
||||
local move_x = nil
|
||||
local move_y = nil
|
||||
for _, spawn in pairs(LoadedObjects.Spawns) do
|
||||
if spawn.selected then
|
||||
if difference_x == nil then
|
||||
difference_x = math.floor((x/game.scale)+Camera.pos.x) - spawn.args[1]
|
||||
difference_y = math.floor((y/game.scale)+Camera.pos.y) - spawn.args[2]
|
||||
local 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]
|
||||
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
|
||||
spawn.args[1] = spawn.args[1] + difference_x
|
||||
spawn.args[2] = spawn.args[2] + difference_y
|
||||
end
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user