diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2025-05-13 15:59:02 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2025-05-13 15:59:02 +0200 |
| commit | 9513f7303ffde9fbda869e346523a23197f4ece9 (patch) | |
| tree | f35ab8afa3273d1a8c4da2fc2ac9580a157a3a2c /core | |
| parent | 661e98cf8bb61f29049d405aef9cdaace1449ac8 (diff) | |
| download | turns-9513f7303ffde9fbda869e346523a23197f4ece9.tar.xz turns-9513f7303ffde9fbda869e346523a23197f4ece9.zip | |
lib: begin TurnOrder implementation
Diffstat (limited to 'core')
| -rw-r--r-- | core/include/turns/core/disposition.hpp | 39 | ||||
| -rw-r--r-- | core/include/turns/core/fwd.hpp | 14 | ||||
| -rw-r--r-- | core/include/turns/core/init.hpp | 11 | ||||
| -rw-r--r-- | core/include/turns/core/participant.hpp | 82 | ||||
| -rw-r--r-- | core/src/disposition.cpp | 51 | ||||
| -rw-r--r-- | core/src/init.cpp | 20 | ||||
| -rw-r--r-- | core/src/participant.cpp | 116 |
7 files changed, 0 insertions, 333 deletions
diff --git a/core/include/turns/core/disposition.hpp b/core/include/turns/core/disposition.hpp deleted file mode 100644 index cd00836..0000000 --- a/core/include/turns/core/disposition.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef TURNS_CORE_DISPOSITION_HPP -#define TURNS_CORE_DISPOSITION_HPP - -#include <glibmm/ustring.h> -#include <glibmm/value.h> - -#include <glib-object.h> - -#include <cstdint> - -namespace turns::core -{ - enum struct Disposition : std::uint8_t - { - Neutral, - Friendly, - Hostile, - Secret, - - ///! End marker - END - }; - - auto presentation_name_for(Disposition value) -> Glib::ustring; -} // namespace turns::core - -namespace Glib -{ - template<> - class Value<turns::core::Disposition> : public Glib::Value_Enum<turns::core::Disposition> - { - GType static constinit inline gtype_{}; - - public: - auto static value_type() -> GType; - }; -} // namespace Glib - -#endif
\ No newline at end of file diff --git a/core/include/turns/core/fwd.hpp b/core/include/turns/core/fwd.hpp deleted file mode 100644 index c006084..0000000 --- a/core/include/turns/core/fwd.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef TURNS_CORE_FWD_HPP -#define TURNS_CORE_FWD_HPP - -#include <cstdint> - -namespace turns::core -{ - enum struct Disposition : std::uint8_t; - - struct Participant; - struct TurnOderModel; -} // namespace turns::core - -#endif
\ No newline at end of file diff --git a/core/include/turns/core/init.hpp b/core/include/turns/core/init.hpp deleted file mode 100644 index f0dc70e..0000000 --- a/core/include/turns/core/init.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef TURNS_CORE_INIT_HPP -#define TURNS_CORE_INIT_HPP - -namespace turns::core -{ - - auto register_types() -> void; - -} // namespace turns::core - -#endif
\ No newline at end of file diff --git a/core/include/turns/core/participant.hpp b/core/include/turns/core/participant.hpp deleted file mode 100644 index e6d9008..0000000 --- a/core/include/turns/core/participant.hpp +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef TURNS_CORE_PARTICIPANT_HPP -#define TURNS_CORE_PARTICIPANT_HPP - -#include "turns/core/disposition.hpp" - -#include <glibmm/object.h> -#include <glibmm/property.h> -#include <glibmm/refptr.h> -#include <glibmm/ustring.h> - -#include <nlohmann/json_fwd.hpp> - -#include <compare> - -namespace turns::core -{ - 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>; - - Participant(); - Participant(Glib::ustring name, float priority, Disposition disposition); - - auto operator<=>(Participant const & other) const noexcept -> std::partial_ordering; - - [[nodiscard]] auto get_disposition() const -> Disposition; - [[nodiscard]] auto get_is_active() const -> bool; - [[nodiscard]] auto get_is_defeated() const -> bool; - [[nodiscard]] auto get_name() const -> Glib::ustring; - [[nodiscard]] auto get_priority() const -> float; - - auto set_disposition(Disposition value) -> void; - auto set_is_active(bool value) -> void; - auto set_is_defeated(bool value) -> void; - auto set_name(Glib::ustring const & value) -> void; - auto set_priority(float value) -> void; - - [[nodiscard]] auto property_disposition(this auto && self); - [[nodiscard]] auto property_is_active(this auto && self); - [[nodiscard]] auto property_is_defeated(this auto && self); - [[nodiscard]] auto property_name(this auto && self); - [[nodiscard]] auto property_priority(this auto && self); - - auto serialize() -> nlohmann::json; - - private: - Glib::Property<core::Disposition> m_disposition{*this, "disposition", core::Disposition::Neutral}; - Glib::Property<bool> m_is_active{*this, "is-active", false}; - Glib::Property<bool> m_is_defeated{*this, "is-defeated", false}; - Glib::Property<Glib::ustring> m_name{*this, "name", ""}; - Glib::Property<float> m_priority{*this, "priority", 0.0f}; - }; - - auto Participant::property_disposition(this auto && self) - { - return self.m_disposition.get_proxy(); - } - - auto Participant::property_is_active(this auto && self) - { - return self.m_is_active.get_proxy(); - } - - auto Participant::property_is_defeated(this auto && self) - { - return self.m_is_defeated.get_proxy(); - } - - auto Participant::property_name(this auto && self) - { - return self.m_name.get_proxy(); - } - - auto Participant::property_priority(this auto && self) - { - return self.m_priority.get_proxy(); - } - -} // namespace turns::core - -#endif
\ No newline at end of file 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 <glibmm/i18n.h> -#include <glibmm/ustring.h> - -#include <glib-object.h> - -#include <array> -#include <atomic> - -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<turns::core::Disposition>::value_type() -> GType - { - auto static is_initialized = std::atomic_flag{false}; - auto static const values = std::array{ - GEnumValue{static_cast<int>(turns::core::Disposition::Neutral), "TURNS_DISPOSITION_NEUTRAL", "neutral" }, - GEnumValue{static_cast<int>(turns::core::Disposition::Friendly), "TURNS_DISPOSITION_FRIENDLY", "friendly"}, - GEnumValue{static_cast<int>(turns::core::Disposition::Hostile), "TURNS_DISPOSITION_HOSTILE", "hostile" }, - GEnumValue{static_cast<int>(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 <glib-object.h> - -namespace turns::core -{ - - auto register_types() -> void - { - static_cast<void>(Participant{}); - static_cast<void>(TurnOderModel{}); - - g_type_ensure(Glib::Value<Disposition>::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 <glibmm/object.h> -#include <glibmm/objectbase.h> -#include <glibmm/refptr.h> -#include <glibmm/ustring.h> - -#include <nlohmann/json.hpp> - -#include <compare> -#include <string> - -namespace turns::core -{ - 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}); - } - - auto Participant::create(nlohmann::json const & serialized) -> Glib::RefPtr<Participant> - { - 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 |
