From 6d51d770d62af8286f8de25a5a9212870191a88b Mon Sep 17 00:00:00 2001 From: octod Date: Thu, 8 Feb 2024 16:14:08 +0100 Subject: [PATCH] feat: adds items pool table --- project/.ggs/1.0.0/equipment/weapon_1.tres | 1 + project/.ggs/1.0.0/equipment/weapon_2.tres | 2 +- .../.ggs/1.0.0/items/common_drop_table.tres | 8 ++ project/.ggs/1.0.0/items/items_pool_000.tres | 5 -- project/.ggs/1.0.0/items/items_pool_001.tres | 8 ++ project/.ggs/1.0.0/tags/items.tres | 2 +- .../item_test_ui/items/test_item_001.tres | 6 -- src/editor_plugin/ggs_editor_plugin.cpp | 2 +- .../main_scene/ggs_new_resource_modal.cpp | 4 +- .../item/ggs_equipment_slot_scene.cpp | 17 ++-- .../main_scene/item/ggs_item_pool_scene.cpp | 80 ++++++++++++++++--- .../main_scene/item/ggs_item_pool_scene.h | 7 +- .../tag/ggs_tag_dictionary_item.cpp | 2 +- .../main_scene/tag/ggs_tag_main_scene.cpp | 8 +- src/register_types.cpp | 4 +- src/resource_manager/resource_manager.cpp | 48 +++++------ src/resource_manager/resource_manager.h | 12 +-- src/system/item/equipment_manager.cpp | 6 +- src/system/item/items_pool.cpp | 18 +++-- src/system/tag/tag_manager.cpp | 2 +- 20 files changed, 160 insertions(+), 82 deletions(-) create mode 100644 project/.ggs/1.0.0/items/common_drop_table.tres delete mode 100644 project/.ggs/1.0.0/items/items_pool_000.tres create mode 100644 project/.ggs/1.0.0/items/items_pool_001.tres delete mode 100644 project/demos/item_test_ui/items/test_item_001.tres diff --git a/project/.ggs/1.0.0/equipment/weapon_1.tres b/project/.ggs/1.0.0/equipment/weapon_1.tres index 7d7888b..c60c5f5 100644 --- a/project/.ggs/1.0.0/equipment/weapon_1.tres +++ b/project/.ggs/1.0.0/equipment/weapon_1.tres @@ -3,4 +3,5 @@ [resource] slot_name = &"weapon_1" accepts_items_with_tags = PackedStringArray("type.weapon.1h", "type.weapon.2h") +denies_items_with_tags = PackedStringArray("type.weapon.shield") resource_name = "weapon_1.tres" diff --git a/project/.ggs/1.0.0/equipment/weapon_2.tres b/project/.ggs/1.0.0/equipment/weapon_2.tres index 84b33c2..72cf8b8 100644 --- a/project/.ggs/1.0.0/equipment/weapon_2.tres +++ b/project/.ggs/1.0.0/equipment/weapon_2.tres @@ -2,5 +2,5 @@ [resource] slot_name = &"weapon_2" -accepts_items_with_tags = PackedStringArray("type.weapon.1h") +accepts_items_with_tags = PackedStringArray("type.weapon.1h", "type.weapon.shield") resource_name = "weapon_2.tres" diff --git a/project/.ggs/1.0.0/items/common_drop_table.tres b/project/.ggs/1.0.0/items/common_drop_table.tres new file mode 100644 index 0000000..7794ce0 --- /dev/null +++ b/project/.ggs/1.0.0/items/common_drop_table.tres @@ -0,0 +1,8 @@ +[gd_resource type="ItemsPool" load_steps=2 format=3 uid="uid://cq5poyahoqrmu"] + +[ext_resource type="Item" uid="uid://cmuoe6r8lr7g" path="res://demos/item_test_ui/items/test_item_000.tres" id="1_a8emk"] + +[resource] +items = Array[Item]([ExtResource("1_a8emk"), ExtResource("1_a8emk")]) +pool_name = &"items_pool_001" +resource_name = "common_drop_table" diff --git a/project/.ggs/1.0.0/items/items_pool_000.tres b/project/.ggs/1.0.0/items/items_pool_000.tres deleted file mode 100644 index 50c435a..0000000 --- a/project/.ggs/1.0.0/items/items_pool_000.tres +++ /dev/null @@ -1,5 +0,0 @@ -[gd_resource type="ItemsPool" format=3 uid="uid://bu65750smiusn"] - -[resource] -pool_name = &"items_pool_000" -resource_name = "items_pool_000" diff --git a/project/.ggs/1.0.0/items/items_pool_001.tres b/project/.ggs/1.0.0/items/items_pool_001.tres new file mode 100644 index 0000000..a2b69ba --- /dev/null +++ b/project/.ggs/1.0.0/items/items_pool_001.tres @@ -0,0 +1,8 @@ +[gd_resource type="ItemsPool" load_steps=2 format=3 uid="uid://b2a7tiunflpnh"] + +[ext_resource type="Item" uid="uid://cmuoe6r8lr7g" path="res://demos/item_test_ui/items/test_item_000.tres" id="1_ocre2"] + +[resource] +items = Array[Item]([ExtResource("1_ocre2")]) +pool_name = &"items_pool_002" +resource_name = "items_pool_001" diff --git a/project/.ggs/1.0.0/tags/items.tres b/project/.ggs/1.0.0/tags/items.tres index 9d7f6b1..1776e39 100644 --- a/project/.ggs/1.0.0/tags/items.tres +++ b/project/.ggs/1.0.0/tags/items.tres @@ -1,5 +1,5 @@ [gd_resource type="TagDictionary" format=3 uid="uid://dqcwj5qs8prk0"] [resource] -tags = PackedStringArray("rarity.common", "rarity.magic", "rarity.legendary", "type.weapon.1h", "type.weapon.2h", "type.armor.helm", "type.armor.torso", "type.armor.hands", "type.armor.ring") +tags = PackedStringArray("rarity.common", "rarity.magic", "rarity.legendary", "type.weapon.1h", "type.weapon.2h", "type.armor.helm", "type.armor.torso", "type.armor.hands", "type.armor.ring", "type.weapon.shield") resource_name = "items.tres" diff --git a/project/demos/item_test_ui/items/test_item_001.tres b/project/demos/item_test_ui/items/test_item_001.tres deleted file mode 100644 index 0a05b53..0000000 --- a/project/demos/item_test_ui/items/test_item_001.tres +++ /dev/null @@ -1,6 +0,0 @@ -[gd_resource type="Item" load_steps=2 format=3 uid="uid://d27wbmd1lsxtp"] - -[ext_resource type="ItemSettings" uid="uid://bcdwpcf5776td" path="res://demos/item_test_ui/items/test_item_settings.tres" id="1_n6u0y"] - -[resource] -item_settings = ExtResource("1_n6u0y") diff --git a/src/editor_plugin/ggs_editor_plugin.cpp b/src/editor_plugin/ggs_editor_plugin.cpp index de67767..ac9fad3 100644 --- a/src/editor_plugin/ggs_editor_plugin.cpp +++ b/src/editor_plugin/ggs_editor_plugin.cpp @@ -41,7 +41,7 @@ void GGSEditorPlugin::_enter_tree() ggs_tag_main_scene->set_visible(false); - GGSResourceManager::get_singleton()->ensure_directories(); + ResourceManager::get_singleton()->ensure_directories(); } void GGSEditorPlugin::_exit_tree() diff --git a/src/editor_plugin/main_scene/ggs_new_resource_modal.cpp b/src/editor_plugin/main_scene/ggs_new_resource_modal.cpp index b83a1ed..1e06a43 100644 --- a/src/editor_plugin/main_scene/ggs_new_resource_modal.cpp +++ b/src/editor_plugin/main_scene/ggs_new_resource_modal.cpp @@ -40,7 +40,7 @@ void NewResourceModal::_handle_create_button_pressed() void NewResourceModal::_handle_line_edit_text_changed(String text) { - resource_name_label->set_text(GGSResourceManager::get_resource_name_from_name(text)); + resource_name_label->set_text(ResourceManager::get_resource_name_from_name(text)); } void NewResourceModal::_ready() @@ -59,7 +59,7 @@ void NewResourceModal::_ready() HBoxContainer *h_box_container = memnew(HBoxContainer); VBoxContainer *v_box_container = memnew(VBoxContainer); - GGSResourceManager *resource_manager = GGSResourceManager::get_singleton(); + ResourceManager *resource_manager = ResourceManager::get_singleton(); add_child(v_box_container); diff --git a/src/editor_plugin/main_scene/item/ggs_equipment_slot_scene.cpp b/src/editor_plugin/main_scene/item/ggs_equipment_slot_scene.cpp index d5c7f00..90dea75 100644 --- a/src/editor_plugin/main_scene/item/ggs_equipment_slot_scene.cpp +++ b/src/editor_plugin/main_scene/item/ggs_equipment_slot_scene.cpp @@ -20,7 +20,7 @@ void EquipmentSlotScene::_handle_slot_create_requested(String p_name) return; } - GGSResourceManager *resource_manager = GGSResourceManager::get_singleton(); + ResourceManager *resource_manager = ResourceManager::get_singleton(); Ref slot = resource_manager->create_equipment_slot_resource(p_name); resource_manager->save_resource(slot); @@ -37,7 +37,7 @@ void EquipmentSlotScene::_handle_slot_remove_confirmed() return; } - Error result = GGSResourceManager::get_singleton()->remove_resource(selected_equipment_slot); + Error result = ResourceManager::get_singleton()->remove_resource(selected_equipment_slot); if (result == OK) { @@ -67,7 +67,7 @@ void EquipmentSlotScene::_handle_item_edited() if (slot) { slot->set_slot_name(slot_name); - GGSResourceManager::get_singleton()->save_resource(slot); + ResourceManager::get_singleton()->save_resource(slot); } } @@ -133,8 +133,7 @@ void EquipmentSlotScene::_handle_slot_item_name_edited(String p_new_text) return; } - Variant slot_variant = EquipmentManager::get_singleton()->slots[selected->get_index()]; - EquipmentSlot *slot = cast_to(slot_variant); + EquipmentSlot *slot = cast_to(EquipmentManager::get_singleton()->slots[selected->get_index()]); if (slot == nullptr) { @@ -149,7 +148,7 @@ void EquipmentSlotScene::_handle_slot_item_name_edited(String p_new_text) slot->set_slot_name(p_new_text); selected->set_text(0, p_new_text); - GGSResourceManager::get_singleton()->save_resource(slot); + ResourceManager::get_singleton()->save_resource(slot); } void EquipmentSlotScene::_handle_tags_changed() @@ -192,7 +191,7 @@ void EquipmentSlotScene::_handle_tags_deselected(PackedStringArray p_tags) slots_tree->get_selected()->set_text(tag_selection_mode, new_text); - GGSResourceManager::get_singleton()->save_resource(slot); + ResourceManager::get_singleton()->save_resource(slot); } } @@ -218,15 +217,15 @@ void EquipmentSlotScene::_handle_tags_selected(PackedStringArray p_tags) slots_tree->get_selected()->set_text(tag_selection_mode, new_text); - GGSResourceManager::get_singleton()->save_resource(slot); + ResourceManager::get_singleton()->save_resource(slot); } } void EquipmentSlotScene::_handle_tag_selection_window_closed() { - selected_equipment_slot = nullptr; selected_slot_tag_selection_tree->deselect_all(); selected_slot_tag_selection_window->hide(); + selected_equipment_slot = nullptr; } void EquipmentSlotScene::_render_slots_tree() diff --git a/src/editor_plugin/main_scene/item/ggs_item_pool_scene.cpp b/src/editor_plugin/main_scene/item/ggs_item_pool_scene.cpp index 7b98012..d425e56 100644 --- a/src/editor_plugin/main_scene/item/ggs_item_pool_scene.cpp +++ b/src/editor_plugin/main_scene/item/ggs_item_pool_scene.cpp @@ -5,6 +5,8 @@ #include #include +#include +#include #include #include @@ -17,9 +19,33 @@ void ItemPoolScene::_handle_add_button_pressed() new_resource_modal->popup_centered(); } +void ItemPoolScene::_handle_cell_selected() +{ + TreeItem *selected_item = item_pool_tree->get_selected(); + ResourceManager *resource_manager = ResourceManager::get_singleton(); + TypedArray pools = resource_manager->get_items_pool_resources(); + int index = selected_item->get_index(); + + if (index < 0 || index > pools.size()) + { + return; + } + + Variant v = pools[index]; + Ref pool = cast_to(v); + EditorInterface::get_singleton()->edit_resource(pool); + + Callable callable = Callable(this, "_handle_resource_pool_changed").bind(index); + + if (!pool->is_connected("changed", callable)) + { + pool->connect("changed", callable, ConnectFlags::CONNECT_DEFERRED); + } +} + void ItemPoolScene::_handle_create_requested(String p_resource_name) { - GGSResourceManager *resource_manager = GGSResourceManager::get_singleton(); + ResourceManager *resource_manager = ResourceManager::get_singleton(); resource_manager->create_items_pool_resource(p_resource_name); resource_manager->save_resource(resource_manager->create_items_pool_resource(p_resource_name)); @@ -29,19 +55,43 @@ void ItemPoolScene::_handle_create_requested(String p_resource_name) new_resource_modal->hide(); } +void ItemPoolScene::_handle_resource_pool_changed(int p_item_pool_index) +{ + TreeItem *item = item_pool_tree->get_selected(); + + if (p_item_pool_index < 0 || p_item_pool_index >= item->get_index()) + { + return; + } + + TypedArray pools = ResourceManager::get_singleton()->get_items_pool_resources(); + + if (p_item_pool_index < 0 || p_item_pool_index >= pools.size()) + { + return; + } + + Variant v = pools[p_item_pool_index]; + ItemsPool *pool = cast_to(v); + + if (pool) + { + item->set_text(1, String::num_int64(pool->get_items().size())); + } +} + void ItemPoolScene::_handle_tree_button_pressed(TreeItem *p_item, int p_column, int p_id, int p_mouse_button_index) { if (p_id == TreeButtonId::DELETE) { - GGSResourceManager *resource_manager = GGSResourceManager::get_singleton(); + ResourceManager *resource_manager = ResourceManager::get_singleton(); TypedArray pools = resource_manager->get_items_pool_resources(); ItemsPool *pool = nullptr; for (int i = 0; i < pools.size(); i++) { - Variant pool_variant = pools[i]; - ItemsPool *pool_ptr = cast_to(pool_variant); + ItemsPool *pool_ptr = cast_to(pools[i]); if (pool_ptr && pool_ptr->get_pool_name() == p_item->get_text(0)) { @@ -61,21 +111,23 @@ void ItemPoolScene::_handle_tree_button_pressed(TreeItem *p_item, int p_column, void ItemPoolScene::_bind_methods() { ClassDB::bind_method(D_METHOD("_handle_add_button_pressed"), &ItemPoolScene::_handle_add_button_pressed); + ClassDB::bind_method(D_METHOD("_handle_cell_selected"), &ItemPoolScene::_handle_cell_selected); ClassDB::bind_method(D_METHOD("_handle_create_requested", "p_resource_name"), &ItemPoolScene::_handle_create_requested); + ClassDB::bind_method(D_METHOD("_handle_resource_pool_changed", "p_item_pool_index"), &ItemPoolScene::_handle_resource_pool_changed); ClassDB::bind_method(D_METHOD("_handle_tree_button_pressed", "p_item", "p_column", "p_id", "p_mouse_button_index"), &ItemPoolScene::_handle_tree_button_pressed); + ClassDB::bind_method(D_METHOD("render_tree"), &ItemPoolScene::render_tree); } void ItemPoolScene::render_tree() { item_pool_tree->clear(); - TypedArray pools = GGSResourceManager::get_singleton()->get_items_pool_resources(); + TypedArray pools = ResourceManager::get_singleton()->get_items_pool_resources(); TreeItem *root = item_pool_tree->create_item(); for (int i = 0; i < pools.size(); i++) { - Variant pool = pools[i]; - ItemsPool *pool_ptr = cast_to(pool); + ItemsPool *pool_ptr = cast_to(pools[i]); TreeItem *item = root->create_child(); item->set_text(0, pool_ptr->get_pool_name()); @@ -93,12 +145,12 @@ void ItemPoolScene::_ready() item_pool_tree = memnew(Tree); item_pool_tree->connect("button_clicked", Callable(this, "_handle_tree_button_pressed")); + item_pool_tree->connect("cell_selected", Callable(this, "_handle_cell_selected")); item_pool_tree->set_anchors_and_offsets_preset(PRESET_FULL_RECT); item_pool_tree->set_columns(3); item_pool_tree->set_column_title(0, "Name"); item_pool_tree->set_column_title(1, "Items stored"); item_pool_tree->set_column_title_alignment(1, HorizontalAlignment::HORIZONTAL_ALIGNMENT_CENTER); - item_pool_tree->set_column_title(2, "Actions"); item_pool_tree->set_column_titles_visible(true); item_pool_tree->set_hide_root(true); item_pool_tree->set_h_size_flags(SIZE_EXPAND_FILL); @@ -109,13 +161,23 @@ void ItemPoolScene::_ready() item_pool_label->set_h_size_flags(SIZE_EXPAND_FILL); item_pool_label->set_text("Items pools"); + Button *refresh_button = memnew(Button); + refresh_button->connect("pressed", Callable(this, "render_tree")); + refresh_button->set_button_icon(get_theme_icon("Reload", "EditorIcons")); + refresh_button->set_text(tr("Refresh")); + Button *add_button = memnew(Button); add_button->connect("pressed", Callable(this, "_handle_add_button_pressed")); add_button->set_button_icon(get_theme_icon("Add", "EditorIcons")); - add_button->set_text("Add items pool"); + add_button->set_text(tr("Add items pool")); + + HSeparator *separator = memnew(HSeparator); + separator->set_custom_minimum_size(Size2(4, 8)); HBoxContainer *header = memnew(HBoxContainer); header->add_child(item_pool_label); + header->add_child(refresh_button); + header->add_child(separator); header->add_child(add_button); header->set_anchors_and_offsets_preset(PRESET_FULL_RECT); header->set_h_size_flags(SIZE_EXPAND_FILL); diff --git a/src/editor_plugin/main_scene/item/ggs_item_pool_scene.h b/src/editor_plugin/main_scene/item/ggs_item_pool_scene.h index 3e90ae7..4feb6fa 100644 --- a/src/editor_plugin/main_scene/item/ggs_item_pool_scene.h +++ b/src/editor_plugin/main_scene/item/ggs_item_pool_scene.h @@ -3,6 +3,7 @@ #include #include +#include #include "editor_plugin/main_scene/ggs_new_resource_modal.h" #include "system/item/items_pool.h" @@ -22,8 +23,10 @@ namespace ggs::editor_plugin }; void _handle_add_button_pressed(); - void _handle_create_requested(String p_resource_name); - void _handle_tree_button_pressed(TreeItem *p_item, int p_column, int p_id, int p_mouse_button_index); + void _handle_cell_selected(); + void _handle_create_requested(String p_resource_name); + void _handle_resource_pool_changed(int p_item_pool_index); + void _handle_tree_button_pressed(TreeItem *p_item, int p_column, int p_id, int p_mouse_button_index); protected: static void _bind_methods(); diff --git a/src/editor_plugin/main_scene/tag/ggs_tag_dictionary_item.cpp b/src/editor_plugin/main_scene/tag/ggs_tag_dictionary_item.cpp index 3319700..fac26c5 100644 --- a/src/editor_plugin/main_scene/tag/ggs_tag_dictionary_item.cpp +++ b/src/editor_plugin/main_scene/tag/ggs_tag_dictionary_item.cpp @@ -142,7 +142,7 @@ void TagDictionaryItem::_handle_add_tag_button_pressed() dictionary->add_tag(tag_name); - GGSResourceManager::get_singleton()->save_resource(dictionary); + ResourceManager::get_singleton()->save_resource(dictionary); new_tag_line_edit->set_text(""); tag_tree->clear(); diff --git a/src/editor_plugin/main_scene/tag/ggs_tag_main_scene.cpp b/src/editor_plugin/main_scene/tag/ggs_tag_main_scene.cpp index 3dc4232..242abe5 100644 --- a/src/editor_plugin/main_scene/tag/ggs_tag_main_scene.cpp +++ b/src/editor_plugin/main_scene/tag/ggs_tag_main_scene.cpp @@ -67,7 +67,7 @@ void TagMainScene::render_tag_dictionaries() void TagMainScene::_handle_add_tag_dictionary_requested(String p_name) { - GGSResourceManager *resource_manager = GGSResourceManager::get_singleton(); + ResourceManager *resource_manager = ResourceManager::get_singleton(); resource_manager->save_resource(resource_manager->create_tag_resource(p_name)); TagManager::get_singleton()->load_dictionaries(); @@ -122,7 +122,7 @@ void TagMainScene::_handle_add_tag(TagDictionary *p_dictionary, LineEdit *p_tag_ p_dictionary->add_tag(tag_path); - GGSResourceManager::get_singleton()->save_resource(p_dictionary); + ResourceManager::get_singleton()->save_resource(p_dictionary); render_tag_dictionaries(); } @@ -137,7 +137,7 @@ void TagMainScene::_handle_edit_tag(TagDictionary *p_dictionary, LineEdit *p_tag p_dictionary->replace_tag_path(old_path, tag_path); - GGSResourceManager::get_singleton()->save_resource(p_dictionary); + ResourceManager::get_singleton()->save_resource(p_dictionary); render_tag_dictionaries(); } @@ -146,7 +146,7 @@ void TagMainScene::_handle_delete_tag(TagDictionary *p_dictionary, String p_tag_ { p_dictionary->remove_tag_path(p_tag_path); - GGSResourceManager::get_singleton()->save_resource(p_dictionary); + ResourceManager::get_singleton()->save_resource(p_dictionary); render_tag_dictionaries(); } diff --git a/src/register_types.cpp b/src/register_types.cpp index 517deda..124168c 100644 --- a/src/register_types.cpp +++ b/src/register_types.cpp @@ -106,9 +106,9 @@ void initialize_ggs_module(ModuleInitializationLevel p_level) } else if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) { - ClassDB::register_internal_class(); + ClassDB::register_internal_class(); - Engine::get_singleton()->register_singleton("GGSResourceManager", ggs::GGSResourceManager::get_singleton()); + Engine::get_singleton()->register_singleton("GGSResourceManager", ggs::ResourceManager::get_singleton()); ClassDB::register_internal_class(); ClassDB::register_internal_class(); diff --git a/src/resource_manager/resource_manager.cpp b/src/resource_manager/resource_manager.cpp index 3542f06..fcc01c2 100644 --- a/src/resource_manager/resource_manager.cpp +++ b/src/resource_manager/resource_manager.cpp @@ -10,17 +10,17 @@ using namespace ggs; -GGSResourceManager *GGSResourceManager::instance = nullptr; +ResourceManager *ResourceManager::instance = nullptr; -const char *GGSResourceManager::EQUIPMENT_DIR = "res://.ggs/1.0.0/equipment"; -const char *GGSResourceManager::ITEMS_DIR = "res://.ggs/1.0.0/items"; -const char *GGSResourceManager::TAGS_DIR = "res://.ggs/1.0.0/tags"; +const char *ResourceManager::EQUIPMENT_DIR = "res://.ggs/1.0.0/equipment"; +const char *ResourceManager::ITEMS_DIR = "res://.ggs/1.0.0/items"; +const char *ResourceManager::TAGS_DIR = "res://.ggs/1.0.0/tags"; -void GGSResourceManager::_bind_methods() +void ResourceManager::_bind_methods() { } -Ref GGSResourceManager::create_equipment_slot_resource(String p_file_name) const +Ref ResourceManager::create_equipment_slot_resource(String p_file_name) const { Ref resource = memnew(EquipmentSlot); resource->set_name(p_file_name); @@ -29,7 +29,7 @@ Ref GGSResourceManager::create_equipment_slot_resource(String p_f return resource; } -Ref GGSResourceManager::create_items_pool_resource(String p_file_name) const +Ref ResourceManager::create_items_pool_resource(String p_file_name) const { Ref resource = memnew(ItemsPool); resource->set_name(p_file_name.replace(".tres", "")); @@ -38,7 +38,7 @@ Ref GGSResourceManager::create_items_pool_resource(String p_file_name return resource; } -Ref GGSResourceManager::create_tag_resource(String p_file_name) const +Ref ResourceManager::create_tag_resource(String p_file_name) const { Ref resource = memnew(TagDictionary); resource->set_name(p_file_name.replace(".tres", "")); @@ -46,7 +46,7 @@ Ref GGSResourceManager::create_tag_resource(String p_file_name) c return resource; } -void GGSResourceManager::ensure_directory(const String &p_dir) const +void ResourceManager::ensure_directory(const String &p_dir) const { if (Engine::get_singleton()->is_editor_hint() && !DirAccess::dir_exists_absolute(p_dir)) { @@ -60,7 +60,7 @@ void GGSResourceManager::ensure_directory(const String &p_dir) const } } -void GGSResourceManager::ensure_directories() const +void ResourceManager::ensure_directories() const { if (Engine::get_singleton()->is_editor_hint()) { @@ -70,7 +70,7 @@ void GGSResourceManager::ensure_directories() const } } -Error GGSResourceManager::remove_resource(Ref p_ref) const +Error ResourceManager::remove_resource(Ref p_ref) const { if (Engine::get_singleton()->is_editor_hint()) { @@ -80,22 +80,22 @@ Error GGSResourceManager::remove_resource(Ref p_ref) const return Error::ERR_UNAVAILABLE; } -bool GGSResourceManager::save_resource(Ref p_ref) const +bool ResourceManager::save_resource(Ref p_ref) const { return save_resource(String(EQUIPMENT_DIR), p_ref) == Error::OK; } -bool GGSResourceManager::save_resource(Ref p_ref) const +bool ResourceManager::save_resource(Ref p_ref) const { return save_resource(String(ITEMS_DIR), p_ref) == Error::OK; } -bool GGSResourceManager::save_resource(Ref p_ref) const +bool ResourceManager::save_resource(Ref p_ref) const { return save_resource(String(TAGS_DIR), p_ref) == Error::OK; } -Error GGSResourceManager::save_resource(const String &p_dirname, Ref p_ref) const +Error ResourceManager::save_resource(const String &p_dirname, Ref p_ref) const { if (!Engine::get_singleton()->is_editor_hint()) { @@ -111,7 +111,7 @@ Error GGSResourceManager::save_resource(const String &p_dirname, Ref p return Error::ERR_DOES_NOT_EXIST; } -GGSResourceManager::GGSResourceManager() +ResourceManager::ResourceManager() { if (instance == nullptr) { @@ -119,7 +119,7 @@ GGSResourceManager::GGSResourceManager() } } -TypedArray GGSResourceManager::get_resources(const String &p_dir) const +TypedArray ResourceManager::get_resources(const String &p_dir) const { TypedArray returnvalue = TypedArray(); @@ -137,7 +137,7 @@ TypedArray GGSResourceManager::get_resources(const String &p_dir) cons return returnvalue; } -GGSResourceManager::~GGSResourceManager() +ResourceManager::~ResourceManager() { if (instance == this) { @@ -145,17 +145,17 @@ GGSResourceManager::~GGSResourceManager() } } -GGSResourceManager *GGSResourceManager::get_singleton() +ResourceManager *ResourceManager::get_singleton() { if (instance == nullptr) { - instance = memnew(GGSResourceManager); + instance = memnew(ResourceManager); } return instance; } -String GGSResourceManager::get_resource_name_from_name(const String &p_string) +String ResourceManager::get_resource_name_from_name(const String &p_string) { String normalized = p_string.replace(" ", "_").to_lower(); @@ -167,17 +167,17 @@ String GGSResourceManager::get_resource_name_from_name(const String &p_string) return normalized + ".tres"; } -TypedArray GGSResourceManager::get_equipment_slot_resources() const +TypedArray ResourceManager::get_equipment_slot_resources() const { return get_resources(EQUIPMENT_DIR); } -TypedArray GGSResourceManager::get_items_pool_resources() const +TypedArray ResourceManager::get_items_pool_resources() const { return get_resources(ITEMS_DIR); } -TypedArray GGSResourceManager::get_tag_resources() const +TypedArray ResourceManager::get_tag_resources() const { return get_resources(TAGS_DIR); } diff --git a/src/resource_manager/resource_manager.h b/src/resource_manager/resource_manager.h index 2221f53..0774c4a 100644 --- a/src/resource_manager/resource_manager.h +++ b/src/resource_manager/resource_manager.h @@ -19,9 +19,9 @@ namespace ggs class TagMainScene; } - class GGSResourceManager : public Node + class ResourceManager : public Node { - GDCLASS(GGSResourceManager, Node); + GDCLASS(ResourceManager, Node); static const char *EQUIPMENT_DIR; static const char *ITEMS_DIR; @@ -36,7 +36,7 @@ namespace ggs /// @brief The resource manager's initialization method. static void _bind_methods(); /// @brief The singleton instance of the resource manager. - static GGSResourceManager *instance; + static ResourceManager *instance; /// @brief Creates a new equipment slot resource. /// @return The new equipment slot resource. @@ -65,12 +65,12 @@ namespace ggs Error save_resource(const String &p_dirname, Ref p_ref) const; public: - GGSResourceManager(); - ~GGSResourceManager(); + ResourceManager(); + ~ResourceManager(); /// @brief Gets the singleton instance of the resource manager. /// @return The singleton instance of the resource manager. - static GGSResourceManager *get_singleton(); + static ResourceManager *get_singleton(); static String get_resource_name_from_name(const String &p_string); diff --git a/src/system/item/equipment_manager.cpp b/src/system/item/equipment_manager.cpp index bf88309..b4be620 100644 --- a/src/system/item/equipment_manager.cpp +++ b/src/system/item/equipment_manager.cpp @@ -72,7 +72,7 @@ void EquipmentManager::remove_slot(EquipmentSlot *p_slot) void EquipmentManager::load_slots() { - slots = GGSResourceManager::get_singleton()->get_equipment_slot_resources(); + slots = ResourceManager::get_singleton()->get_equipment_slot_resources(); } EquipmentManager::EquipmentManager() @@ -121,8 +121,8 @@ bool EquipmentManager::has_slot(StringName p_slot_name) const } } } - - return false; + + return false; } EquipmentManager *EquipmentManager::get_singleton() diff --git a/src/system/item/items_pool.cpp b/src/system/item/items_pool.cpp index e1e537b..60a132f 100644 --- a/src/system/item/items_pool.cpp +++ b/src/system/item/items_pool.cpp @@ -13,24 +13,30 @@ void ItemsPool::_bind_methods() ClassDB::bind_method(D_METHOD("set_pool_name", "p_pool_name"), &ItemsPool::set_pool_name); /// binds properties - ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items"), "set_items", "get_items"); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_RESOURCE_TYPE, vformat("%s/%s:%s", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "Item")), "set_items", "get_items"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "pool_name"), "set_pool_name", "get_pool_name"); + + /// signals bindings + ADD_SIGNAL(MethodInfo("items_changed")); + ADD_SIGNAL(MethodInfo("pool_name_changed")); } TypedArray ItemsPool::get_items() const { - return items; + return items; } StringName ItemsPool::get_pool_name() const { - return pool_name; + return pool_name; } void ItemsPool::set_items(const TypedArray &p_items) { items = p_items; - + + emit_signal("items_changed"); + if (Engine::get_singleton()->is_editor_hint()) { emit_changed(); @@ -40,7 +46,9 @@ void ItemsPool::set_items(const TypedArray &p_items) void ItemsPool::set_pool_name(const StringName &p_pool_name) { pool_name = p_pool_name; - + + emit_signal("pool_name_changed"); + if (Engine::get_singleton()->is_editor_hint()) { emit_changed(); diff --git a/src/system/tag/tag_manager.cpp b/src/system/tag/tag_manager.cpp index 55d399c..bdd94f2 100644 --- a/src/system/tag/tag_manager.cpp +++ b/src/system/tag/tag_manager.cpp @@ -131,7 +131,7 @@ void TagManager::_handle_dictionary_tag_replaced(const TagDictionary *p_tag_dict void TagManager::load_dictionaries() { - TypedArray tag_dictionaries = GGSResourceManager::get_singleton()->get_tag_resources(); + TypedArray tag_dictionaries = ResourceManager::get_singleton()->get_tag_resources(); for (int i = 0; i < tag_dictionaries.size(); i++) {