From f4824f5e7e6cee12bec602f3240770945a73d043 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 6 Dec 2024 17:13:59 +0100 Subject: add more fetching functions to ComponentManager --- src/crepe/manager/ComponentManager.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/crepe/manager/ComponentManager.cpp') diff --git a/src/crepe/manager/ComponentManager.cpp b/src/crepe/manager/ComponentManager.cpp index 80cf8b4..44774d9 100644 --- a/src/crepe/manager/ComponentManager.cpp +++ b/src/crepe/manager/ComponentManager.cpp @@ -1,4 +1,5 @@ #include "../api/GameObject.h" +#include "../api/Metadata.h" #include "../types.h" #include "../util/Log.h" @@ -61,3 +62,16 @@ GameObject ComponentManager::new_object(const string & name, const string & tag, void ComponentManager::set_persistent(game_object_id_t id, bool persistent) { this->persistent[id] = persistent; } + +set ComponentManager::get_objects_by_name(const string & name) const { + return this->get_objects_by_predicate([name](const Metadata & data) { + return data.name == name; + }); +} + +set ComponentManager::get_objects_by_tag(const string & tag) const { + return this->get_objects_by_predicate([tag](const Metadata & data) { + return data.tag == tag; + }); +} + -- cgit v1.2.3 From f3009ab8f0785a54d3fd83c0d758c8ebd901adda Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sat, 7 Dec 2024 14:19:26 +0100 Subject: `make format` --- src/crepe/manager/ComponentManager.cpp | 11 ++++------- src/crepe/manager/ComponentManager.h | 5 +++-- src/crepe/manager/ComponentManager.hpp | 11 +++++++---- src/test/ECSTest.cpp | 1 - src/test/ScriptECSTest.cpp | 5 ++--- src/test/ScriptSceneTest.cpp | 1 - src/test/ScriptTest.cpp | 1 - 7 files changed, 16 insertions(+), 19 deletions(-) (limited to 'src/crepe/manager/ComponentManager.cpp') diff --git a/src/crepe/manager/ComponentManager.cpp b/src/crepe/manager/ComponentManager.cpp index 44774d9..df30d27 100644 --- a/src/crepe/manager/ComponentManager.cpp +++ b/src/crepe/manager/ComponentManager.cpp @@ -64,14 +64,11 @@ void ComponentManager::set_persistent(game_object_id_t id, bool persistent) { } set ComponentManager::get_objects_by_name(const string & name) const { - return this->get_objects_by_predicate([name](const Metadata & data) { - return data.name == name; - }); + return this->get_objects_by_predicate( + [name](const Metadata & data) { return data.name == name; }); } set ComponentManager::get_objects_by_tag(const string & tag) const { - return this->get_objects_by_predicate([tag](const Metadata & data) { - return data.tag == tag; - }); + return this->get_objects_by_predicate( + [tag](const Metadata & data) { return data.tag == tag; }); } - diff --git a/src/crepe/manager/ComponentManager.h b/src/crepe/manager/ComponentManager.h index 4e53954..685cae5 100644 --- a/src/crepe/manager/ComponentManager.h +++ b/src/crepe/manager/ComponentManager.h @@ -1,10 +1,10 @@ #pragma once #include +#include #include #include #include -#include #include "../Component.h" #include "../types.h" @@ -156,7 +156,8 @@ public: private: template - std::set get_objects_by_predicate(const std::function & pred) const; + std::set + get_objects_by_predicate(const std::function & pred) const; template RefVector get_components_by_ids(const std::set & ids) const; diff --git a/src/crepe/manager/ComponentManager.hpp b/src/crepe/manager/ComponentManager.hpp index 52df368..9e70865 100644 --- a/src/crepe/manager/ComponentManager.hpp +++ b/src/crepe/manager/ComponentManager.hpp @@ -101,7 +101,8 @@ RefVector ComponentManager::get_components_by_id(game_object_id_t id) const { type_index type = typeid(T); if (!this->components.contains(type)) return {}; - const by_id_index>> & components_by_id = this->components.at(type); + const by_id_index>> & components_by_id + = this->components.at(type); if (id >= components_by_id.size()) return {}; RefVector out = {}; @@ -151,7 +152,8 @@ RefVector ComponentManager::get_components_by_type() const { } template -std::set ComponentManager::get_objects_by_predicate(const std::function & pred) const { +std::set +ComponentManager::get_objects_by_predicate(const std::function & pred) const { using namespace std; set objects = {}; @@ -168,9 +170,10 @@ std::set ComponentManager::get_objects_by_predicate(const std: } template -RefVector ComponentManager::get_components_by_ids(const std::set & ids) const { +RefVector +ComponentManager::get_components_by_ids(const std::set & ids) const { using namespace std; - + RefVector out = {}; for (game_object_id_t id : ids) { RefVector components = get_components_by_id(id); diff --git a/src/test/ECSTest.cpp b/src/test/ECSTest.cpp index ed5341e..af2b7b0 100644 --- a/src/test/ECSTest.cpp +++ b/src/test/ECSTest.cpp @@ -466,4 +466,3 @@ TEST_F(ECSTest, ComponentsByTag) { EXPECT_EQ(objects.size(), 3); } } - diff --git a/src/test/ScriptECSTest.cpp b/src/test/ScriptECSTest.cpp index 4477e55..1ec33ba 100644 --- a/src/test/ScriptECSTest.cpp +++ b/src/test/ScriptECSTest.cpp @@ -4,8 +4,8 @@ #include #include -#include #include +#include #include #include @@ -32,8 +32,7 @@ TEST_F(ScriptECSTest, GetOwnComponent) { TEST_F(ScriptECSTest, GetOwnComponents) { const unsigned COUNT = 4; - for (unsigned i = 0; i < COUNT; i++) - entity.add_component(); + for (unsigned i = 0; i < COUNT; i++) entity.add_component(); MyScript & script = this->script; RefVector components = script.get_components(); diff --git a/src/test/ScriptSceneTest.cpp b/src/test/ScriptSceneTest.cpp index 8e849c1..2568049 100644 --- a/src/test/ScriptSceneTest.cpp +++ b/src/test/ScriptSceneTest.cpp @@ -28,4 +28,3 @@ TEST_F(ScriptSceneTest, Default) { script.set_next_scene(non_default_value); EXPECT_EQ(non_default_value, scene_manager.next_scene); } - diff --git a/src/test/ScriptTest.cpp b/src/test/ScriptTest.cpp index b0b2546..acdae70 100644 --- a/src/test/ScriptTest.cpp +++ b/src/test/ScriptTest.cpp @@ -73,4 +73,3 @@ TEST_F(ScriptTest, UpdateInactive) { system.update(); } } - -- cgit v1.2.3