mirror of
https://github.com/jorenchik/testing-spring-2024.git
synced 2025-10-21 20:10:36 +00:00
refactor: add static to functions
- Update functions to be declared as static for improved code clarity - No functional changes made, only internal refactoring
This commit is contained in:
parent
7f0a51f5b8
commit
90c78eaa04
@ -9,11 +9,9 @@
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
// These functions need to be declared to use the top-down rule and
|
||||
// make them as module private functions.
|
||||
bool player_belongs_to_room(const Player *player, const Room *room);
|
||||
bool action_belongs_to_role(const Role *role, const Action *action);
|
||||
bool is_action_allowed(const Action *action, std::vector<Event> *relevant_events);
|
||||
static bool player_belongs_to_room(const Player *player, const Room *room);
|
||||
static bool action_belongs_to_role(const Role *role, const Action *action);
|
||||
static bool is_action_allowed(const Action *action, std::vector<Event> *relevant_events);
|
||||
|
||||
/**
|
||||
* Validate if an action is valid for a player in a room based on related events.
|
||||
@ -68,7 +66,7 @@ ValidationStatus validate_action(
|
||||
* @param room Pointer to the room object.
|
||||
* @return `true` if the player belongs to the room, otherwise `false`.
|
||||
*/
|
||||
bool player_belongs_to_room(const Player *player, const Room *room) {
|
||||
static bool player_belongs_to_room(const Player *player, const Room *room) {
|
||||
return std::find(room->players.begin(), room->players.end(), *player) != room->players.end();
|
||||
}
|
||||
|
||||
@ -79,7 +77,7 @@ bool player_belongs_to_room(const Player *player, const Room *room) {
|
||||
* @param action Pointer to the action object.
|
||||
* @return `true` if the action belongs to the role, otherwise `false`.
|
||||
*/
|
||||
bool action_belongs_to_role(const Role *role, const Action *action) {
|
||||
static bool action_belongs_to_role(const Role *role, const Action *action) {
|
||||
return std::find(role->actions.begin(), role->actions.end(), *action) != role->actions.end();
|
||||
}
|
||||
|
||||
@ -90,7 +88,7 @@ bool action_belongs_to_role(const Role *role, const Action *action) {
|
||||
* @param relevantEvents Pointer to the vector of relevant events.
|
||||
* @return `true` if the action is allowed, otherwise `false`.
|
||||
*/
|
||||
bool is_action_allowed(const Action *action, std::vector<Event> *relevant_events) {
|
||||
static bool is_action_allowed(const Action *action, std::vector<Event> *relevant_events) {
|
||||
bool allowed = false; // Actions are disabled by default
|
||||
std::sort(relevant_events->begin(), relevant_events->end());
|
||||
for (const auto &event : *relevant_events) {
|
||||
@ -104,6 +102,12 @@ bool is_action_allowed(const Action *action, std::vector<Event> *relevant_events
|
||||
return allowed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a ValidationStatus enum value to its corresponding string representation.
|
||||
*
|
||||
* @param status The ValidationStatus enum value to convert.
|
||||
* @return The string representation of the given ValidationStatus.
|
||||
*/
|
||||
std::string ValidationStatusUtils::to_string(ValidationStatus status) {
|
||||
switch (status) {
|
||||
case ValidationStatus::PlayerNotInRoom: return "player not in room";
|
||||
|
||||
@ -20,8 +20,6 @@ enum class ValidationStatus {
|
||||
ActionValid,
|
||||
};
|
||||
|
||||
std::string validation_status_to_string(ValidationStatus status);
|
||||
|
||||
ValidationStatus
|
||||
validate_action(Player *actor, const Action *action, Room *room, std::vector<Event> *relatedEvents, Player *target);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user