diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-07-23 15:36:18 +0100 |
---|---|---|
committer | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-07-23 15:36:18 +0100 |
commit | 844e12403400b455fe5df8c2e19145a2ed1a7d45 (patch) | |
tree | 81839795869676892b0219d4d1533fb40d6074af /NorthstarDedicatedTest/scriptsrson.cpp | |
parent | 23a1dafcde70822a9899e9aab190f36521c1aedd (diff) | |
download | NorthstarLauncher-844e12403400b455fe5df8c2e19145a2ed1a7d45.tar.gz NorthstarLauncher-844e12403400b455fe5df8c2e19145a2ed1a7d45.zip |
add support for building scripts.rson at runtime
Diffstat (limited to 'NorthstarDedicatedTest/scriptsrson.cpp')
-rw-r--r-- | NorthstarDedicatedTest/scriptsrson.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/NorthstarDedicatedTest/scriptsrson.cpp b/NorthstarDedicatedTest/scriptsrson.cpp new file mode 100644 index 00000000..05386910 --- /dev/null +++ b/NorthstarDedicatedTest/scriptsrson.cpp @@ -0,0 +1,51 @@ +#include "pch.h" +#include "modmanager.h" +#include "scriptsrson.h" +#include "filesystem.h" + +#include <sstream> +#include <fstream> + +void ModManager::BuildScriptsRson() +{ + spdlog::info("Building custom scripts.rson"); + fs::remove(MOD_SCRIPTS_RSON_PATH); + + // not really important since it doesn't affect actual functionality at all, but the rson we output is really weird + // has a shitload of newlines added, even in places where we don't modify it at all + + std::string scriptsRson = ReadVPKOriginalFile("scripts/vscripts/scripts.rson"); + scriptsRson += "\n\n// START MODDED SCRIPT CONTENT\n\n"; // newline before we start custom stuff + + for (Mod* mod : m_loadedMods) + { + for (ModScript* script : mod->Scripts) + { + /* should create something with the format + When: "CONTEXT" + Scripts: + [ + "_coolscript.gnut" + ]*/ + + scriptsRson += "When: \""; + scriptsRson += script->RsonRunOn; + scriptsRson += "\"\n"; + + scriptsRson += "Scripts:\n[\n\t"; + scriptsRson += script->Path; + scriptsRson += "\n]\n\n"; + } + } + + fs::create_directories(MOD_SCRIPTS_RSON_PATH.parent_path()); + + std::ofstream writeStream(MOD_SCRIPTS_RSON_PATH); + writeStream << scriptsRson; + writeStream.close(); + + ModOverrideFile* overrideFile = new ModOverrideFile; + overrideFile->owningMod = nullptr; + overrideFile->path = "scripts/vscripts/scripts.rson"; + m_modFiles.push_back(overrideFile); +}
\ No newline at end of file |