change settings to be a hash map instead of a fixed struct

this makes adding settings and changing settings incredibly easy, both
from the console and from lua.
This commit is contained in:
Lion Kortlepel
2022-10-23 17:44:57 +02:00
parent 7d35595683
commit bec09a4761
14 changed files with 250 additions and 248 deletions

View File

@@ -208,56 +208,56 @@ void LuaAPI::MP::Set(int ConfigID, sol::object NewValue) {
switch (ConfigID) {
case 0: // debug
if (NewValue.is<bool>()) {
Application::Settings.DebugModeEnabled = NewValue.as<bool>();
beammp_info(std::string("Set `Debug` to ") + (Application::Settings.DebugModeEnabled ? "true" : "false"));
Application::SetSetting(StrDebug, NewValue.as<bool>());
beammp_info(std::string("Set `Debug` to ") + (Application::GetSettingBool(StrDebug) ? "true" : "false"));
} else {
beammp_lua_error("set invalid argument [2] expected boolean");
}
break;
case 1: // private
if (NewValue.is<bool>()) {
Application::Settings.Private = NewValue.as<bool>();
beammp_info(std::string("Set `Private` to ") + (Application::Settings.Private ? "true" : "false"));
Application::SetSetting(StrPrivate, NewValue.as<bool>());
beammp_info(std::string("Set `Private` to ") + (Application::GetSettingBool(StrPrivate) ? "true" : "false"));
} else {
beammp_lua_error("set invalid argument [2] expected boolean");
}
break;
case 2: // max cars
if (NewValue.is<int>()) {
Application::Settings.MaxCars = NewValue.as<int>();
beammp_info(std::string("Set `MaxCars` to ") + std::to_string(Application::Settings.MaxCars));
Application::SetSetting(StrMaxCars, NewValue.as<int>());
beammp_info(std::string("Set `MaxCars` to ") + std::to_string(Application::GetSettingInt(StrMaxCars)));
} else {
beammp_lua_error("set invalid argument [2] expected integer");
}
break;
case 3: // max players
if (NewValue.is<int>()) {
Application::Settings.MaxPlayers = NewValue.as<int>();
beammp_info(std::string("Set `MaxPlayers` to ") + std::to_string(Application::Settings.MaxPlayers));
Application::SetSetting(StrMaxPlayers, NewValue.as<int>());
beammp_info(std::string("Set `MaxPlayers` to ") + std::to_string(Application::GetSettingInt(StrMaxPlayers)));
} else {
beammp_lua_error("set invalid argument [2] expected integer");
}
break;
case 4: // Map
if (NewValue.is<std::string>()) {
Application::Settings.MapName = NewValue.as<std::string>();
beammp_info(std::string("Set `Map` to ") + Application::Settings.MapName);
Application::SetSetting(StrMap, NewValue.as<std::string>());
beammp_info(std::string("Set `Map` to ") + Application::GetSettingString(StrMap));
} else {
beammp_lua_error("set invalid argument [2] expected string");
}
break;
case 5: // Name
if (NewValue.is<std::string>()) {
Application::Settings.ServerName = NewValue.as<std::string>();
beammp_info(std::string("Set `Name` to ") + Application::Settings.ServerName);
Application::SetSetting(StrName, NewValue.as<std::string>());
beammp_info(std::string("Set `Name` to ") + Application::GetSettingString(StrName));
} else {
beammp_lua_error("set invalid argument [2] expected string");
}
break;
case 6: // Desc
if (NewValue.is<std::string>()) {
Application::Settings.ServerDesc = NewValue.as<std::string>();
beammp_info(std::string("Set `Description` to ") + Application::Settings.ServerDesc);
Application::SetSetting(StrDescription, NewValue.as<std::string>());
beammp_info(std::string("Set `Description` to ") + Application::GetSettingString(StrDescription));
} else {
beammp_lua_error("set invalid argument [2] expected string");
}