From 0c8946ff2baadcd8b1a58d0d1ef1befb08011213 Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 3 Aug 2022 20:27:05 +0200 Subject: [PATCH] Updated the data manager addon. --- game/addons/data_manager/_data/settings.tres | 107 ------------------ game/addons/data_manager/panels/MainPanel.gd | 5 + .../addons/data_manager/panels/MainPanel.tscn | 3 - .../data_manager/panels/ResourcePanel.gd | 5 + .../data_manager/panels/ResourcePanel.tscn | 19 ++-- game/addons/data_manager/plugin.gd | 18 +-- .../resources/data_manager_addon_settings.gd | 91 +++++++++++++++ game/project.pandemonium | 4 + 8 files changed, 119 insertions(+), 133 deletions(-) delete mode 100644 game/addons/data_manager/_data/settings.tres diff --git a/game/addons/data_manager/_data/settings.tres b/game/addons/data_manager/_data/settings.tres deleted file mode 100644 index 12c3095..0000000 --- a/game/addons/data_manager/_data/settings.tres +++ /dev/null @@ -1,107 +0,0 @@ -[gd_resource type="Resource" load_steps=2 format=2] - -[ext_resource path="res://addons/data_manager/resources/data_manager_addon_settings.gd" type="Script" id=1] - -[resource] -script = ExtResource( 1 ) -folder_count = 25 -folders/0/folder = "." -folders/0/header = "" -folders/0/name = "Root" -folders/0/type = "Resource" -folders/1/folder = "entity_skills" -folders/1/header = "" -folders/1/name = "Skills" -folders/1/type = "EntitySkillData" -folders/2/folder = "entities" -folders/2/header = "" -folders/2/name = "Entities" -folders/2/type = "EntityData" -folders/3/folder = "player_character_data" -folders/3/header = "" -folders/3/name = "Player Characters" -folders/3/type = "EntityData" -folders/4/folder = "entity_classes" -folders/4/header = "" -folders/4/name = "Classes" -folders/4/type = "EntityClassData" -folders/5/folder = "ai" -folders/5/header = "" -folders/5/name = "AI" -folders/5/type = "AIAction" -folders/6/folder = "character_models" -folders/6/header = "Models" -folders/6/name = "Models" -folders/6/type = "MeshDataResource" -folders/7/folder = "character_textures" -folders/7/header = "" -folders/7/name = "Textures" -folders/7/type = "Texture" -folders/8/folder = "spells" -folders/8/header = "Spells" -folders/8/name = "Spells" -folders/8/type = "Spell" -folders/9/folder = "aura_groups" -folders/9/header = "" -folders/9/name = "Aura Groups" -folders/9/type = "AuraGroup" -folders/10/folder = "character_specs" -folders/10/header = "" -folders/10/name = "Specs" -folders/10/type = "CharacterSpec" -folders/11/folder = "effect_data" -folders/11/header = "" -folders/11/name = "Effect Datas" -folders/11/type = "SpellEffectVisual" -folders/12/folder = "world_spells" -folders/12/header = "" -folders/12/name = "World Spells" -folders/12/type = "WorldSpellData" -folders/13/folder = "item_templates" -folders/13/header = "Items" -folders/13/name = "Items" -folders/13/type = "ItemTemplate" -folders/14/folder = "crafting" -folders/14/header = "" -folders/14/name = "Craft Recipes" -folders/14/type = "CraftRecipe" -folders/15/folder = "item_visuals" -folders/15/header = "" -folders/15/name = "Item Visuals" -folders/15/type = "ItemVisual" -folders/16/folder = "planets" -folders/16/header = "World" -folders/16/name = "World" -folders/16/type = "World" -folders/17/folder = "continents" -folders/17/header = "" -folders/17/name = "Continents" -folders/17/type = "Continent" -folders/18/folder = "zones" -folders/18/header = "" -folders/18/name = "Zones" -folders/18/type = "Zone" -folders/19/folder = "sub_zones" -folders/19/header = "" -folders/19/name = "SubZones" -folders/19/type = "SubZone" -folders/20/folder = "dungeons" -folders/20/header = "" -folders/20/name = "Dungeons" -folders/20/type = "DungeonData" -folders/21/folder = "dungeon_rooms" -folders/21/header = "" -folders/21/name = "Dungeon Rooms" -folders/21/type = "DungeonRoomData" -folders/22/folder = "basic_models" -folders/22/header = "" -folders/22/name = "Basic Models" -folders/22/type = "MeshDataResource" -folders/23/folder = "prop_models" -folders/23/header = "" -folders/23/name = "Prop Models" -folders/23/type = "PackedScene" -folders/24/folder = "entity_resources" -folders/24/header = "Entities" -folders/24/name = "Entity Resources" -folders/24/type = "EntityResourceData" diff --git a/game/addons/data_manager/panels/MainPanel.gd b/game/addons/data_manager/panels/MainPanel.gd index 969ca52..7821cf2 100644 --- a/game/addons/data_manager/panels/MainPanel.gd +++ b/game/addons/data_manager/panels/MainPanel.gd @@ -47,6 +47,7 @@ func load_data(): _main_container.add_child(_resource_scene) _resource_scene.owner = _main_container _resource_scene.connect("inspect_data", self, "inspect_data") + _resource_scene.connect("edit_settings", self, "edit_settings") _module_entry_container = get_node(module_entry_container_path) _folder_entry_container = get_node(folder_entry_container_path) @@ -198,6 +199,10 @@ func hide_all() -> void: func inspect_data(var data : Resource) -> void: emit_signal("inspect_data", data) +func edit_settings() -> void: + emit_signal("inspect_data", _settings) + + func set_plugin(plugin : EditorPlugin) -> void: _plugin = plugin diff --git a/game/addons/data_manager/panels/MainPanel.tscn b/game/addons/data_manager/panels/MainPanel.tscn index 9b6c718..ce15728 100644 --- a/game/addons/data_manager/panels/MainPanel.tscn +++ b/game/addons/data_manager/panels/MainPanel.tscn @@ -10,9 +10,6 @@ anchor_bottom = 1.0 size_flags_horizontal = 3 size_flags_vertical = 3 script = ExtResource( 1 ) -__meta__ = { -"_edit_use_anchors_": false -} resource_scene = ExtResource( 3 ) base_folder = "res://data/" main_container = NodePath("HSplitContainer/MarginContainer") diff --git a/game/addons/data_manager/panels/ResourcePanel.gd b/game/addons/data_manager/panels/ResourcePanel.gd index 707e14a..57eaab4 100644 --- a/game/addons/data_manager/panels/ResourcePanel.gd +++ b/game/addons/data_manager/panels/ResourcePanel.gd @@ -2,6 +2,7 @@ tool extends Control signal inspect_data +signal edit_settings export(PackedScene) var resource_row_scene : PackedScene export(PackedScene) var history_row_scene : PackedScene @@ -292,3 +293,7 @@ func search(text : String) -> void: func sort_entries(a, b): return a["id"] < b["id"] + + +func edit_settings(): + emit_signal("edit_settings") diff --git a/game/addons/data_manager/panels/ResourcePanel.tscn b/game/addons/data_manager/panels/ResourcePanel.tscn index 45fea9a..365039f 100644 --- a/game/addons/data_manager/panels/ResourcePanel.tscn +++ b/game/addons/data_manager/panels/ResourcePanel.tscn @@ -12,9 +12,6 @@ anchor_right = 1.0 anchor_bottom = 1.0 script = ExtResource( 5 ) -__meta__ = { -"_edit_use_anchors_": false -} resource_row_scene = ExtResource( 2 ) history_row_scene = ExtResource( 3 ) entry_container_path = NodePath("ResourcePanel/VBoxContainer2/ScrollContainer2/VBoxContainer") @@ -75,21 +72,28 @@ margin_left = 612.0 margin_right = 1024.0 margin_bottom = 600.0 -[node name="Button" type="Button" parent="ResourcePanel/VBoxContainer"] +[node name="Settings" type="Button" parent="ResourcePanel/VBoxContainer"] margin_right = 412.0 margin_bottom = 20.0 size_flags_horizontal = 3 +text = "Settings" + +[node name="Button" type="Button" parent="ResourcePanel/VBoxContainer"] +margin_top = 24.0 +margin_right = 412.0 +margin_bottom = 44.0 +size_flags_horizontal = 3 text = "Clear History" icon = ExtResource( 7 ) [node name="HSeparator" type="HSeparator" parent="ResourcePanel/VBoxContainer"] -margin_top = 24.0 +margin_top = 48.0 margin_right = 412.0 -margin_bottom = 28.0 +margin_bottom = 52.0 size_flags_horizontal = 3 [node name="ScrollContainer" type="ScrollContainer" parent="ResourcePanel/VBoxContainer"] -margin_top = 32.0 +margin_top = 56.0 margin_right = 412.0 margin_bottom = 600.0 size_flags_horizontal = 3 @@ -114,5 +118,6 @@ dialog_text = "Delete?" [connection signal="text_entered" from="ResourcePanel/VBoxContainer2/LineEdit" to="." method="search"] [connection signal="pressed" from="ResourcePanel/VBoxContainer2/CreateButton" to="CreateNamePopup" method="popup"] +[connection signal="pressed" from="ResourcePanel/VBoxContainer/Settings" to="." method="edit_settings"] [connection signal="pressed" from="ResourcePanel/VBoxContainer/Button" to="." method="clear_history"] [connection signal="confirmed" from="DeletePopup" to="." method="delete_confirm"] diff --git a/game/addons/data_manager/plugin.gd b/game/addons/data_manager/plugin.gd index 4b3a338..c1347d7 100644 --- a/game/addons/data_manager/plugin.gd +++ b/game/addons/data_manager/plugin.gd @@ -42,20 +42,6 @@ func get_plugin_name(): func inspect_data(var data : Resource) -> void: get_editor_interface().inspect_object(data) -func ensure_data_dir_exists() -> void: - var dir : Directory = Directory.new() - - if !dir.dir_exists("res://addons/data_manager/_data/"): - dir.make_dir("res://addons/data_manager/_data/") - func load_settings() -> void: - ensure_data_dir_exists() - - var dir : Directory = Directory.new() - - if !dir.file_exists("res://addons/data_manager/_data/settings.tres"): - settings = DataManagerAddonSettings.new() - - ResourceSaver.save("res://addons/data_manager/_data/settings.tres", settings) - else: - settings = ResourceLoader.load("res://addons/data_manager/_data/settings.tres") + settings = DataManagerAddonSettings.new() + settings.load_from_project_settings() diff --git a/game/addons/data_manager/resources/data_manager_addon_settings.gd b/game/addons/data_manager/resources/data_manager_addon_settings.gd index dab1575..9e032ee 100644 --- a/game/addons/data_manager/resources/data_manager_addon_settings.gd +++ b/game/addons/data_manager/resources/data_manager_addon_settings.gd @@ -100,6 +100,27 @@ func _set(property : StringName, val) -> bool: func _get_property_list() -> Array: var props : Array = Array() + props.append({ + "name": "save", + "type": TYPE_NIL, + "hint": PROPERTY_HINT_BUTTON, + "hint_string": "save_to_project_settings", + }) + +# props.append({ +# "name": "convert_to_json", +# "type": TYPE_NIL, +# "hint": PROPERTY_HINT_BUTTON, +# "hint_string": "convert_to_json", +# }) +# +# props.append({ +# "name": "convert_from_json", +# "type": TYPE_NIL, +# "hint": PROPERTY_HINT_BUTTON, +# "hint_string": "convert_from_json", +# }) + props.append({ "name": "folder_count", "type": TYPE_INT, @@ -137,3 +158,73 @@ func set_folder_count(val : int) -> void: emit_changed() property_list_changed_notify() + +func convert_to_json() -> void: + var f : File = File.new() + + f.open("res://addons/data_manager/_data/settings.json", File.WRITE) + f.store_string(get_as_json()) + f.close() + + PLogger.log_message("Saved settings to res://addons/data_manager/_data/settings.json") + +func convert_from_json() -> void: + var f : File = File.new() + + if (!f.file_exists("res://addons/data_manager/_data/settings.json")): + PLogger.log_message("File res://addons/data_manager/_data/settings.json doesn't exist!") + return + + f.open("res://addons/data_manager/_data/settings.json", File.READ) + set_from_json(f.get_as_text()) + f.close() + + PLogger.log_message("Loaded settings from res://addons/data_manager/_data/settings.json") + +func get_as_json() -> String: + var arr : Array + + for i in range(folders.size()): + var s : SettingEntry = folders[i] + + var dict : Dictionary + + dict["folder"] = s.folder + dict["header"] = s.header + dict["name"] = s.name + dict["type"] = s.type + + arr.push_back(dict) + + return to_json(arr); + +func set_from_json(data : String) -> void: + var jpr : JSONParseResult = JSON.parse(data) + + if jpr.error != OK: + PLogger.log_message("DataManagerAddonSettings: set_from_json: Couldn't load data!"); + return + + var arr = jpr.result + + for i in range(arr.size()): + var dict : Dictionary = arr[i] + + var s : SettingEntry = SettingEntry.new() + + s.folder = dict["folder"] + s.header = dict["header"] + s.name = dict["name"] + s.type = dict["type"] + + folders.push_back(s) + +func save_to_project_settings() -> void: + ProjectSettings.set("addons/data_manager/folder_settings", get_as_json()) + +func load_from_project_settings() -> void: + var d : String = ProjectSettings.get("addons/data_manager/folder_settings") + + if d != "": + set_from_json(d) + diff --git a/game/project.pandemonium b/game/project.pandemonium index 8420941..5c06632 100644 --- a/game/project.pandemonium +++ b/game/project.pandemonium @@ -205,6 +205,10 @@ _global_script_class_icons={ } Node="input/actionbar_5_11" +[addons] + +data_manager/folder_settings="[{\"folder\":\".\",\"header\":\"\",\"name\":\"Root\",\"type\":\"Resource\"},{\"folder\":\"entity_skills\",\"header\":\"\",\"name\":\"Skills\",\"type\":\"EntitySkillData\"},{\"folder\":\"entities\",\"header\":\"\",\"name\":\"Entities\",\"type\":\"EntityData\"},{\"folder\":\"player_character_data\",\"header\":\"\",\"name\":\"Player Characters\",\"type\":\"EntityData\"},{\"folder\":\"entity_classes\",\"header\":\"\",\"name\":\"Classes\",\"type\":\"EntityClassData\"},{\"folder\":\"ai\",\"header\":\"\",\"name\":\"AI\",\"type\":\"AIAction\"},{\"folder\":\"character_models\",\"header\":\"Models\",\"name\":\"Models\",\"type\":\"MeshDataResource\"},{\"folder\":\"character_textures\",\"header\":\"\",\"name\":\"Textures\",\"type\":\"Texture\"},{\"folder\":\"spells\",\"header\":\"Spells\",\"name\":\"Spells\",\"type\":\"Spell\"},{\"folder\":\"aura_groups\",\"header\":\"\",\"name\":\"Aura Groups\",\"type\":\"AuraGroup\"},{\"folder\":\"character_specs\",\"header\":\"\",\"name\":\"Specs\",\"type\":\"CharacterSpec\"},{\"folder\":\"effect_data\",\"header\":\"\",\"name\":\"Effect Datas\",\"type\":\"SpellEffectVisual\"},{\"folder\":\"world_spells\",\"header\":\"\",\"name\":\"World Spells\",\"type\":\"WorldSpellData\"},{\"folder\":\"item_templates\",\"header\":\"Items\",\"name\":\"Items\",\"type\":\"ItemTemplate\"},{\"folder\":\"crafting\",\"header\":\"\",\"name\":\"Craft Recipes\",\"type\":\"CraftRecipe\"},{\"folder\":\"item_visuals\",\"header\":\"\",\"name\":\"Item Visuals\",\"type\":\"ItemVisual\"},{\"folder\":\"planets\",\"header\":\"World\",\"name\":\"World\",\"type\":\"World\"},{\"folder\":\"continents\",\"header\":\"\",\"name\":\"Continents\",\"type\":\"Continent\"},{\"folder\":\"zones\",\"header\":\"\",\"name\":\"Zones\",\"type\":\"Zone\"},{\"folder\":\"sub_zones\",\"header\":\"\",\"name\":\"SubZones\",\"type\":\"SubZone\"},{\"folder\":\"dungeons\",\"header\":\"\",\"name\":\"Dungeons\",\"type\":\"DungeonData\"},{\"folder\":\"dungeon_rooms\",\"header\":\"\",\"name\":\"Dungeon Rooms\",\"type\":\"DungeonRoomData\"},{\"folder\":\"basic_models\",\"header\":\"\",\"name\":\"Basic Models\",\"type\":\"MeshDataResource\"},{\"folder\":\"prop_models\",\"header\":\"\",\"name\":\"Prop Models\",\"type\":\"PackedScene\"},{\"folder\":\"entity_resources\",\"header\":\"Entities\",\"name\":\"Entity Resources\",\"type\":\"EntityResourceData\"}]" + [application] config/name="Broken Seals 2DS"