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 --- lib/src/turns-turn-order.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 lib/src/turns-turn-order.cpp (limited to 'lib/src/turns-turn-order.cpp') diff --git a/lib/src/turns-turn-order.cpp b/lib/src/turns-turn-order.cpp new file mode 100644 index 0000000..538ff11 --- /dev/null +++ b/lib/src/turns-turn-order.cpp @@ -0,0 +1,80 @@ +#include "turns-turn-order.h" + +#include +#include + +#include +#include + +G_BEGIN_DECLS + +struct _TurnsTurnOrder +{ + GObject parent_instance; + + gboolean running; +}; + +G_DEFINE_FINAL_TYPE(TurnsTurnOrder, turns_turn_order, G_TYPE_OBJECT); + +G_END_DECLS + +namespace +{ + enum struct property + { + Running = 1, + N_PROPERTIES, + }; + + auto static constinit properties = std::array(property::N_PROPERTIES)>{}; + + auto get_property(GObject * self, guint id, GValue * value, GParamSpec * specification) -> void + { + auto instance = TURNS_TURN_ORDER(self); + + switch (static_cast(id)) + { + case property::Running: + return g_value_set_boolean(value, turns_turn_order_get_running(instance)); + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(self, id, specification); + } + } + +} // namespace + +G_BEGIN_DECLS + +static void turns_turn_order_class_init(TurnsTurnOrderClass * klass) +{ + auto object_class = G_OBJECT_CLASS(klass); + + object_class->get_property = get_property; + + properties[static_cast(property::Running)] = + g_param_spec_boolean("running", + "Running", + "Whether or not the turn order is running (e.g. has been started)", + false, + static_cast(G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY)); + + g_object_class_install_properties(object_class, properties.size(), properties.data()); +} + +static void turns_turn_order_init(TurnsTurnOrder *) +{ +} + +TurnsTurnOrder * turns_turn_order_new() +{ + return TURNS_TURN_ORDER(g_object_new(TURNS_TYPE_TURN_ORDER, nullptr)); +} + +gboolean turns_turn_order_get_running(TurnsTurnOrder const * self) +{ + g_return_val_if_fail(TURNS_IS_TURN_ORDER(const_cast(self)), false); + return self->running; +} + +G_END_DECLS \ No newline at end of file -- cgit v1.2.3