From 1302e86adcc84770773ca161365d3f9410e14a7c Mon Sep 17 00:00:00 2001 From: spectreseven1138 <44363049+spectreseven1138@users.noreply.github.com> Date: Mon, 14 Mar 2022 23:19:58 +0900 Subject: [PATCH 1/4] Add support for custom resource types --- addons/launchy/plugin.gd | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/addons/launchy/plugin.gd b/addons/launchy/plugin.gd index 12d5729..f9a1141 100644 --- a/addons/launchy/plugin.gd +++ b/addons/launchy/plugin.gd @@ -70,7 +70,7 @@ func handles(object): #When choosing the application to launch, we should probably #go through the entire set of keys to check for if an exact class is found. for type in settings.keys(): - if object.is_class(type): + if object.is_class(type) or get_object_type(object) == type: return true return false @@ -81,8 +81,8 @@ func make_visible(visible): if visible == true: if current_object is Resource: b.res = current_object #Set the launch exe to the most specific class we can get. - if settings.has(current_object.get_class()): - b.exe = settings[current_object.get_class()] + if settings.has(get_object_type(current_object)): + b.exe = settings[get_object_type(current_object)] else: #Exact match not found. Search for a base class. #TODO: Maybe walk the inheretance tree recursively up to find the # subclass which matches the closest to current_object type @@ -90,6 +90,14 @@ func make_visible(visible): if current_object.is_class(type): b.exe = settings[type] +func get_object_type(object: Object): + if object.get_script() != null: + var name: String = object.get_script().resource_path.get_basename().get_file() + if name in settings: + return name + else: + return object.get_class() + func launchConfigPopup(param=null): if param is bool: c.popup_exclusive = param From a85522a1be93c394b23fea9af10e7dc62e6cc53d Mon Sep 17 00:00:00 2001 From: spectreseven1138 <44363049+spectreseven1138@users.noreply.github.com> Date: Tue, 15 Mar 2022 10:11:36 +0900 Subject: [PATCH 2/4] Add check for GDScript class_name --- addons/launchy/plugin.gd | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/addons/launchy/plugin.gd b/addons/launchy/plugin.gd index f9a1141..fdd9d4e 100644 --- a/addons/launchy/plugin.gd +++ b/addons/launchy/plugin.gd @@ -9,6 +9,7 @@ var interface = get_editor_interface() var editor_settings = interface.get_editor_settings() var current_object #currently selected object in the editor var settings = editor_settings.get_setting('editors/external/associations') #Dict +var custom_type_cache: Dictionary = {} const MENU_LABEL = "Launchy: Edit Associations..." @@ -91,10 +92,29 @@ func make_visible(visible): b.exe = settings[type] func get_object_type(object: Object): - if object.get_script() != null: + + var script: Script = object.get_script() + if script != null: + + # Check cache for this object type + if object in custom_type_cache: + return custom_type_cache[script.resource_path] + + if object is GDScript: + + # Parse source code to find class name + var source_code: String = object.get_script().source_code + for line in source_code.split("\n"): + if line.begins_with("class_name "): + custom_type_cache[script.resource_path] = line.trim_prefix("class_name ").strip_edges() + return custom_type_cache[script.resource_path] + + # If script has no class_name, return file name instead var name: String = object.get_script().resource_path.get_basename().get_file() if name in settings: + custom_type_cache[script.resource_path] = name return name + else: return object.get_class() From 1eb3c623f2643cf32f035ebdc1e9e6c17a5f5597 Mon Sep 17 00:00:00 2001 From: spectreseven1138 <44363049+spectreseven1138@users.noreply.github.com> Date: Tue, 15 Mar 2022 10:15:45 +0900 Subject: [PATCH 3/4] Fix cache check --- addons/launchy/plugin.gd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/launchy/plugin.gd b/addons/launchy/plugin.gd index fdd9d4e..2bd98fe 100644 --- a/addons/launchy/plugin.gd +++ b/addons/launchy/plugin.gd @@ -97,7 +97,7 @@ func get_object_type(object: Object): if script != null: # Check cache for this object type - if object in custom_type_cache: + if script.resource_path in custom_type_cache: return custom_type_cache[script.resource_path] if object is GDScript: @@ -110,7 +110,7 @@ func get_object_type(object: Object): return custom_type_cache[script.resource_path] # If script has no class_name, return file name instead - var name: String = object.get_script().resource_path.get_basename().get_file() + var name: String = script.resource_path.get_basename().get_file() if name in settings: custom_type_cache[script.resource_path] = name return name From 4f6b599b0fd6d552ac3587a91629224a1a40b45a Mon Sep 17 00:00:00 2001 From: spectreseven1138 <44363049+spectreseven1138@users.noreply.github.com> Date: Tue, 15 Mar 2022 10:19:05 +0900 Subject: [PATCH 4/4] . --- addons/launchy/plugin.gd | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/addons/launchy/plugin.gd b/addons/launchy/plugin.gd index 2bd98fe..4371c0b 100644 --- a/addons/launchy/plugin.gd +++ b/addons/launchy/plugin.gd @@ -100,11 +100,10 @@ func get_object_type(object: Object): if script.resource_path in custom_type_cache: return custom_type_cache[script.resource_path] - if object is GDScript: + if script is GDScript: - # Parse source code to find class name - var source_code: String = object.get_script().source_code - for line in source_code.split("\n"): + # Parse source code to find class_name + for line in script.source_code.split("\n"): if line.begins_with("class_name "): custom_type_cache[script.resource_path] = line.trim_prefix("class_name ").strip_edges() return custom_type_cache[script.resource_path]