mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-07 03:49:43 -05:00
Issue/2768 (#2872)
* Rename remote scripting property to reflect better what it does * Change the remote scripting name in all modules * Update all scripts and action calls to use the new property for sync * Simplify code that decides whether to send actions to nodes and peers * Move Lua console hint text to be right top aligned * Update Lua script topic * Added new JSON key whether or not the script should be synced to other nodes and peers * Per default all scripts sync to everyone In the next full release, we should have two separate keys that decides whether to sync and send to nodes and peers separately * Add some comments that explain why there is no sync for some scripts * Make sync argument in trigger action function BooleanType
This commit is contained in:
@@ -35,7 +35,7 @@ public:
|
||||
bool isDone() const override;
|
||||
|
||||
private:
|
||||
void runScript(std::string script, bool returnValue);
|
||||
void runScript(std::string script, bool returnValue, bool shouldBeSynchronized);
|
||||
|
||||
bool _waitingForReturnValue = true;
|
||||
};
|
||||
|
||||
@@ -467,7 +467,8 @@ void FlightControllerTopic::processLua(const nlohmann::json &json) {
|
||||
const std::string script = json[LuaScript];
|
||||
global::scriptEngine->queueScript(
|
||||
script,
|
||||
openspace::scripting::ScriptEngine::RemoteScripting::Yes
|
||||
scripting::ScriptEngine::ShouldBeSynchronized::Yes,
|
||||
scripting::ScriptEngine::ShouldSendToRemote::Yes
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace {
|
||||
constexpr std::string_view KeyFunction = "function";
|
||||
constexpr std::string_view KeyArguments = "arguments";
|
||||
constexpr std::string_view KeyReturn = "return";
|
||||
constexpr std::string_view KeyShouldBeSynchronized = "shouldBeSynchronized";
|
||||
constexpr std::string_view _loggerCat = "LuaScriptTopic";
|
||||
|
||||
std::string formatLua(const nlohmann::json::const_iterator& it);
|
||||
@@ -146,7 +147,13 @@ void LuaScriptTopic::handleJson(const nlohmann::json& json) {
|
||||
ret->is_boolean() &&
|
||||
ret->get<bool>();
|
||||
|
||||
runScript(luaScript, shouldReturn);
|
||||
nlohmann::json::const_iterator sync = json.find(KeyShouldBeSynchronized);
|
||||
bool shouldBeSynchronized = true;
|
||||
if (sync != json.end() && sync->is_boolean()) {
|
||||
shouldBeSynchronized = sync->get<bool>();
|
||||
}
|
||||
|
||||
runScript(luaScript, shouldReturn, shouldBeSynchronized);
|
||||
}
|
||||
else if (function != json.end() && function->is_string()) {
|
||||
std::string luaFunction = function->get<std::string>();
|
||||
@@ -155,6 +162,12 @@ void LuaScriptTopic::handleJson(const nlohmann::json& json) {
|
||||
ret->is_boolean() &&
|
||||
ret->get<bool>();
|
||||
|
||||
nlohmann::json::const_iterator sync = json.find(KeyShouldBeSynchronized);
|
||||
bool shouldBeSynchronized = true;
|
||||
if (sync != json.end() && sync->is_boolean()) {
|
||||
shouldBeSynchronized = sync->get<bool>();
|
||||
}
|
||||
|
||||
nlohmann::json::const_iterator args = json.find(KeyArguments);
|
||||
if (!args->is_array()) {
|
||||
return;
|
||||
@@ -167,7 +180,7 @@ void LuaScriptTopic::handleJson(const nlohmann::json& json) {
|
||||
}
|
||||
|
||||
std::string luaScript = generateScript(luaFunction, formattedArgs);
|
||||
runScript(luaScript, shouldReturn);
|
||||
runScript(luaScript, shouldReturn, shouldBeSynchronized);
|
||||
}
|
||||
}
|
||||
catch (const std::out_of_range& e) {
|
||||
@@ -176,7 +189,9 @@ void LuaScriptTopic::handleJson(const nlohmann::json& json) {
|
||||
}
|
||||
}
|
||||
|
||||
void LuaScriptTopic::runScript(std::string script, bool shouldReturn) {
|
||||
void LuaScriptTopic::runScript(std::string script, bool shouldReturn,
|
||||
bool shouldBeSynchronized)
|
||||
{
|
||||
scripting::ScriptEngine::ScriptCallback callback;
|
||||
if (shouldReturn) {
|
||||
callback = [this](ghoul::Dictionary data) {
|
||||
@@ -195,7 +210,8 @@ void LuaScriptTopic::runScript(std::string script, bool shouldReturn) {
|
||||
|
||||
global::scriptEngine->queueScript(
|
||||
std::move(script),
|
||||
scripting::ScriptEngine::RemoteScripting::No,
|
||||
scripting::ScriptEngine::ShouldBeSynchronized(shouldBeSynchronized),
|
||||
scripting::ScriptEngine::ShouldSendToRemote(shouldBeSynchronized),
|
||||
callback
|
||||
);
|
||||
}
|
||||
|
||||
@@ -126,7 +126,8 @@ void SetPropertyTopic::handleJson(const nlohmann::json& json) {
|
||||
fmt::format(
|
||||
"openspace.setPropertyValueSingle(\"{}\", {})", propertyKey, literal
|
||||
),
|
||||
scripting::ScriptEngine::RemoteScripting::Yes
|
||||
scripting::ScriptEngine::ShouldBeSynchronized::Yes,
|
||||
scripting::ScriptEngine::ShouldSendToRemote::Yes
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@ void TriggerPropertyTopic::handleJson(const nlohmann::json& json) {
|
||||
fmt::format(
|
||||
"openspace.setPropertyValueSingle(\"{}\", nil)", propertyKey
|
||||
),
|
||||
scripting::ScriptEngine::RemoteScripting::Yes
|
||||
scripting::ScriptEngine::ShouldBeSynchronized::Yes,
|
||||
scripting::ScriptEngine::ShouldSendToRemote::Yes
|
||||
);
|
||||
}
|
||||
catch (const std::out_of_range& e) {
|
||||
|
||||
Reference in New Issue
Block a user