diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2025-05-12 17:02:36 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2025-05-12 17:02:36 +0200 |
| commit | 97c74a7c43bcc7e0551a967c6fa2720e9cb58efb (patch) | |
| tree | c2ad9a76dbaf788bd8fdb41e5b18b75b7f7e3298 /lib/src | |
| parent | 2618066ba0b9e7c490797821dca4d19b48a09256 (diff) | |
| download | turns-97c74a7c43bcc7e0551a967c6fa2720e9cb58efb.tar.xz turns-97c74a7c43bcc7e0551a967c6fa2720e9cb58efb.zip | |
lib: add active and defeated properties to Turns.Participant
Diffstat (limited to 'lib/src')
| -rw-r--r-- | lib/src/turns-participant.cpp | 75 | ||||
| -rw-r--r-- | lib/src/turns-participant.h | 32 |
2 files changed, 100 insertions, 7 deletions
diff --git a/lib/src/turns-participant.cpp b/lib/src/turns-participant.cpp index a94462e..49f29ff 100644 --- a/lib/src/turns-participant.cpp +++ b/lib/src/turns-participant.cpp @@ -17,6 +17,8 @@ struct _TurnsParticipant { GObject parent_instance; + gboolean active; + gboolean defeated; TurnsDisposition disposition; gchar * name; gfloat priority; @@ -30,7 +32,9 @@ namespace { enum struct property { - Disposition = 1, + Active = 1, + Defeated, + Disposition, Name, Priority, N_PROPERTIES, @@ -53,15 +57,16 @@ namespace 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: - g_value_set_string(value, turns_participant_get_name(participant)); - return; + return g_value_set_string(value, turns_participant_get_name(participant)); case property::Priority: - g_value_set_float(value, turns_participant_get_priority(participant)); - return; + return g_value_set_float(value, turns_participant_get_priority(participant)); case property::Disposition: - g_value_set_enum(value, turns_participant_get_disposition(participant)); - return; + return g_value_set_enum(value, turns_participant_get_disposition(participant)); default: G_OBJECT_WARN_INVALID_PROPERTY_ID(self, id, specification); }; @@ -73,6 +78,10 @@ namespace 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: @@ -97,6 +106,20 @@ static void turns_participant_class_init(TurnsParticipantClass * klass) 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", @@ -142,6 +165,18 @@ TurnsParticipant * turns_participant_new_with(gchar const * name, gfloat priorit 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; +} + TurnsDisposition turns_participant_get_disposition(TurnsParticipant const * self) { g_return_val_if_fail(TURNS_IS_PARTICIPANT(const_cast<TurnsParticipant *>(self)), TurnsDisposition::TURNS_DISPOSITION_NEUTRAL); @@ -160,6 +195,32 @@ gfloat turns_participant_get_priority(TurnsParticipant const * self) 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, TurnsDisposition value) { g_return_if_fail(TURNS_IS_PARTICIPANT(self)); diff --git a/lib/src/turns-participant.h b/lib/src/turns-participant.h index a2af8d6..a0e0d98 100644 --- a/lib/src/turns-participant.h +++ b/lib/src/turns-participant.h @@ -32,6 +32,22 @@ TurnsParticipant * turns_participant_new() G_GNUC_WARN_UNUSED_RESULT; TurnsParticipant * turns_participant_new_with(gchar const * name, gfloat priority, TurnsDisposition disposition) G_GNUC_WARN_UNUSED_RESULT; /** + * @brief Get the active state of a participant. + * + * @param self A Participant instance. The value *must not* be NULL. + * @return The active state of the instance. + */ +gboolean turns_participant_get_active(TurnsParticipant const * self); + +/** + * @brief Get the defeated state of a participant. + * + * @param self A Participant instance. The value *must not* be NULL. + * @return The defeated state of the instance. + */ +gboolean turns_participant_get_defeated(TurnsParticipant const * self); + +/** * @brief Get the disposition of a participant. * * @param self A Participant instance. The value *must not* be NULL. @@ -56,6 +72,22 @@ gchar const * turns_participant_get_name(TurnsParticipant const * self); gfloat turns_participant_get_priority(TurnsParticipant const * self); /** + * @brief Set the active state of a participant. + * + * @param self A Participant instance. The value *must not* be NULL. + * @return The new active state. + */ +void turns_participant_set_active(TurnsParticipant * self, gboolean value); + +/** + * @brief Set the defeated state of a participant. + * + * @param self A Participant instance. The value *must not* be NULL. + * @param value The new defeated state. + */ +void turns_participant_set_defeated(TurnsParticipant * self, gboolean value); + +/** * @brief Set the disposition of a participant. * * @param self A Participant instance. The value *must not* be NULL. |
