From 331e4cf44c3a64477eb7f033ff955d8164a12adc Mon Sep 17 00:00:00 2001 From: Airyzz <36567925+Airyzz@users.noreply.github.com> Date: Wed, 24 Jan 2024 20:23:54 +1030 Subject: [PATCH 1/6] Load user plugin from pck --- addons/material_maker/engine/loader.gd | 44 ++++++++++++++++++++++++++ material_maker/main_window.gd | 10 +++++- material_maker/main_window.tscn | 2 +- 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd index 579d18c59..ef99d51fd 100644 --- a/addons/material_maker/engine/loader.gd +++ b/addons/material_maker/engine/loader.gd @@ -18,6 +18,50 @@ const SHARED_NODES_DIR : String = "user://shared_nodes" func _ready()-> void: update_predefined_generators() load_external_export_targets() + load_plugins() + +func load_plugins(): + var plugin_dir = DirAccess.open("user://plugins") + var any_plugins_loaded = false + + plugin_dir.list_dir_begin() + var plugin_file_name = plugin_dir.get_next() + while (plugin_file_name != ""): + if plugin_dir.current_is_dir(): + continue + print("Attempting to load plugin: ", plugin_file_name) + var result = ProjectSettings.load_resource_pack("user://plugins/" + plugin_file_name) + if(result): + print("Loaded successfully") + else: + print("Load failed") + + any_plugins_loaded = any_plugins_loaded or result + plugin_file_name = plugin_dir.get_next() + + if not any_plugins_loaded: + return + + var dir = DirAccess.open("res://mm_plugin") + + dir.list_dir_begin() + var file_name = dir.get_next() + + while (file_name != ""): + print("Initialising plugin: ", file_name) + var plugin_scene = "res://mm_plugin/" + file_name + "/plugin.tscn" + print(plugin_scene) + file_name = dir.get_next() + + if dir.current_is_dir(): + if ResourceLoader.exists(plugin_scene) == false: + print("Plugin scene did not exist, this plugin may not be configured correctly") + continue + + var plugin = load(plugin_scene) + var plugin_node = plugin.instantiate() + add_child(plugin_node) + func get_predefined_generators_from_dir(path : String) -> void: var parser diff --git a/material_maker/main_window.gd b/material_maker/main_window.gd index 40ac2fa49..a3641f358 100644 --- a/material_maker/main_window.gd +++ b/material_maker/main_window.gd @@ -219,9 +219,11 @@ func _ready() -> void: if get_current_graph_edit() == null: await get_tree().process_frame new_material() - + update_menus() + plugin_ui_loaded.call_deferred() + var menu_update_requested : bool = false func update_menus() -> void: @@ -229,6 +231,12 @@ func update_menus() -> void: menu_update_requested = true do_update_menus.call_deferred() +func plugin_ui_loaded(): + var children = mm_loader.get_children() + for child in children: + if child.has_method("on_ui_loaded"): + child.on_ui_loaded() + func do_update_menus() -> void: # Create menus var menu_bar_class diff --git a/material_maker/main_window.tscn b/material_maker/main_window.tscn index 18f37d95f..2c1f53901 100644 --- a/material_maker/main_window.tscn +++ b/material_maker/main_window.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=19 format=3 uid="uid://cgfeik04a5qqs"] +[gd_scene load_steps=19 format=3 uid="uid://xycv1evlfpuf"] [ext_resource type="Script" path="res://material_maker/main_window.gd" id="1"] [ext_resource type="Script" path="res://material_maker/main_window_layout.gd" id="2"] From d295586de081f72f9c9c2d9d5b63ea1946f8c5f4 Mon Sep 17 00:00:00 2001 From: Airyzz <36567925+Airyzz@users.noreply.github.com> Date: Wed, 24 Jan 2024 22:15:11 +1030 Subject: [PATCH 2/6] Add a way for plugins to store arbitrary data in the node graph --- addons/material_maker/engine/nodes/gen_graph.gd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/material_maker/engine/nodes/gen_graph.gd b/addons/material_maker/engine/nodes/gen_graph.gd index fed9309f9..e220c1268 100644 --- a/addons/material_maker/engine/nodes/gen_graph.gd +++ b/addons/material_maker/engine/nodes/gen_graph.gd @@ -6,6 +6,7 @@ var label : String = "Graph" var shortdesc = "" var longdesc = "" var connections = [] +var plugin_data = {} var editable : bool = false @@ -525,6 +526,7 @@ func _serialize(data: Dictionary) -> Dictionary: data.shortdesc = shortdesc data.longdesc = longdesc data.nodes = [] + data.plugin_data = plugin_data for c in get_children(): data.nodes.append(c.serialize()) #data.connections = connections_to_compact(connections) @@ -538,6 +540,8 @@ func _deserialize(data : Dictionary) -> void: shortdesc = data.shortdesc if data.has("longdesc"): longdesc = data.longdesc + if data.has("plugin_data"): + plugin_data = data.plugin_data var nodes = data.nodes if data.has("nodes") else [] var connection_array : Array = [] if data.has("connections"): From d07187cbd4c519fb7233174357ebc6ddeb77b17c Mon Sep 17 00:00:00 2001 From: Airyzz <36567925+Airyzz@users.noreply.github.com> Date: Wed, 24 Jan 2024 22:53:17 +1030 Subject: [PATCH 3/6] Update loader.gd --- addons/material_maker/engine/loader.gd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd index ef99d51fd..5b3c7b5dc 100644 --- a/addons/material_maker/engine/loader.gd +++ b/addons/material_maker/engine/loader.gd @@ -22,6 +22,9 @@ func _ready()-> void: func load_plugins(): var plugin_dir = DirAccess.open("user://plugins") + if not plugin_dir: + return + var any_plugins_loaded = false plugin_dir.list_dir_begin() From 520a95c57920c659750dd1f884defa3078be84f2 Mon Sep 17 00:00:00 2001 From: Airyzz <36567925+Airyzz@users.noreply.github.com> Date: Thu, 25 Jan 2024 13:52:00 +1030 Subject: [PATCH 4/6] Move animation export to a separate file so it's callable by user plugin without opening file browser --- material_maker/windows/export_animation/export_animation.gd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/material_maker/windows/export_animation/export_animation.gd b/material_maker/windows/export_animation/export_animation.gd index 8c5b1e5dd..6974f6428 100644 --- a/material_maker/windows/export_animation/export_animation.gd +++ b/material_maker/windows/export_animation/export_animation.gd @@ -88,6 +88,9 @@ func _on_Export_pressed(): dialog.add_filter("*.png;PNG image files") add_child(dialog) var files = await dialog.select_files() + do_export(files) + +func do_export(files): if files.size() > 0: var filename : String = files[0] var size : int = 1 << value_size.size_value From cf70da5593a7a306b62d571ea199079227a8ed0c Mon Sep 17 00:00:00 2001 From: Airyzz <36567925+Airyzz@users.noreply.github.com> Date: Thu, 25 Jan 2024 14:06:27 +1030 Subject: [PATCH 5/6] Update main_window.tscn --- material_maker/main_window.tscn | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/material_maker/main_window.tscn b/material_maker/main_window.tscn index 2c1f53901..7384cca60 100644 --- a/material_maker/main_window.tscn +++ b/material_maker/main_window.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=19 format=3 uid="uid://xycv1evlfpuf"] +[gd_scene load_steps=19 format=3 uid="uid://cgfeik04a5qqs"] [ext_resource type="Script" path="res://material_maker/main_window.gd" id="1"] [ext_resource type="Script" path="res://material_maker/main_window_layout.gd" id="2"] @@ -141,7 +141,6 @@ layout_mode = 2 [node name="Menu" type="HBoxContainer" parent="VBoxContainer/TopBar"] layout_mode = 2 -size_flags_horizontal = 3 [node name="Layout" type="HBoxContainer" parent="VBoxContainer"] layout_mode = 2 From 53e30eece1d7a36ea3eeaa29f11214a373197151 Mon Sep 17 00:00:00 2001 From: Airyzz <36567925+Airyzz@users.noreply.github.com> Date: Sun, 4 Feb 2024 12:29:38 +1030 Subject: [PATCH 6/6] Update library_manager.gd --- material_maker/tools/library_manager/library_manager.gd | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/material_maker/tools/library_manager/library_manager.gd b/material_maker/tools/library_manager/library_manager.gd index 8591c16e8..4521797c2 100644 --- a/material_maker/tools/library_manager/library_manager.gd +++ b/material_maker/tools/library_manager/library_manager.gd @@ -125,7 +125,12 @@ func get_items(filter : String, sorted = false) -> Array: func save_library_list() -> void: var library_list = [] for i in range(2, get_child_count()): - library_list.push_back(get_child(i).library_path) + var path = get_child(i).library_path + + # Libraries loaded via a plugin might not have a file path, so we dont need to save it + if path != "": + library_list.push_back(get_child(i).library_path) + mm_globals.config.set_value(config_section, "libraries", library_list) func has_library(path : String) -> bool: