From 9513f7303ffde9fbda869e346523a23197f4ece9 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 13 May 2025 15:59:02 +0200 Subject: lib: begin TurnOrder implementation --- core/src/disposition.cpp | 51 --------------------- core/src/init.cpp | 20 -------- core/src/participant.cpp | 116 ----------------------------------------------- 3 files changed, 187 deletions(-) delete mode 100644 core/src/disposition.cpp delete mode 100644 core/src/init.cpp delete mode 100644 core/src/participant.cpp (limited to 'core/src') diff --git a/core/src/disposition.cpp b/core/src/disposition.cpp deleted file mode 100644 index 894baed..0000000 --- a/core/src/disposition.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "turns/core/disposition.hpp" - -#include -#include - -#include - -#include -#include - -namespace turns::core -{ - - auto presentation_name_for(Disposition value) -> Glib::ustring - { - switch (value) - { - case Disposition::Neutral: - return _("Neutral"); - case Disposition::Friendly: - return _("Friendly"); - case Disposition::Hostile: - return _("Hostile"); - case Disposition::Secret: - return _("Secret"); - default: - return _("Unknown disposition value"); - } - } - -} // namespace turns::core - -namespace Glib -{ - auto Value::value_type() -> GType - { - auto static is_initialized = std::atomic_flag{false}; - auto static const values = std::array{ - GEnumValue{static_cast(turns::core::Disposition::Neutral), "TURNS_DISPOSITION_NEUTRAL", "neutral" }, - GEnumValue{static_cast(turns::core::Disposition::Friendly), "TURNS_DISPOSITION_FRIENDLY", "friendly"}, - GEnumValue{static_cast(turns::core::Disposition::Hostile), "TURNS_DISPOSITION_HOSTILE", "hostile" }, - GEnumValue{static_cast(turns::core::Disposition::Secret), "TURNS_DISPOSITION_SECRET", "secret" }, - GEnumValue{0, nullptr, nullptr }, - }; - if (!is_initialized.test_and_set()) - { - gtype_ = g_enum_register_static("TurnsDisposition", values.data()); - } - return gtype_; - } -} // namespace Glib \ No newline at end of file diff --git a/core/src/init.cpp b/core/src/init.cpp deleted file mode 100644 index 4f67817..0000000 --- a/core/src/init.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "turns/core/init.hpp" - -#include "turns/core/disposition.hpp" -#include "turns/core/participant.hpp" -#include "turns/core/turn_order_model.hpp" - -#include - -namespace turns::core -{ - - auto register_types() -> void - { - static_cast(Participant{}); - static_cast(TurnOderModel{}); - - g_type_ensure(Glib::Value::value_type()); - } - -} // namespace turns::core \ No newline at end of file diff --git a/core/src/participant.cpp b/core/src/participant.cpp deleted file mode 100644 index ff2c2fb..0000000 --- a/core/src/participant.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include "turns/core/participant.hpp" - -#include "turns/core/disposition.hpp" -#include "turns/core/json_ext.hpp" - -#include -#include -#include -#include - -#include - -#include -#include - -namespace turns::core -{ - auto Participant::create(Glib::ustring name, float priority, core::Disposition disposition) -> Glib::RefPtr - { - return Glib::make_refptr_for_instance(new Participant{name, priority, disposition}); - } - - auto Participant::create(nlohmann::json const & serialized) -> Glib::RefPtr - { - auto disposition = serialized.value("disposition", Disposition::Neutral); - auto priority = serialized.value("priority", 0.0f); - auto name = serialized.value("name", std::string{}); - - auto instance = create(name, priority, disposition); - instance->property_is_active() = serialized.value("is-active", false); - instance->property_is_defeated() = serialized.value("is-defeated", false); - ; - - return instance; - } - - Participant::Participant() - : Glib::ObjectBase{"TurnsParticipant"} - , Glib::Object{} - { - } - - 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 - { - return m_priority <=> other.m_priority; - } - - auto Participant::get_disposition() const -> Disposition - { - return m_disposition.get_value(); - } - - auto Participant::get_is_active() const -> bool - { - return m_is_active.get_value(); - } - - auto Participant::get_is_defeated() const -> bool - { - return m_is_defeated.get_value(); - } - - auto Participant::get_name() const -> Glib::ustring - { - return m_name.get_value(); - } - - auto Participant::get_priority() const -> float - { - return m_priority.get_value(); - } - - auto Participant::set_disposition(Disposition value) -> void - { - return m_disposition.set_value(value); - } - - auto Participant::set_is_active(bool value) -> void - { - return m_is_active.set_value(value); - } - - auto Participant::set_is_defeated(bool value) -> void - { - return m_is_defeated.set_value(value); - } - - auto Participant::set_name(Glib::ustring const & value) -> void - { - return m_name.set_value(value); - } - - auto Participant::set_priority(float value) -> void - { - return m_priority.set_value(value); - } - - auto Participant::serialize() -> nlohmann::json - { - return nlohmann::json{ - {"disposition", m_disposition}, - {"is-active", m_is_active }, - {"is-defeated", m_is_defeated}, - {"name", m_name }, - {"priority", m_priority }, - }; - } -} // namespace turns::core \ No newline at end of file -- cgit v1.2.3