Skip to content

Commit

Permalink
chore: removes pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
OctoD committed Feb 12, 2024
1 parent 2f8f93d commit 17e9d31
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,11 @@ void AbilityInspectorPluginEditor::_ready()
button = memnew(Button);
tag_tree = memnew(TagTree);

for (int i = 0; i < tag_manager->dictionaries->size(); i++)
TypedArray<TagDictionary> dictionaries = tag_manager->get_dictionaries();

for (int i = 0; i < dictionaries.size(); i++)
{
Variant variant = tag_manager->dictionaries->operator[](i);
Variant variant = dictionaries[i];
TagDictionary *dictionary = cast_to<TagDictionary>(variant);

if (dictionary != nullptr)
Expand Down
2 changes: 1 addition & 1 deletion src/editor_plugin/docks/tag/tag_docks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void TagDocks::render()
TagDictionary *all_tags = memnew(TagDictionary);
AttributeManager *attribute_manager = AttributeManager::get_singleton();

all_tags->from_many(TagManager::get_singleton()->dictionaries);
all_tags->from_many(TagManager::get_singleton()->get_dictionaries());
all_tags->remove_tags(attribute_manager->get_attributes());

for (int i = 0; i < selected_nodes.size(); i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ void AttributeMainScene::_ready()

void AttributeMainScene::_handle_dictionary_selected(int p_item_index)
{
TypedArray<TagDictionary> *items = TagManager::get_singleton()->dictionaries;
Variant variant = items->operator[](p_item_index);
TypedArray<TagDictionary> items = TagManager::get_singleton()->get_dictionaries();
Variant variant = items[p_item_index];
TagDictionary *tag_dictionary = cast_to<TagDictionary>(variant);

if (tag_dictionary != nullptr)
Expand All @@ -86,17 +86,17 @@ void AttributeMainScene::_handle_dictionary_selected(int p_item_index)

void AttributeMainScene::render()
{
TypedArray<TagDictionary> *items = TagManager::get_singleton()->dictionaries;
TypedArray<TagDictionary> items = TagManager::get_singleton()->get_dictionaries();
String current_value = AttributeProjectSettings::get_attribute_resource_path();

int preselect_index = -1;
int size = items->size();
int size = items.size();

tag_select->clear();

for (int i = 0; i < size; i++)
{
Variant item = items->operator[](i);
Variant item = items[i];
TagDictionary *tag_dictionary = cast_to<TagDictionary>(item);

tag_select->add_item(tag_dictionary->get_path());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ void EquipmentSlotScene::_handle_slot_item_name_edited(String p_new_text)

void EquipmentSlotScene::_handle_tags_changed()
{
TypedArray<TagDictionary> *dictionaries = TagManager::get_singleton()->dictionaries;
TypedArray<TagDictionary> dictionaries = TagManager::get_singleton()->get_dictionaries();

for (int i = 0; i < dictionaries->size(); i++)
for (int i = 0; i < dictionaries.size(); i++)
{
Variant dictionary_variant = dictionaries->operator[](i);
Variant dictionary_variant = dictionaries[i];
TagDictionary *_dictionary = cast_to<TagDictionary>(dictionary_variant);

if (_dictionary)
Expand Down
6 changes: 3 additions & 3 deletions src/editor_plugin/main_scene/tag/ggs_tag_main_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void TagMainScene::render_tag_dictionaries()

tag_manager->load_dictionaries();

TypedArray<TagDictionary> *dictionaries = tag_manager->dictionaries;
TypedArray<TagDictionary> dictionaries = tag_manager->get_dictionaries();
TypedArray<godot::Node> children = _dictionaries_container->get_children();

for (int i = 0; i < _dictionaries_container->get_child_count(); i++)
Expand All @@ -50,7 +50,7 @@ void TagMainScene::render_tag_dictionaries()
}
}

for (int i = 0; i < dictionaries->size(); i++)
for (int i = 0; i < dictionaries.size(); i++)
{
TagDictionaryItem *dict_container = memnew(TagDictionaryItem);

Expand All @@ -60,7 +60,7 @@ void TagMainScene::render_tag_dictionaries()
dict_container->connect("remove_tag_requested", Callable(this, "_handle_remove_tag_requested"));
dict_container->connect("add_tag_requested", Callable(this, "_handle_tag_add_requested"));
dict_container->connect("edit_tag_requested", Callable(this, "_handle_tag_edit_requested"));
dict_container->set_tag_dictionary(cast_to<TagDictionary>(dictionaries->operator[](i)));
dict_container->set_tag_dictionary(cast_to<TagDictionary>(dictionaries[i]));
dict_container->render();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/resource_manager/resource_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ ResourceManager *ResourceManager::get_singleton()
{
if (instance == nullptr)
{
instance = memnew(ResourceManager);
return memnew(ResourceManager);
}

return instance;
Expand Down
2 changes: 1 addition & 1 deletion src/system/attribute/attribute_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ AttributeManager *AttributeManager::get_singleton()
{
if (_singleton == nullptr)
{
_singleton = memnew(AttributeManager);
return memnew(AttributeManager);
}

return _singleton;
Expand Down
2 changes: 1 addition & 1 deletion src/system/item/equipment_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ EquipmentManager *EquipmentManager::get_singleton()
{
if (singleton == nullptr)
{
singleton = memnew(EquipmentManager);
return memnew(EquipmentManager);
}

return singleton;
Expand Down
2 changes: 1 addition & 1 deletion src/system/item/item_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ ItemManager *ItemManager::get_singleton()
{
if (singleton == nullptr)
{
singleton = memnew(ItemManager);
return memnew(ItemManager);
}

return singleton;
Expand Down
6 changes: 3 additions & 3 deletions src/system/tag/tag_dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ void TagDictionary::clear_tags()
emit_changed();
}

void TagDictionary::from_many(const TypedArray<TagDictionary> *p_tag_dictionaries)
void TagDictionary::from_many(const TypedArray<TagDictionary> p_tag_dictionaries)
{
for (int i = 0; i < p_tag_dictionaries->size(); i++)
for (int i = 0; i < p_tag_dictionaries.size(); i++)
{
TagDictionary *x = cast_to<TagDictionary>(p_tag_dictionaries->operator[](i));
TagDictionary *x = cast_to<TagDictionary>(p_tag_dictionaries[i]);
add_tags(x->get_tags());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/system/tag/tag_dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace ggs
void clear_tags();
/// @brief Adds all tags from the tag dictionaries passed to this one.
/// @param p_tag_dictionaries
void from_many(const TypedArray<TagDictionary> *p_tag_dictionaries);
void from_many(const TypedArray<TagDictionary> p_tag_dictionaries);
/// @brief Returns all tags as an array of packed string arrays.
/// @return
TypedArray<PackedStringArray> get_chunks() const;
Expand Down
23 changes: 14 additions & 9 deletions src/system/tag/tag_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ TagManager::TagManager()
{
if (singleton == nullptr)
{
dictionaries = memnew(TypedArray<TagDictionary>);
dictionaries = TypedArray<TagDictionary>();
singleton = this;
}
else
Expand All @@ -172,7 +172,7 @@ TagManager *TagManager::get_singleton()
{
if (singleton == nullptr)
{
singleton = memnew(TagManager);
return memnew(TagManager);
}

return singleton;
Expand Down Expand Up @@ -239,6 +239,11 @@ TypedArray<Node> TagManager::get_child_tagged_nodes(const Node *p_node) const
return output;
}

TypedArray<TagDictionary> TagManager::get_dictionaries() const
{
return TypedArray<TagDictionary>(dictionaries);
}

PackedStringArray TagManager::get_tags(const Node *p_node) const
{
if (p_node != nullptr)
Expand All @@ -253,24 +258,24 @@ int TagManager::add_dictionary(TagDictionary *p_dictionary)
{
if (p_dictionary != nullptr && !has_dictionary(p_dictionary))
{
dictionaries->append(p_dictionary);
dictionaries.append(p_dictionary);

emit_signal("dictionary_added", p_dictionary);
emit_signal("dictionaries_changed");

_bind_dictionary_signals(p_dictionary);

return dictionaries->size();
return dictionaries.size();
}

return dictionaries->size();
return dictionaries.size();
}

bool TagManager::has_dictionary(const TagDictionary *p_dictionary) const
{
if (p_dictionary != nullptr)
{
return dictionaries->has(p_dictionary);
return dictionaries.has(p_dictionary);
}

return false;
Expand Down Expand Up @@ -402,13 +407,13 @@ void TagManager::remove_dictionary(TagDictionary *p_dictionary)
{
if (p_dictionary != nullptr)
{
for (int i = 0; i < dictionaries->size(); i++)
for (int i = 0; i < dictionaries.size(); i++)
{
int64_t index = dictionaries->find(p_dictionary);
int64_t index = dictionaries.find(p_dictionary);

if (index > -1)
{
dictionaries->remove_at(index);
dictionaries.remove_at(index);
emit_signal("dictionary_removed", p_dictionary);
emit_signal("dictionaries_changed");
}
Expand Down
24 changes: 6 additions & 18 deletions src/system/tag/tag_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ using namespace godot;

namespace ggs
{
namespace editor_plugin
{
class AbilityInspectorPluginEditor;
class AttributeMainScene;
class EquipmentSlotScene;
class TagDocks;
class TagMainScene;
}

/// @brief The tag manager node. It is used to manage tags.
class TagManager : public Node
{
Expand Down Expand Up @@ -59,6 +50,9 @@ namespace ggs
/// @param p_node The node to get the tag container from.
/// @return
TypedArray<Node> get_child_tagged_nodes(const Node *p_node) const;
/// @brief Returns the dictionaries
/// @return The dictionaries
TypedArray<TagDictionary> get_dictionaries() const;
/// @brief Gets the tags associated with a node.
/// @param p_node The node to get the tags from.
/// @return The tags associated with the node.
Expand Down Expand Up @@ -96,16 +90,12 @@ namespace ggs
/// @param p_node
/// @param p_tags
void remove_tags(Node *p_node, const PackedStringArray &p_tags);
/// @brief Loads all dictionaries.
void load_dictionaries();
/// @brief Called when the node enters the scene tree for the first time.
void _ready() override;

protected:
friend class editor_plugin::AttributeMainScene;
friend class editor_plugin::AbilityInspectorPluginEditor;
friend class editor_plugin::EquipmentSlotScene;
friend class editor_plugin::TagDocks;
friend class editor_plugin::TagMainScene;

/// @brief Registers all methods that can be called from Godot.
static void _bind_methods();
/// @brief Adds a tag dictionary.
Expand All @@ -120,7 +110,7 @@ namespace ggs
/// @param dictionary The tag dictionary to remove.
void remove_dictionary(TagDictionary *p_dictionary);
/// @brief The tag dictionary.
TypedArray<TagDictionary> *dictionaries;
TypedArray<TagDictionary> dictionaries;

private:
/// @brief Binds all signals of a tag dictionary.
Expand All @@ -146,8 +136,6 @@ namespace ggs
/// @param p_old_tag The old tag.
/// @param p_new_tag The new tag.
void _handle_dictionary_tag_replaced(const TagDictionary *p_tag_dictionary, const String &p_old_tag, const String &p_new_tag);
/// @brief Loads all dictionaries.
void load_dictionaries();
};
}

Expand Down

0 comments on commit 17e9d31

Please sign in to comment.