summaryrefslogtreecommitdiff
path: root/lib/src/turns-participant.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/turns-participant.cpp')
-rw-r--r--lib/src/turns-participant.cpp272
1 files changed, 0 insertions, 272 deletions
diff --git a/lib/src/turns-participant.cpp b/lib/src/turns-participant.cpp
deleted file mode 100644
index e69de6e..0000000
--- a/lib/src/turns-participant.cpp
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2025 Felix Morgner <felix.morgner@gmail.com>
- * SPDX-License-Identifier: LGPL-2.1-only
- */
-
-#include "turns-participant.h"
-
-#include <glib-object.h>
-#include <glib.h>
-
-#include <array>
-#include <cstddef>
-#include <limits>
-
-G_BEGIN_DECLS
-
-struct _TurnsParticipant
-{
- GObject parent_instance;
-
- gboolean active;
- gboolean defeated;
- TurnsParticipantDisposition disposition;
- gchar * id;
- gchar * name;
- gfloat priority;
-};
-
-G_DEFINE_TYPE(TurnsParticipant, turns_participant, G_TYPE_OBJECT)
-
-G_END_DECLS
-
-namespace
-{
- enum struct property
- {
- Active = 1,
- Defeated,
- Disposition,
- Name,
- Priority,
- N_PROPERTIES,
- };
-
- auto static constinit properties = std::array<GParamSpec *, static_cast<std::size_t>(property::N_PROPERTIES)>{};
-
- auto finalize(GObject * self)
- {
- auto participant = TURNS_PARTICIPANT(self);
-
- g_free(participant->id);
- g_free(participant->name);
-
- G_OBJECT_CLASS(turns_participant_parent_class)->finalize(self);
- }
-
- auto get_property(GObject * self, guint id, GValue * value, GParamSpec * specification) -> void
- {
- auto participant = TURNS_PARTICIPANT(self);
-
- switch (static_cast<property>(id))
- {
- case property::Active:
- return g_value_set_boolean(value, turns_participant_get_active(participant));
- case property::Defeated:
- return g_value_set_boolean(value, turns_participant_get_defeated(participant));
- case property::Name:
- return g_value_set_string(value, turns_participant_get_name(participant));
- case property::Priority:
- return g_value_set_float(value, turns_participant_get_priority(participant));
- case property::Disposition:
- return g_value_set_enum(value, turns_participant_get_disposition(participant));
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(self, id, specification);
- };
- }
-
- auto set_property(GObject * self, guint id, GValue const * value, GParamSpec * specification) -> void
- {
- auto participant = TURNS_PARTICIPANT(self);
-
- switch (static_cast<property>(id))
- {
- case property::Active:
- return turns_participant_set_active(participant, g_value_get_boolean(value));
- case property::Defeated:
- return turns_participant_set_defeated(participant, g_value_get_boolean(value));
- case property::Name:
- return turns_participant_set_name(participant, g_value_get_string(value));
- case property::Priority:
- return turns_participant_set_priority(participant, g_value_get_float(value));
- case property::Disposition:
- return turns_participant_set_disposition(participant, static_cast<TurnsParticipantDisposition>(g_value_get_enum(value)));
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(self, id, specification);
- }
- }
-} // namespace
-
-G_BEGIN_DECLS
-
-static void turns_participant_class_init(TurnsParticipantClass * klass)
-{
- GObjectClass * object_class = G_OBJECT_CLASS(klass);
-
- (void)object_class;
-
- object_class->get_property = get_property;
- object_class->set_property = set_property;
- object_class->finalize = finalize;
-
- properties[static_cast<std::size_t>(property::Active)] =
- g_param_spec_boolean("active",
- "Active",
- "Whether or not the participant is currently active (taking their turn)",
- false,
- static_cast<GParamFlags>(G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY));
-
- properties[static_cast<std::size_t>(property::Defeated)] =
- g_param_spec_boolean("defeated",
- "Defeated",
- "Whether or not the participant has been defeated",
- false,
- static_cast<GParamFlags>(G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY));
-
- properties[static_cast<std::size_t>(property::Name)] =
- g_param_spec_string("name",
- "Name",
- "The Name of the participant",
- "",
- static_cast<GParamFlags>(G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY));
-
- properties[static_cast<std::size_t>(property::Priority)] =
- g_param_spec_float("priority",
- "Priority",
- "The turn priority of the participant",
- -std::numeric_limits<float>::infinity(),
- +std::numeric_limits<float>::infinity(),
- 0.0f,
- static_cast<GParamFlags>(G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY));
-
- properties[static_cast<std::size_t>(property::Disposition)] =
- g_param_spec_enum("disposition",
- "Disposition",
- "Disposition of the participant toward the players",
- turns_participant_disposition_get_type(),
- TURNS_PARTICIPANT_DISPOSITION_NEUTRAL,
- static_cast<GParamFlags>(G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY));
-
- g_object_class_install_properties(object_class, static_cast<guint>(property::N_PROPERTIES), properties.data());
-}
-
-static void turns_participant_init(TurnsParticipant * self)
-{
- self->id = g_uuid_string_random();
-}
-
-TurnsParticipant * turns_participant_new()
-{
- return static_cast<TurnsParticipant *>(g_object_new(TURNS_TYPE_PARTICIPANT, nullptr));
-}
-
-TurnsParticipant * turns_participant_new_with(gchar const * name, gfloat priority, TurnsParticipantDisposition disposition)
-{
- g_return_val_if_fail(name != nullptr, nullptr);
-
- return static_cast<TurnsParticipant *>(
- g_object_new(TURNS_TYPE_PARTICIPANT, "name", name, "priority", priority, "disposition", static_cast<gint>(disposition), nullptr));
-}
-
-gboolean turns_participant_get_active(TurnsParticipant const * self)
-{
- g_return_val_if_fail(TURNS_IS_PARTICIPANT(const_cast<TurnsParticipant *>(self)), false);
- return self->active;
-}
-
-gboolean turns_participant_get_defeated(TurnsParticipant const * self)
-{
- g_return_val_if_fail(TURNS_IS_PARTICIPANT(const_cast<TurnsParticipant *>(self)), false);
- return self->defeated;
-}
-
-TurnsParticipantDisposition turns_participant_get_disposition(TurnsParticipant const * self)
-{
- g_return_val_if_fail(TURNS_IS_PARTICIPANT(const_cast<TurnsParticipant *>(self)), TurnsParticipantDisposition::TURNS_PARTICIPANT_DISPOSITION_NEUTRAL);
- return self->disposition;
-}
-
-gchar const * turns_participant_get_id(TurnsParticipant const * self)
-{
- g_return_val_if_fail(TURNS_IS_PARTICIPANT(const_cast<TurnsParticipant *>(self)), nullptr);
- return self->id;
-}
-
-gchar const * turns_participant_get_name(TurnsParticipant const * self)
-{
- g_return_val_if_fail(TURNS_IS_PARTICIPANT(const_cast<TurnsParticipant *>(self)), nullptr);
- return self->name;
-}
-
-gfloat turns_participant_get_priority(TurnsParticipant const * self)
-{
- g_return_val_if_fail(TURNS_IS_PARTICIPANT(const_cast<TurnsParticipant *>(self)), 0.0f);
- return self->priority;
-}
-
-void turns_participant_set_active(TurnsParticipant * self, gboolean value)
-{
- g_return_if_fail(TURNS_IS_PARTICIPANT(self));
-
- if (value == self->active)
- {
- return;
- }
-
- self->active = value;
- g_object_notify_by_pspec(G_OBJECT(self), properties[static_cast<std::size_t>(property::Active)]);
-}
-
-void turns_participant_set_defeated(TurnsParticipant * self, gboolean value)
-{
- g_return_if_fail(TURNS_IS_PARTICIPANT(self));
-
- if (value == self->defeated)
- {
- return;
- }
-
- self->defeated = value;
- g_object_notify_by_pspec(G_OBJECT(self), properties[static_cast<std::size_t>(property::Defeated)]);
-}
-
-void turns_participant_set_disposition(TurnsParticipant * self, TurnsParticipantDisposition value)
-{
- g_return_if_fail(TURNS_IS_PARTICIPANT(self));
-
- if (value == self->disposition)
- {
- return;
- }
-
- self->disposition = value;
- g_object_notify_by_pspec(G_OBJECT(self), properties[static_cast<std::size_t>(property::Disposition)]);
-}
-
-void turns_participant_set_name(TurnsParticipant * self, gchar const * value)
-{
- g_return_if_fail(TURNS_IS_PARTICIPANT(self));
- g_return_if_fail(value != nullptr);
-
- if (!g_set_str(&self->name, value))
- {
- return;
- }
-
- g_object_notify_by_pspec(G_OBJECT(self), properties[static_cast<std::size_t>(property::Name)]);
-}
-
-void turns_participant_set_priority(TurnsParticipant * self, gfloat value)
-{
- g_return_if_fail(TURNS_IS_PARTICIPANT(self));
-
- if (value == self->priority)
- {
- return;
- }
-
- self->priority = value;
- g_object_notify_by_pspec(G_OBJECT(self), properties[static_cast<std::size_t>(property::Priority)]);
-}
-
-G_END_DECLS