From 09d17e2d0a149f76133518fa4c3337d190990251 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Thu, 14 Mar 2024 01:20:39 +0200 Subject: [PATCH] refactor(event): move `event` to separate file --- src/event.cc | 48 ++++++++++++++++++++++++++++++++++ src/{prep/prep.hh => event.hh} | 45 +++++++++++++++---------------- src/player.hh | 18 +++++++------ src/prep/prep.cc | 48 ---------------------------------- src/room.hh | 21 ++++++++------- 5 files changed, 93 insertions(+), 87 deletions(-) create mode 100644 src/event.cc rename src/{prep/prep.hh => event.hh} (53%) delete mode 100644 src/prep/prep.cc diff --git a/src/event.cc b/src/event.cc new file mode 100644 index 0000000..1c24b4d --- /dev/null +++ b/src/event.cc @@ -0,0 +1,48 @@ +#include "event.hh" + +#include "action.hh" +#include "time.hh" + +#include +#include +#include + +Event::Event(std::string title, + uint32_t created_at, + uint32_t night_number, + bool is_visible, + std::vector prohibits, + std::vector allows): + title(title), + created_at(create_utc_timestamp(created_at)), + night_number(night_number), + is_visible(is_visible), + prohibits(prohibits), + allows(allows) { +} + +Event::Event(std::string title, + uint32_t created_at, + uint32_t night_number, + bool is_visible, + std::initializer_list prohibits, + std::initializer_list allows): + title(title), + created_at(create_utc_timestamp(created_at)), + night_number(night_number), + is_visible(is_visible), + prohibits(prohibits), + allows(allows) { +} + +bool Event::operator<(const Event &right) const { + return this->created_at < right.created_at; +} + +bool Event::operator==(const Event &right) const { + return this->created_at == right.created_at; +} + +bool Event::operator>(const Event &right) const { + return this->created_at > right.created_at; +} diff --git a/src/prep/prep.hh b/src/event.hh similarity index 53% rename from src/prep/prep.hh rename to src/event.hh index b199396..75199c8 100644 --- a/src/prep/prep.hh +++ b/src/event.hh @@ -1,45 +1,46 @@ -#ifndef PREP_H -#define PREP_H +#ifndef EVENT_HH +#define EVENT_HH + +#include "action.hh" #include #include +#include #include #include -// All IDs are uint32_t -enum EventType { - PHASE_CHANGE, - ACTION, - ROOM_STATE_CHANGE, - PLAYER_STATE_CHANGE, -}; - -struct Event; +namespace event { + enum Type { + PhaseChange, + EventAction, + RoomStateChange, + PlayerStateChange, + }; +} struct Event { std::string title; - std::tm *utcTimestampCreatedAt; - uint32_t numberNight; - bool isVisible; + std::tm *created_at; + uint32_t night_number; + bool is_visible; std::vector prohibits; std::vector allows; - bool operator<(const Event &other) const; bool operator==(const Event &other) const; bool operator>(const Event &other) const; Event(std::string title, - uint32_t utcTimestampCreatedAt, - uint32_t numberNight, - bool isVisible, + uint32_t created_at, + uint32_t night_number, + bool is_visible, std::vector prohibits, std::vector allows); Event(std::string title, - uint32_t utcTimestampCreatedAt, - uint32_t numberNight, - bool isVisible, + uint32_t created_at, + uint32_t night_number, + bool is_visible, std::initializer_list prohibits, std::initializer_list allows); }; -#endif +#endif // !EVENT_HH diff --git a/src/player.hh b/src/player.hh index a2760b4..588d17b 100644 --- a/src/player.hh +++ b/src/player.hh @@ -6,20 +6,22 @@ #include #include -enum PlayerStatus { - Kicked, - Alive, - Dead, - VotedOut, -}; +namespace player { + enum Status { + Kicked, + Alive, + Dead, + VotedOut, + }; +} struct Player { uint32_t id; std::string username; Role role; - PlayerStatus status; + player::Status status; - Player(uint32_t id, std::string username, Role role, PlayerStatus status); + Player(uint32_t id, std::string username, Role role, player::Status status); bool operator==(const Player &other) const; }; diff --git a/src/prep/prep.cc b/src/prep/prep.cc deleted file mode 100644 index ec5d4a3..0000000 --- a/src/prep/prep.cc +++ /dev/null @@ -1,48 +0,0 @@ -#include "prep.hh" - -#include "timeUtils.hh" - -#include -#include - -Event::Event(std::string title, - uint32_t utcTimestampCreatedAt, - uint32_t numberNight, - bool isVisible, - std::vector prohibits, - std::vector allows): - title(title), - utcTimestampCreatedAt(createUTCTimestamp(utcTimestampCreatedAt)), - numberNight(numberNight), - isVisible(isVisible), - prohibits(prohibits), - allows(allows) { - this->utcTimestampCreatedAt = createUTCTimestamp(utcTimestampCreatedAt); -} - -Event::Event(std::string title, - uint32_t utcTimestampCreatedAt, - uint32_t numberNight, - bool isVisible, - std::initializer_list prohibits, - std::initializer_list allows): - Event(title, - utcTimestampCreatedAt, - numberNight, - isVisible, - std::vector(prohibits), - std::vector(allows)) { - this->utcTimestampCreatedAt = createUTCTimestamp(utcTimestampCreatedAt); -} - -bool Event::operator<(const Event &right) const { - return this->utcTimestampCreatedAt < right.utcTimestampCreatedAt; -} - -bool Event::operator==(const Event &right) const { - return this->utcTimestampCreatedAt == right.utcTimestampCreatedAt; -} - -bool Event::operator>(const Event &right) const { - return this->utcTimestampCreatedAt > right.utcTimestampCreatedAt; -} diff --git a/src/room.hh b/src/room.hh index 39cb12d..e9ce478 100644 --- a/src/room.hh +++ b/src/room.hh @@ -9,22 +9,25 @@ #include #include -enum RoomStatus { - AwaitingStart, - InProgress, - Stopped, - Ended, -}; +namespace room { + enum Status { + AwaitingStart, + InProgress, + Stopped, + Ended, + }; +} struct Room { uint32_t id; std::string title; std::tm *created_at; - RoomStatus status; + room::Status status; std::vector players; - Room(uint32_t id, std::string title, uint32_t created_at, RoomStatus status, std::vector players); - Room(uint32_t id, std::string title, uint32_t created_at, RoomStatus status, std::initializer_list players); + Room(uint32_t id, std::string title, uint32_t created_at, room::Status status, std::vector players); + Room( + uint32_t id, std::string title, uint32_t created_at, room::Status status, std::initializer_list players); }; #endif // !ROOM_HH