mirror of
https://github.com/jorenchik/testing-spring-2024.git
synced 2025-10-21 20:10:36 +00:00
refactor(event): move event to separate file
This commit is contained in:
parent
5238b348c6
commit
09d17e2d0a
48
src/event.cc
Normal file
48
src/event.cc
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#include "event.hh"
|
||||||
|
|
||||||
|
#include "action.hh"
|
||||||
|
#include "time.hh"
|
||||||
|
|
||||||
|
#include <initializer_list>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
Event::Event(std::string title,
|
||||||
|
uint32_t created_at,
|
||||||
|
uint32_t night_number,
|
||||||
|
bool is_visible,
|
||||||
|
std::vector<Action> prohibits,
|
||||||
|
std::vector<Action> 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<Action> prohibits,
|
||||||
|
std::initializer_list<Action> 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;
|
||||||
|
}
|
||||||
@ -1,45 +1,46 @@
|
|||||||
#ifndef PREP_H
|
#ifndef EVENT_HH
|
||||||
#define PREP_H
|
#define EVENT_HH
|
||||||
|
|
||||||
|
#include "action.hh"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <initializer_list>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// All IDs are uint32_t
|
namespace event {
|
||||||
enum EventType {
|
enum Type {
|
||||||
PHASE_CHANGE,
|
PhaseChange,
|
||||||
ACTION,
|
EventAction,
|
||||||
ROOM_STATE_CHANGE,
|
RoomStateChange,
|
||||||
PLAYER_STATE_CHANGE,
|
PlayerStateChange,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
struct Event;
|
|
||||||
|
|
||||||
struct Event {
|
struct Event {
|
||||||
std::string title;
|
std::string title;
|
||||||
std::tm *utcTimestampCreatedAt;
|
std::tm *created_at;
|
||||||
uint32_t numberNight;
|
uint32_t night_number;
|
||||||
bool isVisible;
|
bool is_visible;
|
||||||
std::vector<Action> prohibits;
|
std::vector<Action> prohibits;
|
||||||
std::vector<Action> allows;
|
std::vector<Action> allows;
|
||||||
|
|
||||||
bool operator<(const Event &other) const;
|
bool operator<(const Event &other) const;
|
||||||
bool operator==(const Event &other) const;
|
bool operator==(const Event &other) const;
|
||||||
bool operator>(const Event &other) const;
|
bool operator>(const Event &other) const;
|
||||||
|
|
||||||
Event(std::string title,
|
Event(std::string title,
|
||||||
uint32_t utcTimestampCreatedAt,
|
uint32_t created_at,
|
||||||
uint32_t numberNight,
|
uint32_t night_number,
|
||||||
bool isVisible,
|
bool is_visible,
|
||||||
std::vector<Action> prohibits,
|
std::vector<Action> prohibits,
|
||||||
std::vector<Action> allows);
|
std::vector<Action> allows);
|
||||||
Event(std::string title,
|
Event(std::string title,
|
||||||
uint32_t utcTimestampCreatedAt,
|
uint32_t created_at,
|
||||||
uint32_t numberNight,
|
uint32_t night_number,
|
||||||
bool isVisible,
|
bool is_visible,
|
||||||
std::initializer_list<Action> prohibits,
|
std::initializer_list<Action> prohibits,
|
||||||
std::initializer_list<Action> allows);
|
std::initializer_list<Action> allows);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // !EVENT_HH
|
||||||
@ -6,20 +6,22 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
enum PlayerStatus {
|
namespace player {
|
||||||
|
enum Status {
|
||||||
Kicked,
|
Kicked,
|
||||||
Alive,
|
Alive,
|
||||||
Dead,
|
Dead,
|
||||||
VotedOut,
|
VotedOut,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
struct Player {
|
struct Player {
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
std::string username;
|
std::string username;
|
||||||
Role role;
|
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;
|
bool operator==(const Player &other) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,48 +0,0 @@
|
|||||||
#include "prep.hh"
|
|
||||||
|
|
||||||
#include "timeUtils.hh"
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <initializer_list>
|
|
||||||
|
|
||||||
Event::Event(std::string title,
|
|
||||||
uint32_t utcTimestampCreatedAt,
|
|
||||||
uint32_t numberNight,
|
|
||||||
bool isVisible,
|
|
||||||
std::vector<Action> prohibits,
|
|
||||||
std::vector<Action> 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<Action> prohibits,
|
|
||||||
std::initializer_list<Action> allows):
|
|
||||||
Event(title,
|
|
||||||
utcTimestampCreatedAt,
|
|
||||||
numberNight,
|
|
||||||
isVisible,
|
|
||||||
std::vector<Action>(prohibits),
|
|
||||||
std::vector<Action>(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;
|
|
||||||
}
|
|
||||||
13
src/room.hh
13
src/room.hh
@ -9,22 +9,25 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
enum RoomStatus {
|
namespace room {
|
||||||
|
enum Status {
|
||||||
AwaitingStart,
|
AwaitingStart,
|
||||||
InProgress,
|
InProgress,
|
||||||
Stopped,
|
Stopped,
|
||||||
Ended,
|
Ended,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
struct Room {
|
struct Room {
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
std::string title;
|
std::string title;
|
||||||
std::tm *created_at;
|
std::tm *created_at;
|
||||||
RoomStatus status;
|
room::Status status;
|
||||||
std::vector<Player> players;
|
std::vector<Player> players;
|
||||||
|
|
||||||
Room(uint32_t id, std::string title, uint32_t created_at, RoomStatus status, std::vector<Player> players);
|
Room(uint32_t id, std::string title, uint32_t created_at, room::Status status, std::vector<Player> players);
|
||||||
Room(uint32_t id, std::string title, uint32_t created_at, RoomStatus status, std::initializer_list<Player> players);
|
Room(
|
||||||
|
uint32_t id, std::string title, uint32_t created_at, room::Status status, std::initializer_list<Player> players);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !ROOM_HH
|
#endif // !ROOM_HH
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user