Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/base/StarConfiguration.cpp10
-rw-r--r--source/game/scripting/StarRootLuaBindings.cpp8
2 files changed, 12 insertions, 6 deletions
diff --git a/source/base/StarConfiguration.cpp b/source/base/StarConfiguration.cpp
index 81c1212..89ec7fa 100644
--- a/source/base/StarConfiguration.cpp
+++ b/source/base/StarConfiguration.cpp
@@ -46,7 +46,10 @@ void Configuration::set(String const& key, Json const& value) {
if (key == "configurationVersion")
throw ConfigurationException("cannot set configurationVersion");
- m_currentConfig = m_currentConfig.set(key, value);
+ if (value)
+ m_currentConfig = m_currentConfig.set(key, value);
+ else
+ m_currentConfig = m_currentConfig.eraseKey(key);
}
void Configuration::setPath(String const& path, Json const& value) {
@@ -54,7 +57,10 @@ void Configuration::setPath(String const& path, Json const& value) {
if (path.splitAny("[].").get(0) == "configurationVersion")
throw ConfigurationException("cannot set configurationVersion");
- m_currentConfig = m_currentConfig.setPath(path, value);
+ if (value)
+ m_currentConfig = m_currentConfig.setPath(path, value);
+ else
+ m_currentConfig = m_currentConfig.erasePath(path);
}
}
diff --git a/source/game/scripting/StarRootLuaBindings.cpp b/source/game/scripting/StarRootLuaBindings.cpp
index 6f8886e..d72748f 100644
--- a/source/game/scripting/StarRootLuaBindings.cpp
+++ b/source/game/scripting/StarRootLuaBindings.cpp
@@ -177,7 +177,7 @@ LuaCallbacks LuaBindings::makeRootCallbacks() {
});
callbacks.registerCallback("setConfiguration", [root](String const& key, Json const& value) {
- if (key == "safeScripts" || key == "configurationVersion")
+ if (key == "safeScripts")
throw StarException(strf("Cannot set {}", key));
else
root->configuration()->set(key, value);
@@ -186,14 +186,14 @@ LuaCallbacks LuaBindings::makeRootCallbacks() {
callbacks.registerCallback("getConfigurationPath", [root](String const& path) -> Json {
if (path.beginsWith("title"))
- throw StarException(strf("Cannot get {}", path));
+ throw ConfigurationException(strf("cannot get {}", path));
else
return root->configuration()->getPath(path);
});
callbacks.registerCallback("setConfigurationPath", [root](String const& path, Json const& value) {
- if (path.beginsWith("safeScripts") || path.beginsWith("configurationVersion"))
- throw StarException(strf("Cannot set {}", path));
+ if (path.beginsWith("safeScripts"))
+ throw ConfigurationException(strf("cannot set {}", path));
else
root->configuration()->setPath(path, value);
});