From 2cf97d763c7a398854aafdc24cddba7c20d0f701 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Thu, 2 Nov 2023 08:09:51 +1100 Subject: [PATCH] add root configuration getters & setters --- source/game/scripting/StarRootLuaBindings.cpp | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/source/game/scripting/StarRootLuaBindings.cpp b/source/game/scripting/StarRootLuaBindings.cpp index de70950..6f8886e 100644 --- a/source/game/scripting/StarRootLuaBindings.cpp +++ b/source/game/scripting/StarRootLuaBindings.cpp @@ -169,6 +169,35 @@ LuaCallbacks LuaBindings::makeRootCallbacks() { return ItemDescriptor(descriptor1).matches(ItemDescriptor(descriptor2), exactMatch.value(false)); }); + callbacks.registerCallback("getConfiguration", [root](String const& key) -> Json { + if (key == "title") + throw StarException(strf("Cannot get {}", key)); + else + return root->configuration()->get(key); + }); + + callbacks.registerCallback("setConfiguration", [root](String const& key, Json const& value) { + if (key == "safeScripts" || key == "configurationVersion") + throw StarException(strf("Cannot set {}", key)); + else + root->configuration()->set(key, value); + }); + + + callbacks.registerCallback("getConfigurationPath", [root](String const& path) -> Json { + if (path.beginsWith("title")) + throw StarException(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)); + else + root->configuration()->setPath(path, value); + }); + return callbacks; }