summaryrefslogtreecommitdiff
path: root/core/include
diff options
context:
space:
mode:
Diffstat (limited to 'core/include')
-rw-r--r--core/include/turns/core/disposition.hpp27
-rw-r--r--core/include/turns/core/participant.hpp58
-rw-r--r--core/include/turns/core/turn_order.hpp85
3 files changed, 170 insertions, 0 deletions
diff --git a/core/include/turns/core/disposition.hpp b/core/include/turns/core/disposition.hpp
new file mode 100644
index 0000000..291aaf5
--- /dev/null
+++ b/core/include/turns/core/disposition.hpp
@@ -0,0 +1,27 @@
+#ifndef TURNS_DOMAIN_DISPOSITION_HPP
+#define TURNS_DOMAIN_DISPOSITION_HPP
+
+#include <compare>
+#include <cstdint>
+
+#include <glibmm/ustring.h>
+
+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
+
+#endif \ No newline at end of file
diff --git a/core/include/turns/core/participant.hpp b/core/include/turns/core/participant.hpp
new file mode 100644
index 0000000..9b5dab4
--- /dev/null
+++ b/core/include/turns/core/participant.hpp
@@ -0,0 +1,58 @@
+#ifndef TURNS_DOMAIN_PARTICIPANT_HPP
+#define TURNS_DOMAIN_PARTICIPANT_HPP
+
+#include "turns/core/disposition.hpp"
+
+#include <compare>
+
+#include <glibmm/object.h>
+#include <glibmm/property.h>
+#include <glibmm/propertyproxy.h>
+#include <glibmm/refptr.h>
+#include <glibmm/ustring.h>
+
+namespace turns::core
+{
+ struct participant : Glib::Object
+ {
+ auto static create(Glib::ustring name, float priority, disposition disposition) -> Glib::RefPtr<participant>;
+
+ participant();
+ participant(Glib::ustring name, float priority, disposition disposition);
+
+ auto operator<=>(participant const & other) const noexcept -> std::partial_ordering;
+
+ template<typename Self>
+ auto disposition(this Self && self)
+ {
+ return self.m_disposition.get_proxy();
+ }
+
+ template<typename Self>
+ auto is_active(this Self && self)
+ {
+ return self.m_is_active.get_proxy();
+ }
+
+ template<typename Self>
+ auto name(this Self && self)
+ {
+ return self.m_name.get_proxy();
+ }
+
+ template<typename Self>
+ auto priority(this Self && self)
+ {
+ return self.m_priority.get_proxy();
+ }
+
+ private:
+ Glib::Property<core::disposition> m_disposition{*this, "disposition", core::disposition::neutral};
+ Glib::Property<bool> m_is_active{*this, "active", false};
+ Glib::Property<Glib::ustring> m_name{*this, "name", ""};
+ Glib::Property<float> m_priority{*this, "priority", 0.0f};
+ };
+
+} // namespace turns::core
+
+#endif \ No newline at end of file
diff --git a/core/include/turns/core/turn_order.hpp b/core/include/turns/core/turn_order.hpp
new file mode 100644
index 0000000..43ee075
--- /dev/null
+++ b/core/include/turns/core/turn_order.hpp
@@ -0,0 +1,85 @@
+#ifndef TURNS_DOMAIN_TURN_ORDER_HPP
+#define TURNS_DOMAIN_TURN_ORDER_HPP
+
+#include "turns/core/disposition.hpp"
+#include "turns/core/participant.hpp"
+
+#include <initializer_list>
+#include <limits>
+#include <optional>
+#include <vector>
+
+#include <giomm/listmodel.h>
+#include <glibmm/property.h>
+#include <glibmm/refptr.h>
+#include <glibmm/ustring.h>
+
+namespace turns::core
+{
+
+ struct turn_order : Gio::ListModel,
+ Glib::Object
+ {
+ 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;
+
+ using active_participant_type = unsigned int;
+ using is_empty_type = bool;
+ using has_next_type = bool;
+ using has_previous_type = bool;
+ using is_running_type = bool;
+ using round_number_type = unsigned int;
+
+ auto static constexpr invalid_participant_index = std::numeric_limits<active_participant_type>::max();
+ auto static constexpr invalid_round_number = std::numeric_limits<round_number_type>::max();
+
+ /** Life-time */
+ turn_order();
+
+ auto static create() -> Glib::RefPtr<turn_order>;
+
+ /** Properties */
+ auto is_empty() const -> Glib::PropertyProxy_ReadOnly<is_empty_type>;
+ auto has_next() const -> Glib::PropertyProxy_ReadOnly<has_next_type>;
+ auto has_previous() const -> Glib::PropertyProxy_ReadOnly<has_previous_type>;
+ auto is_running() const -> Glib::PropertyProxy_ReadOnly<is_running_type>;
+ auto round_number() const -> Glib::PropertyProxy_ReadOnly<round_number_type>;
+
+ /** Element Modifications */
+ auto add(Glib::ustring const & name, float priority, disposition disposition) -> void;
+ auto clear() -> void;
+ auto remove(unsigned index) -> void;
+
+ /** Turn Modification */
+ auto next() -> void;
+ auto previous() -> void;
+ auto start() -> void;
+ auto stop() -> void;
+
+ private:
+ auto get_item_type_vfunc() -> GType override;
+ auto get_n_items_vfunc() -> unsigned override;
+ auto get_item_vfunc(unsigned position) -> void * override;
+
+ /** Signal handlers */
+ auto handle_priority_changed(value_type entry) -> void;
+
+ /** Data management */
+ auto find(value_type entry) const -> const_iterator;
+ auto insert(value_type entry) -> const_iterator;
+
+ container_type m_data{};
+ std::optional<unsigned> m_active{};
+
+ Glib::Property<has_next_type> m_has_next{*this, "has-next", false};
+ Glib::Property<has_previous_type> m_has_previous{*this, "has-previous", false};
+ Glib::Property<is_empty_type> m_is_empty{*this, "is-empty", true};
+ Glib::Property<is_running_type> m_is_running{*this, "is-running", false};
+ Glib::Property<round_number_type> m_round_number{*this, "round-number", invalid_round_number};
+ };
+
+} // namespace turns::core
+
+#endif \ No newline at end of file