mirror of
				https://github.com/JohnBreaux/Boat-Battle.git
				synced 2025-02-04 12:28:35 +00:00 
			
		
		
		
	Make debug menu fully functional, flesh out command bus.
This commit is contained in:
		
							
								
								
									
										9
									
								
								godot_ship/script/debug/In.gd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								godot_ship/script/debug/In.gd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| extends LineEdit | ||||
|  | ||||
|  | ||||
| # Declare member variables here. Examples: | ||||
| # var a = 2 | ||||
| # var b = "text" | ||||
|  | ||||
| func _on_Debug_clear_line(): | ||||
| 	clear() | ||||
							
								
								
									
										9
									
								
								godot_ship/script/debug/LineEdit.gd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								godot_ship/script/debug/LineEdit.gd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| extends LineEdit | ||||
|  | ||||
|  | ||||
| # Declare member variables here. Examples: | ||||
| # var a = 2 | ||||
| # var b = "text" | ||||
|  | ||||
| func _on_Debug_clear_line(): | ||||
| 	clear() | ||||
							
								
								
									
										10
									
								
								godot_ship/script/debug/Out.gd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								godot_ship/script/debug/Out.gd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| extends TextEdit | ||||
|  | ||||
| # Called when the node enters the scene tree for the first time. | ||||
| func _ready(): | ||||
| 	MessageBus.connect("print_console", self, "_on_Debug_print_text") | ||||
| 	pass # Replace with function body. | ||||
|  | ||||
|  | ||||
| func _on_Debug_print_text(text): | ||||
| 	insert_text_at_cursor(text) | ||||
| @@ -15,6 +15,10 @@ var menu_velocity = 4 | ||||
| var menu_hidden = Transform2D(Vector2(1,0), Vector2(0,1), Vector2(0,-170)) | ||||
| var menu_active = Transform2D(Vector2(1,0), Vector2(0,1), Vector2(0,   0)) | ||||
|  | ||||
| # signals | ||||
| signal clear_line | ||||
| signal print_text(text) | ||||
|  | ||||
| # Called when the node enters the scene tree for the first time. | ||||
| func _ready(): | ||||
| 	 | ||||
| @@ -33,31 +37,42 @@ func _process(delta): | ||||
| 	 | ||||
| 	debug_canvas.set_transform(menu_hidden.interpolate_with(menu_active, menu_position)) | ||||
|  | ||||
| func _unhandled_input(event): | ||||
| func _input(event): | ||||
| 	if event.is_action_pressed("ui_debug"): | ||||
| 		# open debug menu | ||||
| 		debug_active = !debug_active; | ||||
|  | ||||
| func _on_LineEdit_text_entered(line): | ||||
| 	emit_signal("clear_line") | ||||
| 	debug_print_line("") | ||||
| 	var command = line.split(' ', true, 1) | ||||
| 	if command.size() > 0: | ||||
| 		print("match ", command) | ||||
| 		match command[0]: | ||||
| 			"open": | ||||
| 			"start": | ||||
| 				if command.size() > 1: | ||||
| 					MessageBus.emit_signal("change_scene", command[1]) | ||||
| 					debug_print_line("start '" + command[1] + "'\n".c_unescape()) | ||||
| 				else: | ||||
| 					debug_print_line("Usage: open scene") | ||||
| 					debug_print_line("Usage: start scene") | ||||
| 			"kill": | ||||
| 				if command.size() > 1: | ||||
| 				if command.size() > 1 and command[1] != "Debug": | ||||
| 					MessageBus.emit_signal("kill_scene", command[1]) | ||||
| 					debug_print_line("kill '" + command[1] + "'\n".c_unescape()) | ||||
| 				else: | ||||
| 					debug_print_line("Usage: kill scene") | ||||
| 			"restart": | ||||
| 				MessageBus.emit_signal("return_to_title") | ||||
| 	else: | ||||
| 		pass | ||||
| 			"print": | ||||
| 				if command.size() > 1: | ||||
| 					debug_print_line(command[1].c_unescape()) | ||||
| 			"raw_emit": | ||||
| 				var mbus_signal = command[1].split(' ', true, 1) | ||||
| 				match mbus_signal.size(): | ||||
| 					2: MessageBus.emit_signal(mbus_signal[0], mbus_signal[1]) | ||||
| 					1: MessageBus.emit_signal(mbus_signal[0]) | ||||
| 					0: debug_print_line( "Usage: raw_emit signal [value]\n") | ||||
| 			_: | ||||
| 				debug_print_line("BY YOUR COMMAND.\n") | ||||
|  | ||||
| func debug_print_line(string): | ||||
| 	debug_output.set_line(debug_line, string) | ||||
| 	debug_line += 1 | ||||
| 	emit_signal("print_text", string.c_unescape()) | ||||
|   | ||||
| @@ -28,12 +28,20 @@ func _ready(): | ||||
| func _on_scene_start(scene): | ||||
| 	print ("_on_scene_start(",scene,")") | ||||
| 	match scene: | ||||
| 		"Singleplayer": add_child (gameplay.instance()) | ||||
| 		"Multiplayer":   | ||||
| 		"Singleplayer":  | ||||
| 			add_child (gameplay.instance()) | ||||
| 			return true | ||||
| 		"Multiplayer":  | ||||
| 			add_child (gameplay.instance()) | ||||
| 			# add_child (multiplayercontroller.instance()) | ||||
| 		"Options":      add_child (options.instance()) | ||||
| 		"Title":        add_child (title_screen.instance()) | ||||
| 			return true | ||||
| 		"Options":  | ||||
| 			add_child (options.instance()) | ||||
| 			return true | ||||
| 		"Title":  | ||||
| 			add_child (title_screen.instance()) | ||||
| 			return true | ||||
| 		 | ||||
|  | ||||
| # Kills all child nodes with name matching `scene` | ||||
| func _on_scene_kill(scene): | ||||
| @@ -42,6 +50,8 @@ func _on_scene_kill(scene): | ||||
| 	for i in range (c.size()): | ||||
| 		if c[i].name == scene: | ||||
| 			c[i].queue_free() | ||||
| 			return true | ||||
| 	return false | ||||
|  | ||||
| # Quits | ||||
| func _on_quit_request(): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user