multiselecting entities!
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user