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
|
||||
#define PREP_H
|
||||
#ifndef EVENT_HH
|
||||
#define EVENT_HH
|
||||
|
||||
#include "action.hh"
|
||||
|
||||
#include <cstdint>
|
||||
#include <ctime>
|
||||
#include <initializer_list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// 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<Action> prohibits;
|
||||
std::vector<Action> 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<Action> prohibits,
|
||||
std::vector<Action> 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<Action> prohibits,
|
||||
std::initializer_list<Action> allows);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // !EVENT_HH
|
||||
@ -6,20 +6,22 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
21
src/room.hh
21
src/room.hh
@ -9,22 +9,25 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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<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, RoomStatus status, std::initializer_list<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, room::Status status, std::initializer_list<Player> players);
|
||||
};
|
||||
|
||||
#endif // !ROOM_HH
|
||||
|
||||
Loading…
Reference in New Issue
Block a user