12#include <unordered_map>
68 float get(
const std::string &key,
float defaultValue = 0.0f)
const {
69 std::scoped_lock lock(
mutex_);
70 auto it =
rules_.find(key);
71 return (it !=
rules_.end()) ? it->second : defaultValue;
86 void update(
const std::string &key,
float value) {
87 std::scoped_lock lock(
mutex_);
95 void updateMultiple(
const std::unordered_map<std::string, float> &gamerules) {
96 std::scoped_lock lock(
mutex_);
97 for (
const auto &[key, value] : gamerules) {
114 bool has(
const std::string &key)
const {
115 std::scoped_lock lock(
mutex_);
123 std::scoped_lock lock(
mutex_);
132 std::scoped_lock lock(
mutex_);
141 std::unordered_map<std::string, float>
rules_;
GameruleKey
Type-safe enum for gamerule identifiers.
Client-side storage for game rules synchronized from server.
float get(const std::string &key, float defaultValue=0.0f) const
Get a gamerule value (string version)
void update(const std::string &key, float value)
Update a gamerule value (string version)
ClientGameRules & operator=(const ClientGameRules &)=delete
static ClientGameRules & getInstance()
Get the singleton instance.
void updateMultiple(const std::unordered_map< std::string, float > &gamerules)
Update multiple gamerules at once.
float get(GameruleKey key, float defaultValue=0.0f) const
Get a gamerule value (type-safe with enum)
~ClientGameRules()=default
std::unordered_map< std::string, float > rules_
bool has(GameruleKey key) const
Check if a gamerule exists (type-safe with enum)
void clear()
Clear all gamerules.
ClientGameRules()=default
void update(GameruleKey key, float value)
Update a gamerule value (type-safe with enum)
ClientGameRules(const ClientGameRules &)=delete
bool has(const std::string &key) const
Check if a gamerule exists (string version)
size_t size() const
Get the number of stored gamerules.
const char * toString(GameruleKey key)
Convert GameruleKey enum to string.