you can now edit archetype and args of spawns in editor with "t" and "d" when selected, respectively

This commit is contained in:
lustlion 2022-03-10 18:23:47 +01:00
parent 93bfe0bda4
commit dbfae2f74e
4 changed files with 89 additions and 11 deletions

View File

@ -117,6 +117,7 @@ function stepEditor()
editor_mode = not editor_mode
deselectSpawns()
createTileObjects()
restartGame()
end
end
@ -223,6 +224,11 @@ function doEditorEdit()
if Keybind:checkDown(Keybind.generic.rclick) then
moveSpawns(mouse_x,mouse_y)
end
if Keybind:checkDown({keys={"t"}}) then
promptSpawnArchetype()
elseif Keybind:checkDown({keys={"d"}}) then
promptSpawnArgs()
end
end
elseif Keybind:checkPressed(Keybind.generic.lshift) then
expandLevelCanvas(math.sign(expand_h),math.sign(expand_v))

View File

@ -1,3 +1,14 @@
function restartGame()
for _, entity in ipairs(LoadedObjects.Entities) do
if entity.light ~= nil then entity.light:kill() end
entity = nil
end
LoadedObjects.Entities = {}
LoadedObjects.Particles = {}
main_player = Player:new(75,50)
activateSpawns()
end
function stepGame()
setCollisionFlags()
if menu_type == "no" then
@ -33,13 +44,6 @@ function stepGame()
end
if Keybind:checkPressed(Keybind.debug.reposition) then
if not editor_mode then
main_player.pos.x, main_player.pos.y = 75,50
end
for _, entity in pairs(LoadedObjects.Entities) do
if entity.id ~= main_player.id then entity:kill() end
end
activateSpawns()
end
if Keybind:checkPressed(Keybind.debug.reload) then

View File

@ -22,6 +22,7 @@ end
function selectSpawns(x,y)
for _, spawn in pairs(LoadedObjects.Spawns) do
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
@ -54,6 +55,73 @@ function moveSpawns(x,y)
end
end
function promptSpawnArchetype()
if Prompt.active_prompt then
Prompt.active_prompt.canceled = true
end
for _, spawn in pairs(LoadedObjects.Spawns) do
if spawn.selected then
local offset_x, offset_y = spawn.archetype.display:getCenteredOffset()
local text = ""
for i=1, #spawn.args do
if i > 1 then text = text .. ", " end
text = text .. tostring(spawn.args[i])
end
local prompt = Prompt:new({
name = "archetype",
input = spawn.archetype.type,
spawn = spawn,
func = function(prompt)
local arch = spawn.archetype
print("return "..prompt.input)
local f = loadstring("return "..prompt.input)
if f == nil then
spawn.archetype = arch
else
spawn.archetype = f()
end
end,
})
prompt.pos.x = spawn.args[1] - Camera.pos.x - offset_x
prompt.pos.y = spawn.args[2] - Camera.pos.y - offset_y
prompt:activate()
end
end
end
function promptSpawnArgs()
if Prompt.active_prompt then
Prompt.active_prompt.canceled = true
end
for _, spawn in pairs(LoadedObjects.Spawns) do
if spawn.selected then
local offset_x, offset_y = spawn.archetype.display:getCenteredOffset()
local text = ""
for i=1, #spawn.args do
if i > 1 then text = text .. ", " end
text = text .. tostring(spawn.args[i])
end
local prompt = Prompt:new({
name = "args",
input = text,
func = function(prompt)
local f = loadstring("return {"..prompt.input.."}")
if f == nil then
spawn.args = arch
else
spawn.args = f()
end
end,
})
prompt.pos.x = spawn.args[1] - Camera.pos.x - offset_x
prompt.pos.y = spawn.args[2] - Camera.pos.y - offset_y
prompt:activate()
end
end
end
function drawSpawns()
for _, spawn in pairs(LoadedObjects.Spawns) do
local offset_x, offset_y = spawn.archetype.display:getCenteredOffset()
@ -63,6 +131,7 @@ function drawSpawns()
spawn.args[2] - Camera.pos.y - offset_y
)
if spawn.selected then
love.graphics.setColor(0,1,1,1)
else

View File

@ -9,7 +9,7 @@ local function backspace(text)
-- so we couldn't do string.sub(text, 1, -2).
return string.sub(text, 1, byteoffset - 1)
end
return ""
end
@ -20,7 +20,7 @@ Prompt = {
name = "input",
canceled = false,
closing = false,
active_prompt = nil,
}
@ -44,7 +44,7 @@ function Prompt:keypressed(key, scancode, isrepeat)
end
function Prompt:update()
end
function Prompt:textinput(text)
@ -65,4 +65,3 @@ local test_prompt = Prompt:new()
assert(test_prompt.name == "input")
test_prompt.name = "foobar"
assert(Prompt.name == "input")