diff --git a/data/assets/base_profile.asset b/data/assets/base_profile.asset new file mode 100644 index 0000000000..67e5ba0556 --- /dev/null +++ b/data/assets/base_profile.asset @@ -0,0 +1,25 @@ +-- This is a base scene that is included in most other scenes to set up defaults +-- loading this scene directly without any other elements added on top of it will +-- probably not work + +local assetHelper = asset.require('util/asset_helper') +local sceneHelper = asset.require('util/scene_helper') +local propertyHelper = asset.require('util/property_helper') + +-- Specifying which other assets should be loaded in this scene +asset.require('spice/base') +-- Load default key bindings applicable to most scenes +asset.require('util/default_keybindings') +asset.require('util/default_dashboard') +asset.require('util/default_joystick') + +-- Load web gui +asset.require('util/webgui') +asset.request('customization/globebrowsing') + +asset.onInitialize(function () + openspace.setDefaultGuiSorting() + openspace.globebrowsing.loadWMSServersFromFile( + openspace.absPath("${DATA}/globebrowsing_servers.lua") + ) +end) \ No newline at end of file diff --git a/data/assets/util/webgui.asset b/data/assets/util/webgui.asset index 25c60c242a..cf1f498148 100644 --- a/data/assets/util/webgui.asset +++ b/data/assets/util/webgui.asset @@ -3,7 +3,7 @@ asset.require('./static_server') local guiCustomization = asset.require('customization/gui') -- Select which commit hashes to use for the frontend and backend -local frontendHash = "129a2c70ec8179b193fdb3a689c37bd65418ac22" +local frontendHash = "785d6fe3416b2e30bed0a04313ef61b0e2729645" local dataProvider = "data.openspaceproject.com/files/webgui" local frontend = asset.syncedResource({ diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index baf10eea25..8728f0d0a4 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -464,6 +464,13 @@ void ScriptEngine::addBaseLibrary() { "true, then the compressed file will be deleted after the decompression " "is finished." }, + { + "saveLastChangeToProfile", + &luascriptfunctions::saveLastChangeToProfile, + {}, + "", + "This function saves the last script log action into the profile " + }, } }; addLibrary(lib); diff --git a/src/scripting/scriptengine_lua.inl b/src/scripting/scriptengine_lua.inl index ce3ef4ccb1..5be9abdd29 100644 --- a/src/scripting/scriptengine_lua.inl +++ b/src/scripting/scriptengine_lua.inl @@ -377,4 +377,71 @@ int unzipFile(lua_State* L) { return 0; } +/** + * \ingroup LuaScripts + * saveLastChangeToProfile(string): + * Saves the last entry from the script log to the current profile + */ +int saveLastChangeToProfile(lua_State* L) { + std::string asset = global::configuration.asset; + std::string logFilePath = absPath(global::configuration.scriptLog); + std::ifstream logfile(logFilePath); + std::string actualLastLine; + std::string lastLine; + std::string line; + //add check for log file + if (!logfile.good()) { + ghoul::lua::push(L, fmt::format("Could not open scriptlog '{}'", logFilePath)); + printInternal(ghoul::logging::LogLevel::Error, L); + } + while (std::getline (logfile,line)) { + actualLastLine = lastLine; + lastLine=line; + } + + std::string dataString = "${ASSETS}/"; + std::string assetPath = absPath(fmt::format("{}{}.scene", dataString, asset)); + std::string tempAssetPath = absPath(fmt::format("{}{}.scene.tmp", dataString, asset)); + std::string strReplace = "--customizations"; + std::string strNew = fmt::format("{}\n{}",strReplace, actualLastLine); + std::ifstream filein(assetPath); + std::ofstream fileout(tempAssetPath); + if(!filein) { + ghoul::lua::push(L, fmt::format("Could not open profile '{}'", assetPath)); + printInternal(ghoul::logging::LogLevel::Error, L); + } + if(!fileout) { + ghoul::lua::push(L, fmt::format("Could not open tmp profile '{}'", tempAssetPath)); + printInternal(ghoul::logging::LogLevel::Error, L); + } + + bool found = false; + while(std::getline (filein, line)) { + if(line == strReplace){ + line = strNew; + found = true; + } + line += "\n"; + fileout << line; + } + filein.close(); + fileout.close(); + if (found) { + int success = rename(tempAssetPath.c_str(), assetPath.c_str()); + if (success != 0) { + std::string error = fmt::format("Error renaming file {} to {}", + tempAssetPath, assetPath); + ghoul::lua::push(L, error); + printInternal(ghoul::logging::LogLevel::Error, L); + return -1; + } + FileSys.deleteFile(tempAssetPath); + return 0; + } else { + ghoul::lua::push(L, "can not save to built in profiles"); + printInternal(ghoul::logging::LogLevel::Error, L); + return -1; + } +} + } // namespace openspace::luascriptfunctions