R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
GameruleKeys.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** Created on 07/01/2026.
4** File description:
5** GameruleKeys.hpp - Shared gamerule key constants
6*/
7
8#pragma once
9
10#include <optional>
11#include <string>
12#include <unordered_map>
13
29
30namespace GameruleKeys {
31
37 inline const char *toString(GameruleKey key) {
38 switch (key) {
40 return "player.speed";
42 return "player.health";
44 return "player.fireRate";
46 return "player.damage";
48 return "player.spawnX";
50 return "player.spawnY";
52 return "game.speedMultiplier";
53 default:
54 return "unknown";
55 }
56 }
57
63 inline std::optional<GameruleKey> fromString(const std::string &str) {
64 static const std::unordered_map<std::string, GameruleKey> map = {
65 {"player.speed", GameruleKey::PLAYER_SPEED},
66 {"player.health", GameruleKey::PLAYER_HEALTH},
67 {"player.fireRate", GameruleKey::PLAYER_FIRE_RATE},
68 {"player.damage", GameruleKey::PLAYER_DAMAGE},
69 {"player.spawnX", GameruleKey::PLAYER_SPAWN_X},
70 {"player.spawnY", GameruleKey::PLAYER_SPAWN_Y},
71 {"game.speedMultiplier", GameruleKey::GAME_SPEED_MULTIPLIER}};
72
73 auto it = map.find(str);
74 if (it != map.end()) {
75 return it->second;
76 }
77 return std::nullopt;
78 }
79
80 // Legacy constants for backward compatibility (deprecated)
81 [[deprecated("Use GameruleKey::PLAYER_SPEED with GameruleKeys::toString() instead")]]
82 static constexpr const char *PLAYER_SPEED = "player.speed";
83
84 [[deprecated("Use GameruleKey::PLAYER_HEALTH with GameruleKeys::toString() instead")]]
85 static constexpr const char *PLAYER_HEALTH = "player.health";
86
87 [[deprecated("Use GameruleKey::PLAYER_FIRE_RATE with GameruleKeys::toString() instead")]]
88 static constexpr const char *PLAYER_FIRE_RATE = "player.fireRate";
89
90 [[deprecated("Use GameruleKey::PLAYER_DAMAGE with GameruleKeys::toString() instead")]]
91 static constexpr const char *PLAYER_DAMAGE = "player.damage";
92
93 [[deprecated("Use GameruleKey::PLAYER_SPAWN_X with GameruleKeys::toString() instead")]]
94 static constexpr const char *PLAYER_SPAWN_X = "player.spawnX";
95
96 [[deprecated("Use GameruleKey::PLAYER_SPAWN_Y with GameruleKeys::toString() instead")]]
97 static constexpr const char *PLAYER_SPAWN_Y = "player.spawnY";
98
99} // namespace GameruleKeys
GameruleKey
Type-safe enum for gamerule identifiers.
@ GAME_SPEED_MULTIPLIER
Game speed multiplier (0.25 to 1.0, accessibility feature)
const char * toString(GameruleKey key)
Convert GameruleKey enum to string.
std::optional< GameruleKey > fromString(const std::string &str)
Convert string to GameruleKey enum (optional, for deserialization)
static constexpr const char * PLAYER_SPAWN_X
static constexpr const char * PLAYER_SPAWN_Y
static constexpr const char * PLAYER_HEALTH
static constexpr const char * PLAYER_SPEED
static constexpr const char * PLAYER_FIRE_RATE
static constexpr const char * PLAYER_DAMAGE