more editor work on handling entity spawns

This commit is contained in:
lustlion
2022-03-10 10:21:10 +01:00
parent 6e76607030
commit 39b65571a0
10 changed files with 91 additions and 8 deletions

View File

@@ -13,3 +13,71 @@ function activateSpawns()
spawn.archetype:new(unpack(spawn.args))
end
end
function selectSpawns(x,y)
for _, spawn in pairs(LoadedObjects.Spawns) do
spawn.selected = nil
local offset_x, offset_y = spawn.archetype.display:getCenteredOffset()
local left = spawn.args[1] - Camera.pos.x - offset_x
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
spawn.selected = true
end
if spawn.selected then
love.graphics.setColor(0,1,1,1)
else
love.graphics.setColor(0,1,0,1)
end
love.graphics.rectangle("fill",left-2,top-2,4,4)
love.graphics.rectangle("fill",right-2,bottom-2,4,4)
love.graphics.setColor(1,1,1,1)
end
end
function drawSpawns()
for _, spawn in pairs(LoadedObjects.Spawns) do
local offset_x, offset_y = spawn.archetype.display:getCenteredOffset()
love.graphics.setColor(1,1,1,1)
spawn.archetype.display:draw(
spawn.args[1] - Camera.pos.x - offset_x,
spawn.args[2] - Camera.pos.y - offset_y
)
if spawn.selected then
love.graphics.setColor(0,1,1,1)
else
love.graphics.setColor(0,1,0,1)
end
love.graphics.rectangle(
"line",
spawn.args[1] - Camera.pos.x - offset_x,
spawn.args[2] - Camera.pos.y - offset_y,
spawn.args[1] - Camera.pos.x + offset_x - (spawn.args[1] - Camera.pos.x - offset_x),
spawn.args[2] - Camera.pos.y + offset_y - (spawn.args[2] - Camera.pos.y - offset_y)
)
if spawn.selected then
local text = ""
for i=1, #spawn.args do
text = text .. tostring(spawn.args[i])..", "
end
love.graphics.print(
spawn.archetype.type,
spawn.args[1] - Camera.pos.x + 20,
spawn.args[2] - Camera.pos.y
)
love.graphics.print(
text,
spawn.args[1] - Camera.pos.x + 20,
spawn.args[2] - Camera.pos.y + 20
)
end
end
end