added function to cancel active prompt added function to add new spawns from editor added keybind for that
This commit is contained in:
@@ -55,10 +55,64 @@ function moveSpawns(x,y)
|
||||
end
|
||||
end
|
||||
|
||||
function promptSpawnArchetype()
|
||||
if Prompt.active_prompt then
|
||||
Prompt.active_prompt.canceled = true
|
||||
|
||||
function promptSpawnNew()
|
||||
Prompt:cancelActive()
|
||||
local text = ""
|
||||
local prompt = Prompt:new({
|
||||
name = "new spawn",
|
||||
input = text,
|
||||
func = function(prompt)
|
||||
local f = loadstring("return {"..prompt.input.."}")
|
||||
if f ~= nil then
|
||||
local succ, result = pcall(f)
|
||||
local arch = result[1]
|
||||
local args = {}
|
||||
if #result > 1 then
|
||||
for i=2, #result+1 do
|
||||
print("arg #"..i-1)
|
||||
args[i-1] = result[i]
|
||||
end
|
||||
else
|
||||
args = {0,0}
|
||||
end
|
||||
|
||||
print("new entity spawn --",succ)
|
||||
if not succ
|
||||
or checkArchetypeInvalid(arch)
|
||||
then
|
||||
print("invalid input for prompt "..prompt.name)
|
||||
else
|
||||
print("archetype: ",arch.type)
|
||||
print("args: ",unpack(args))
|
||||
addSpawn(arch, unpack(args))
|
||||
end
|
||||
else
|
||||
print("invalid input for prompt "..prompt.name)
|
||||
end
|
||||
end,
|
||||
})
|
||||
prompt.pos.x = 0
|
||||
prompt.pos.y = 10
|
||||
prompt:activate()
|
||||
end
|
||||
|
||||
function deleteSpawn()
|
||||
for i=1, #LoadedObjects.Spawns do
|
||||
if LoadedObjects.Spawns[i]
|
||||
and LoadedObjects.Spawns[i].selected then
|
||||
table.remove(LoadedObjects.Spawns,i)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function checkArchetypeInvalid(arch)
|
||||
return type(arch) ~= "table" or type(arch.type) ~= "string"
|
||||
end
|
||||
|
||||
function promptSpawnArchetype()
|
||||
Prompt:cancelActive()
|
||||
for _, spawn in pairs(LoadedObjects.Spawns) do
|
||||
if spawn.selected then
|
||||
local offset_x, offset_y = spawn.archetype.display:getCenteredOffset()
|
||||
@@ -79,8 +133,7 @@ function promptSpawnArchetype()
|
||||
print("archetype changed --",succ)
|
||||
print("from: ", spawn.archetype.type)
|
||||
if not succ
|
||||
or type(arch) ~= "table"
|
||||
or type(arch.type) ~= "string"
|
||||
or checkArchetypeInvalid(arch)
|
||||
then
|
||||
arch = spawn.archetype
|
||||
end
|
||||
@@ -90,25 +143,27 @@ function promptSpawnArchetype()
|
||||
print("invalid input for prompt "..prompt.name)
|
||||
end
|
||||
end,
|
||||
})
|
||||
prompt.pos.x = (spawn.args[1]-4)*game.scale - Camera.pos.x - offset_x
|
||||
prompt.pos.y = (spawn.args[2]-20)*game.scale - Camera.pos.y - offset_y
|
||||
|
||||
})
|
||||
prompt.pos.x = (spawn.args[1]-4)*game.scale - Camera.pos.x - offset_x
|
||||
prompt.pos.y = (spawn.args[2]-20)*game.scale - Camera.pos.y - offset_y
|
||||
prompt:activate()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function checkArgsAreInvalid(args)
|
||||
function checkArgsInvalid(args)
|
||||
for _, arg in pairs(args) do
|
||||
if arg == nil then return true end
|
||||
-- this is checking the args are not nil variables
|
||||
if arg == nil
|
||||
or arg == ""
|
||||
then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function promptSpawnArgs()
|
||||
if Prompt.active_prompt then
|
||||
Prompt.active_prompt.canceled = true
|
||||
end
|
||||
Prompt:cancelActive()
|
||||
for _, spawn in pairs(LoadedObjects.Spawns) do
|
||||
if spawn.selected then
|
||||
local offset_x, offset_y = spawn.archetype.display:getCenteredOffset()
|
||||
@@ -127,7 +182,7 @@ function promptSpawnArgs()
|
||||
print("args changed --",succ)
|
||||
print("from: ", unpack(args))
|
||||
if not succ
|
||||
or checkArgsAreInvalid(args)
|
||||
or checkArgsInvalid(args)
|
||||
then
|
||||
args = spawn.args
|
||||
end
|
||||
@@ -137,9 +192,9 @@ function promptSpawnArgs()
|
||||
print("invalid input for prompt "..prompt.name)
|
||||
end
|
||||
end,
|
||||
})
|
||||
prompt.pos.x = (spawn.args[1]-4)*game.scale - Camera.pos.x - offset_x
|
||||
prompt.pos.y = (spawn.args[2]-4)*game.scale - Camera.pos.y - offset_y
|
||||
})
|
||||
prompt.pos.x = (spawn.args[1]-4)*game.scale - Camera.pos.x - offset_x
|
||||
prompt.pos.y = (spawn.args[2]-4)*game.scale - Camera.pos.y - offset_y
|
||||
prompt:activate()
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user