added function to cancel active prompt added function to add new spawns from editor added keybind for that
This commit is contained in:
		
							parent
							
								
									3d41699d8f
								
							
						
					
					
						commit
						61b8aa883b
					
				| @ -7,39 +7,15 @@ editor = { | ||||
| function stepEditor() | ||||
| 	editor.palette_mode = editor.palette_mode or false | ||||
| 	animateTiles() | ||||
| 	if Keybind:checkPressed(Keybind.editor.room_mode) then | ||||
| 		if love.keyboard.isDown("lshift") then | ||||
| 			editor.room_mode = "delete" | ||||
| 		else | ||||
| 			editor.room_mode = not editor.room_mode | ||||
| 	if Prompt.active_prompt == nil then | ||||
| 		if Keybind:checkPressed(Keybind.editor.room_mode) then | ||||
| 			if love.keyboard.isDown("lshift") then | ||||
| 				editor.room_mode = "delete" | ||||
| 			else | ||||
| 				editor.room_mode = not editor.room_mode | ||||
| 			end | ||||
| 			editor.room_points = {} | ||||
| 		end | ||||
| 		editor.room_points = {} | ||||
| 	end | ||||
| 
 | ||||
| 	if Keybind:checkPressed(Keybind.editor.palette_mode) then | ||||
| 		if editor.palette_mode then | ||||
| 			editor.palette_mode = false | ||||
| 			palette_scroll_x = nil | ||||
| 			palette_scroll_y = nil | ||||
| 		else | ||||
| 			editor.palette_mode = true | ||||
| 			palette_scroll_x = 0 | ||||
| 			palette_scroll_y = 0 | ||||
| 		end | ||||
| 	end | ||||
| 
 | ||||
| 	if Keybind:checkPressed(Keybind.editor.palette_mode) then | ||||
| 		if editor.palette_mode then | ||||
| 			editor.palette_mode = false | ||||
| 			palette_scroll_x = nil | ||||
| 			palette_scroll_y = nil | ||||
| 		else | ||||
| 			editor.palette_mode = true | ||||
| 			palette_scroll_x = 0 | ||||
| 			palette_scroll_y = 0 | ||||
| 		end | ||||
| 	end | ||||
| 
 | ||||
| 
 | ||||
| 		if Keybind:checkPressed(Keybind.editor.palette_mode) then | ||||
| 			if editor.palette_mode then | ||||
| @ -53,6 +29,31 @@ function stepEditor() | ||||
| 			end | ||||
| 		end | ||||
| 
 | ||||
| 		if Keybind:checkPressed(Keybind.editor.palette_mode) then | ||||
| 			if editor.palette_mode then | ||||
| 				editor.palette_mode = false | ||||
| 				palette_scroll_x = nil | ||||
| 				palette_scroll_y = nil | ||||
| 			else | ||||
| 				editor.palette_mode = true | ||||
| 				palette_scroll_x = 0 | ||||
| 				palette_scroll_y = 0 | ||||
| 			end | ||||
| 		end | ||||
| 
 | ||||
| 		if Keybind:checkPressed(Keybind.editor.palette_mode) then | ||||
| 			if editor.palette_mode then | ||||
| 				editor.palette_mode = false | ||||
| 				palette_scroll_x = nil | ||||
| 				palette_scroll_y = nil | ||||
| 			else | ||||
| 				editor.palette_mode = true | ||||
| 				palette_scroll_x = 0 | ||||
| 				palette_scroll_y = 0 | ||||
| 			end | ||||
| 		end | ||||
| 	end | ||||
| 
 | ||||
| 	-- TODO: | ||||
|   -- i changed this but i dont know what was to do here. | ||||
| 	-- - made specific action keybinds | ||||
| @ -237,6 +238,10 @@ function doEditorEdit() | ||||
| 						promptSpawnArchetype() | ||||
| 					elseif Keybind:checkDown(Keybind.editor.entity_modify_data) then | ||||
| 						promptSpawnArgs() | ||||
| 					elseif Keybind:checkDown(Keybind.editor.entity_remove) then | ||||
| 						deleteSpawn() | ||||
| 					elseif Keybind:checkDown(Keybind.editor.entity_new) then | ||||
| 						promptSpawnNew() | ||||
| 					end | ||||
| 				end | ||||
| 			end | ||||
|  | ||||
| @ -129,6 +129,8 @@ function Keybind:default() | ||||
| 	Keybind.editor.entity_move = { keys = {2}} | ||||
| 	Keybind.editor.entity_modify_archetype = { keys = {"t"}} | ||||
| 	Keybind.editor.entity_modify_data = { keys = {"g"}} | ||||
| 	Keybind.editor.entity_remove = { keys = {"delete"}} | ||||
| 	Keybind.editor.entity_new = { keys = {"n"}} | ||||
| 	-- Generic | ||||
| 	Keybind.generic.lclick = { keys = {1}} | ||||
| 	Keybind.generic.rclick = { keys = {2}} | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -24,6 +24,11 @@ Prompt = { | ||||
| 	background_color = {0,0,0,1}, | ||||
| 	active_prompt = nil, | ||||
| } | ||||
| function Prompt:cancelActive() | ||||
| 	if Prompt.active_prompt then | ||||
| 		Prompt.active_prompt.canceled = true | ||||
| 	end | ||||
| end | ||||
| 
 | ||||
| function Prompt:new(o) | ||||
| 	o = o or {} | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user