Browse Source

Add option to run the project with visible collision shapes and navigation (#312)

Co-authored-by: Hugo Locurcio <[email protected]>
Anton Vakhtel 3 năm trước cách đây
mục cha
commit
547b92ad80

+ 14 - 0
package.json

@@ -47,6 +47,10 @@
 				"command": "godot-tool.run_project",
 				"command": "godot-tool.run_project",
 				"title": "Godot Tools: Run workspace as Godot project"
 				"title": "Godot Tools: Run workspace as Godot project"
 			},
 			},
+			{
+				"command": "godot-tool.run_project_debug",
+				"title": "Godot Tools: Run workspace as Godot project with visible collision shapes and navigation meshes"
+			},
 			{
 			{
 				"command": "godot-tool.list_native_classes",
 				"command": "godot-tool.list_native_classes",
 				"title": "Godot Tools: List native classes of godot"
 				"title": "Godot Tools: List native classes of godot"
@@ -141,6 +145,16 @@
 					"type": "number",
 					"type": "number",
 					"default": 10,
 					"default": 10,
 					"description": "How many times the client will attempt to reconnect"
 					"description": "How many times the client will attempt to reconnect"
+				},
+				"godot_tools.force_visible_collision_shapes": {
+					"type": "boolean",
+					"default": false,
+					"description": "Force the project to run with visible collision shapes"
+				},
+				"godot_tools.force_visible_nav_mesh": {
+					"type": "boolean",
+					"default": false,
+					"description": "Force the project to run with visible navigation meshes"
 				}
 				}
 			}
 			}
 		},
 		},

+ 13 - 4
src/debugger/server_controller.ts

@@ -98,7 +98,17 @@ export class ServerController {
 
 
 		if (launch_instance) {
 		if (launch_instance) {
 			let godot_path: string = utils.get_configuration("editor_path", "godot");
 			let godot_path: string = utils.get_configuration("editor_path", "godot");
-			let executable_line = `"${godot_path}" --path "${project_path}" --remote-debug ${address}:${port}`;
+			const force_visible_collision_shapes = utils.get_configuration("force_visible_collision_shapes", false);
+			const force_visible_nav_mesh = utils.get_configuration("force_visible_nav_mesh", false);
+			let visible_collision_shapes_param = "";
+			let visible_nav_mesh_param = "";
+			if (force_visible_collision_shapes) {
+				visible_collision_shapes_param = " --debug-collisions";
+			}
+			if (force_visible_nav_mesh) {
+				visible_nav_mesh_param = " --debug-navigation";
+			}
+			let executable_line = `"${godot_path}" --path "${project_path}" --remote-debug ${address}:${port}""${visible_collision_shapes_param}""${visible_nav_mesh_param}`;
 			if (launch_scene) {
 			if (launch_scene) {
 				let filename = "";
 				let filename = "";
 				if (scene_file) {
 				if (scene_file) {
@@ -266,9 +276,8 @@ export class ServerController {
 		if (breakpoints.length > 0) {
 		if (breakpoints.length > 0) {
 			output += " --breakpoints ";
 			output += " --breakpoints ";
 			breakpoints.forEach((bp, i) => {
 			breakpoints.forEach((bp, i) => {
-				output += `${this.breakpoint_path(project_path, bp.file)}:${bp.line}${
-					i < breakpoints.length - 1 ? "," : ""
-				}`;
+				output += `${this.breakpoint_path(project_path, bp.file)}:${bp.line}${i < breakpoints.length - 1 ? "," : ""
+					}`;
 			});
 			});
 		}
 		}
 
 

+ 1 - 1
src/extension.ts

@@ -11,7 +11,7 @@ export function activate(context: ExtensionContext) {
 }
 }
 
 
 export function deactivate(): Thenable<void> {
 export function deactivate(): Thenable<void> {
-	return new Promise((resolve, reject) => {
+	return new Promise<void>((resolve, reject) => {
 		tools.deactivate();
 		tools.deactivate();
 		resolve();
 		resolve();
 	});
 	});

+ 28 - 25
src/godot-tools.ts

@@ -27,11 +27,14 @@ export class GodotTools {
 	}
 	}
 
 
 	public activate() {
 	public activate() {
-		vscode.commands.registerCommand("godot-tool.open_editor", ()=>{
-			this.open_workspace_with_editor("-e").catch(err=>vscode.window.showErrorMessage(err));
+		vscode.commands.registerCommand("godot-tool.open_editor", () => {
+			this.open_workspace_with_editor("-e").catch(err => vscode.window.showErrorMessage(err));
 		});
 		});
-		vscode.commands.registerCommand("godot-tool.run_project", ()=>{
-			this.open_workspace_with_editor().catch(err=>vscode.window.showErrorMessage(err));
+		vscode.commands.registerCommand("godot-tool.run_project", () => {
+			this.open_workspace_with_editor().catch(err => vscode.window.showErrorMessage(err));
+		});
+		vscode.commands.registerCommand("godot-tool.run_project_debug", () => {
+			this.open_workspace_with_editor("--debug-collisions --debug-navigation").catch(err => vscode.window.showErrorMessage(err));
 		});
 		});
 		vscode.commands.registerCommand("godot-tool.check_status", this.check_client_status.bind(this));
 		vscode.commands.registerCommand("godot-tool.check_status", this.check_client_status.bind(this));
 		vscode.commands.registerCommand("godot-tool.set_scene_file", this.set_scene_file.bind(this));
 		vscode.commands.registerCommand("godot-tool.set_scene_file", this.set_scene_file.bind(this));
@@ -39,7 +42,7 @@ export class GodotTools {
 		this.connection_status.text = "$(sync) Initializing";
 		this.connection_status.text = "$(sync) Initializing";
 		this.connection_status.command = "godot-tool.check_status";
 		this.connection_status.command = "godot-tool.check_status";
 		this.connection_status.show();
 		this.connection_status.show();
-		
+
 		this.reconnection_attempts = 0;
 		this.reconnection_attempts = 0;
 		this.client.connect_to_server();
 		this.client.connect_to_server();
 	}
 	}
@@ -57,7 +60,7 @@ export class GodotTools {
 				valid = (fs.existsSync(cfg) && fs.statSync(cfg).isFile());
 				valid = (fs.existsSync(cfg) && fs.statSync(cfg).isFile());
 			}
 			}
 			if (valid) {
 			if (valid) {
-				this.run_editor(`--path "${this.workspace_dir}" ${params}`).then(()=>resolve()).catch(err=>{
+				this.run_editor(`--path "${this.workspace_dir}" ${params}`).then(() => resolve()).catch(err => {
 					reject(err);
 					reject(err);
 				});
 				});
 			} else {
 			} else {
@@ -75,7 +78,7 @@ export class GodotTools {
 		else {
 		else {
 			scene_config = right_clicked_scene_path
 			scene_config = right_clicked_scene_path
 		}
 		}
-		
+
 		set_configuration("scene_file_config", scene_config);
 		set_configuration("scene_file_config", scene_config);
 	}
 	}
 
 
@@ -86,13 +89,13 @@ export class GodotTools {
 				const is_powershell_path = (path?: string) => {
 				const is_powershell_path = (path?: string) => {
 					const POWERSHELL = "powershell.exe";
 					const POWERSHELL = "powershell.exe";
 					const POWERSHELL_CORE = "pwsh.exe";
 					const POWERSHELL_CORE = "pwsh.exe";
-					return path && (path.endsWith(POWERSHELL) || path.endsWith(POWERSHELL_CORE)); 
+					return path && (path.endsWith(POWERSHELL) || path.endsWith(POWERSHELL_CORE));
 				};
 				};
 				const escape_command = (cmd: string) => {
 				const escape_command = (cmd: string) => {
 					const cmdEsc = `"${cmd}"`;
 					const cmdEsc = `"${cmd}"`;
 					if (process.platform === "win32") {
 					if (process.platform === "win32") {
 						const shell_plugin = vscode.workspace.getConfiguration("terminal.integrated.shell");
 						const shell_plugin = vscode.workspace.getConfiguration("terminal.integrated.shell");
-						
+
 						if (shell_plugin) {
 						if (shell_plugin) {
 							const shell = shell_plugin.get<string>("windows");
 							const shell = shell_plugin.get<string>("windows");
 							if (shell) {
 							if (shell) {
@@ -103,7 +106,7 @@ export class GodotTools {
 								}
 								}
 							}
 							}
 						}
 						}
-							
+
 						const POWERSHELL_SOURCE = "PowerShell"
 						const POWERSHELL_SOURCE = "PowerShell"
 						const default_profile = vscode.workspace.getConfiguration("terminal.integrated.defaultProfile");
 						const default_profile = vscode.workspace.getConfiguration("terminal.integrated.defaultProfile");
 						if (default_profile) {
 						if (default_profile) {
@@ -113,7 +116,7 @@ export class GodotTools {
 									return `&${cmdEsc}`;
 									return `&${cmdEsc}`;
 								}
 								}
 								const profiles = vscode.workspace.getConfiguration("terminal.integrated.profiles.windows");
 								const profiles = vscode.workspace.getConfiguration("terminal.integrated.profiles.windows");
-								const profile = profiles.get<{source?: string, path?: string}>(profile_name);
+								const profile = profiles.get<{ source?: string, path?: string }>(profile_name);
 								if (profile) {
 								if (profile) {
 									if (POWERSHELL_SOURCE === profile.source || is_powershell_path(profile.path)) {
 									if (POWERSHELL_SOURCE === profile.source || is_powershell_path(profile.path)) {
 										return `&${cmdEsc}`;
 										return `&${cmdEsc}`;
@@ -145,19 +148,19 @@ export class GodotTools {
 			editorPath = editorPath.replace("${workspaceRoot}", this.workspace_dir);
 			editorPath = editorPath.replace("${workspaceRoot}", this.workspace_dir);
 			if (!fs.existsSync(editorPath) || !fs.statSync(editorPath).isFile()) {
 			if (!fs.existsSync(editorPath) || !fs.statSync(editorPath).isFile()) {
 				vscode.window.showOpenDialog({
 				vscode.window.showOpenDialog({
-						openLabel: "Run",
-						filters: process.platform === "win32" ? {"Godot Editor Binary": ["exe", "EXE"]} : undefined
-					}).then((uris: vscode.Uri[])=> {
-						if (!uris) {
-							return;
-						}
-						let path = uris[0].fsPath;
-						if (!fs.existsSync(path) || !fs.statSync(path).isFile()) {
-							reject("Invalid editor path to run the project");
-						} else {
-							run_godot(path, params);
-							set_configuration("editor_path", path);
-						}
+					openLabel: "Run",
+					filters: process.platform === "win32" ? { "Godot Editor Binary": ["exe", "EXE"] } : undefined
+				}).then((uris: vscode.Uri[]) => {
+					if (!uris) {
+						return;
+					}
+					let path = uris[0].fsPath;
+					if (!fs.existsSync(path) || !fs.statSync(path).isFile()) {
+						reject("Invalid editor path to run the project");
+					} else {
+						run_godot(path, params);
+						set_configuration("editor_path", path);
+					}
 				});
 				});
 			} else {
 			} else {
 				run_godot(editorPath, params);
 				run_godot(editorPath, params);
@@ -244,7 +247,7 @@ export class GodotTools {
 				this.client.connect_to_server();
 				this.client.connect_to_server();
 			} else if (item == 'Open Godot Editor') {
 			} else if (item == 'Open Godot Editor') {
 				this.client.status = ClientStatus.PENDING;
 				this.client.status = ClientStatus.PENDING;
-				this.open_workspace_with_editor("-e").then(()=>{
+				this.open_workspace_with_editor("-e").then(() => {
 					setTimeout(() => {
 					setTimeout(() => {
 						this.reconnection_attempts = 0;
 						this.reconnection_attempts = 0;
 						this.client.connect_to_server();
 						this.client.connect_to_server();