diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/include/turns/core/fwd.hpp | 2 | ||||
| -rw-r--r-- | core/include/turns/core/participant.hpp | 22 | ||||
| -rw-r--r-- | core/include/turns/core/turn_order.hpp | 2 | ||||
| -rw-r--r-- | core/src/init.cpp | 2 | ||||
| -rw-r--r-- | core/src/participant.cpp | 19 | ||||
| -rw-r--r-- | core/src/turn_order.cpp | 6 | ||||
| -rw-r--r-- | core/tests/participant.cpp | 24 | ||||
| -rw-r--r-- | core/tests/turn_order.cpp | 12 |
8 files changed, 44 insertions, 45 deletions
diff --git a/core/include/turns/core/fwd.hpp b/core/include/turns/core/fwd.hpp index 1646d4b..612e8c8 100644 --- a/core/include/turns/core/fwd.hpp +++ b/core/include/turns/core/fwd.hpp @@ -7,7 +7,7 @@ namespace turns::core { enum struct disposition : std::uint8_t; - struct participant; + struct Participant; struct turn_order; } // namespace turns::core diff --git a/core/include/turns/core/participant.hpp b/core/include/turns/core/participant.hpp index a7eb98d..2c02b1b 100644 --- a/core/include/turns/core/participant.hpp +++ b/core/include/turns/core/participant.hpp @@ -14,15 +14,15 @@ namespace turns::core { - struct participant : Glib::Object + struct Participant : Glib::Object { - auto static create(Glib::ustring name, float priority, disposition disposition) -> Glib::RefPtr<participant>; - auto static create(nlohmann::json const & serialized) -> Glib::RefPtr<participant>; + auto static create(Glib::ustring name, float priority, disposition disposition) -> Glib::RefPtr<Participant>; + auto static create(nlohmann::json const & serialized) -> Glib::RefPtr<Participant>; - participant(); - participant(Glib::ustring name, float priority, disposition disposition); + Participant(); + Participant(Glib::ustring name, float priority, disposition disposition); - auto operator<=>(participant const & other) const noexcept -> std::partial_ordering; + auto operator<=>(Participant const & other) const noexcept -> std::partial_ordering; auto property_disposition(this auto && self); auto property_is_active(this auto && self); @@ -40,27 +40,27 @@ namespace turns::core Glib::Property<float> m_priority{*this, "priority", 0.0f}; }; - auto participant::property_disposition(this auto && self) + auto Participant::property_disposition(this auto && self) { return self.m_disposition.get_proxy(); } - auto participant::property_is_active(this auto && self) + auto Participant::property_is_active(this auto && self) { return self.m_is_active.get_proxy(); } - auto participant::property_is_defeated(this auto && self) + auto Participant::property_is_defeated(this auto && self) { return self.m_is_defeated.get_proxy(); } - auto participant::property_name(this auto && self) + auto Participant::property_name(this auto && self) { return self.m_name.get_proxy(); } - auto participant::property_priority(this auto && self) + auto Participant::property_priority(this auto && self) { return self.m_priority.get_proxy(); } diff --git a/core/include/turns/core/turn_order.hpp b/core/include/turns/core/turn_order.hpp index 5e38d0c..6a0ee43 100644 --- a/core/include/turns/core/turn_order.hpp +++ b/core/include/turns/core/turn_order.hpp @@ -24,7 +24,7 @@ namespace turns::core struct turn_order : Gio::ListModel, Glib::Object { - using value_type = Glib::RefPtr<participant>; + using value_type = Glib::RefPtr<Participant>; using container_type = std::vector<value_type>; using iterator = container_type::iterator; using const_iterator = container_type::const_iterator; diff --git a/core/src/init.cpp b/core/src/init.cpp index 258aceb..3991248 100644 --- a/core/src/init.cpp +++ b/core/src/init.cpp @@ -8,7 +8,7 @@ namespace turns::core auto register_types() -> void { - static_cast<void>(participant{}); + static_cast<void>(Participant{}); static_cast<void>(turn_order{}); } diff --git a/core/src/participant.cpp b/core/src/participant.cpp index 9b0ec51..d4b3835 100644 --- a/core/src/participant.cpp +++ b/core/src/participant.cpp @@ -12,16 +12,15 @@ #include <compare> #include <string> -#include <typeinfo> namespace turns::core { - auto participant::create(Glib::ustring name, float priority, core::disposition disposition) -> Glib::RefPtr<participant> + auto Participant::create(Glib::ustring name, float priority, core::disposition disposition) -> Glib::RefPtr<Participant> { - return Glib::make_refptr_for_instance(new participant{name, priority, disposition}); + return Glib::make_refptr_for_instance(new Participant{name, priority, disposition}); } - auto participant::create(nlohmann::json const & serialized) -> Glib::RefPtr<participant> + auto Participant::create(nlohmann::json const & serialized) -> Glib::RefPtr<Participant> { auto disposition = serialized.value("disposition", disposition::neutral); auto priority = serialized.value("priority", 0.0f); @@ -35,26 +34,26 @@ namespace turns::core return instance; } - participant::participant() - : Glib::ObjectBase{typeid(participant)} + Participant::Participant() + : Glib::ObjectBase{"TurnsParticipant"} , Glib::Object{} { } - participant::participant(Glib::ustring name, float priority, core::disposition disposition) - : participant() + Participant::Participant(Glib::ustring name, float priority, core::disposition disposition) + : Participant() { m_name = name; m_priority = priority; m_disposition = disposition; } - auto participant::operator<=>(participant const & other) const noexcept -> std::partial_ordering + auto Participant::operator<=>(Participant const & other) const noexcept -> std::partial_ordering { return m_priority <=> other.m_priority; } - auto participant::serialize() -> nlohmann::json + auto Participant::serialize() -> nlohmann::json { return nlohmann::json{ {"disposition", m_disposition}, diff --git a/core/src/turn_order.cpp b/core/src/turn_order.cpp index d43ac7f..ef7bde6 100644 --- a/core/src/turn_order.cpp +++ b/core/src/turn_order.cpp @@ -102,7 +102,7 @@ namespace turns::core auto turn_order::add(Glib::ustring const & name, float priority, disposition disposition) -> void { - auto entry = participant::create(name, priority, disposition); + auto entry = Participant::create(name, priority, disposition); entry->property_priority().signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &turn_order::handle_priority_changed), entry)); auto position = std::distance(m_data.cbegin(), insert(entry)); items_changed(position, 0, 1); @@ -220,7 +220,7 @@ namespace turns::core m_data.clear(); auto participants = from.value("participants", std::vector<nlohmann::json>{}); auto factory = [](auto s) { - return participant::create(s); + return Participant::create(s); }; auto inserter = std::bind(&turn_order::insert, this, _1); std::ranges::for_each(participants | std::views::transform(factory), inserter); @@ -256,7 +256,7 @@ namespace turns::core auto turn_order::get_item_type_vfunc() -> GType { - return participant::get_type(); + return Participant::get_type(); } auto turn_order::get_n_items_vfunc() -> unsigned diff --git a/core/tests/participant.cpp b/core/tests/participant.cpp index ed7b435..8c7c230 100644 --- a/core/tests/participant.cpp +++ b/core/tests/participant.cpp @@ -30,7 +30,7 @@ namespace turns::core::tests SECTION("Can be constructed using default ctor") { - auto instance = participant{}; + auto instance = Participant{}; REQUIRE(instance.property_name() == ""); REQUIRE(instance.property_priority() == 0); REQUIRE(instance.property_disposition() == disposition::neutral); @@ -40,7 +40,7 @@ namespace turns::core::tests SECTION("Can be constructed using ctor") { - auto instance = participant{name, priority, disposition}; + auto instance = Participant{name, priority, disposition}; REQUIRE(instance.property_name() == name); REQUIRE(instance.property_priority() == priority); REQUIRE(instance.property_disposition() == disposition); @@ -50,7 +50,7 @@ namespace turns::core::tests SECTION("Can be constructed using factory") { - auto instance = participant::create(name, priority, disposition); + auto instance = Participant::create(name, priority, disposition); REQUIRE(instance->property_name() == name); REQUIRE(instance->property_priority() == priority); REQUIRE(instance->property_disposition() == disposition); @@ -60,7 +60,7 @@ namespace turns::core::tests SECTION("Can be constructed using JSON factory", "[json]") { - auto instance = participant::create(json); + auto instance = Participant::create(json); REQUIRE(instance->property_name() == name); REQUIRE(instance->property_priority() == priority); REQUIRE(instance->property_disposition() == disposition); @@ -75,7 +75,7 @@ namespace turns::core::tests auto constexpr priority = 10; auto constexpr disposition = disposition::hostile; - auto instance = participant{name, priority, disposition}; + auto instance = Participant{name, priority, disposition}; SECTION("Setting '::disposition' via proxy changes the 'disposition' value") { @@ -153,11 +153,11 @@ namespace turns::core::tests auto constexpr constructed_name = "Vana Thistletop"; auto constexpr constructed_priority = 17; auto constexpr constructed_disposition = disposition::friendly; - auto instance = participant{constructed_name, constructed_priority, constructed_disposition}; + auto instance = Participant{constructed_name, constructed_priority, constructed_disposition}; SECTION("can be created") { - REQUIRE(participant::create(constructed_name, constructed_priority, constructed_disposition)); + REQUIRE(Participant::create(constructed_name, constructed_priority, constructed_disposition)); } SECTION("allows access to its disposition") @@ -222,9 +222,9 @@ namespace turns::core::tests SECTION("can be compared with another participant") { - auto equivalent_instance = participant{"Equivalent", constructed_priority, constructed_disposition}; - auto lesser_instance = participant{"Lesser", constructed_priority - 1, constructed_disposition}; - auto greater_instance = participant{"Greater", constructed_priority + 1, constructed_disposition}; + auto equivalent_instance = Participant{"Equivalent", constructed_priority, constructed_disposition}; + auto lesser_instance = Participant{"Lesser", constructed_priority - 1, constructed_disposition}; + auto greater_instance = Participant{"Greater", constructed_priority + 1, constructed_disposition}; SECTION("yielding std::partial_ordering::equivalent for itself") { @@ -250,7 +250,7 @@ namespace turns::core::tests TEST_CASE("Serializing a participant") { - auto instance = participant::create("Participant #0", 17.2, disposition::friendly); + auto instance = Participant::create("Participant #0", 17.2, disposition::friendly); auto serialized = instance->serialize(); SECTION("the active state is serialized correctly") @@ -284,7 +284,7 @@ namespace turns::core::tests "is-active": true } )"); - auto instance = participant::create(serialized); + auto instance = Participant::create(serialized); SECTION("the active state is de-serialized correctly") { diff --git a/core/tests/turn_order.cpp b/core/tests/turn_order.cpp index b4958c5..a7a0be0 100644 --- a/core/tests/turn_order.cpp +++ b/core/tests/turn_order.cpp @@ -20,12 +20,12 @@ namespace turns::core::tests THEN("get_type() returns participant::get_type()") { - REQUIRE(instance->get_item_type() == participant::get_type()); + REQUIRE(instance->get_item_type() == Participant::get_type()); } THEN("get_typed_object(0) returns nullptr") { - REQUIRE(instance->get_typed_object<participant>(0) == nullptr); + REQUIRE(instance->get_typed_object<Participant>(0) == nullptr); } THEN("has_next() returns false") @@ -70,7 +70,7 @@ namespace turns::core::tests THEN("get_typed_object(0) returns a non-null pointer") { - REQUIRE(instance->get_typed_object<participant>(0) != nullptr); + REQUIRE(instance->get_typed_object<Participant>(0) != nullptr); } THEN("has_next() returns true") @@ -109,7 +109,7 @@ namespace turns::core::tests THEN("get_typed_object(0) still returns a non-null pointer") { - REQUIRE(instance->get_typed_object<participant>(0) != nullptr); + REQUIRE(instance->get_typed_object<Participant>(0) != nullptr); } THEN("has_next() still returns true") @@ -148,7 +148,7 @@ namespace turns::core::tests THEN("get_typed_object(0) still returns a non-null pointer") { - REQUIRE(instance->get_typed_object<participant>(0) != nullptr); + REQUIRE(instance->get_typed_object<Participant>(0) != nullptr); } THEN("has_next() still returns true") @@ -188,7 +188,7 @@ namespace turns::core::tests THEN("get_typed_object(0) still returns a non-null pointer") { - REQUIRE(instance->get_typed_object<participant>(0) != nullptr); + REQUIRE(instance->get_typed_object<Participant>(0) != nullptr); } THEN("has_next() still returns true") |
