diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2022-08-24 00:32:31 +0100 |
---|---|---|
committer | GeckoEidechse <gecko.eidechse+git@pm.me> | 2022-08-25 21:32:55 +0200 |
commit | 46bed8d09f32360377350d71816a76abdfbf2c7c (patch) | |
tree | 7feedae4910dbfe0e53d26ea1e00c4616d2c1850 /NorthstarDLL/scriptsrson.cpp | |
parent | a97f1f07bb5aa31629cd87023e09669eb4bf1fe9 (diff) | |
download | NorthstarLauncher-46bed8d09f32360377350d71816a76abdfbf2c7c.tar.gz NorthstarLauncher-46bed8d09f32360377350d71816a76abdfbf2c7c.zip |
Adjust folder structure (#242)v1.9.5-rc1v1.9.5
* Adjust folder structure
* change launcher directory name
Diffstat (limited to 'NorthstarDLL/scriptsrson.cpp')
-rw-r--r-- | NorthstarDLL/scriptsrson.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/NorthstarDLL/scriptsrson.cpp b/NorthstarDLL/scriptsrson.cpp new file mode 100644 index 00000000..91a12737 --- /dev/null +++ b/NorthstarDLL/scriptsrson.cpp @@ -0,0 +1,67 @@ +#include "pch.h" +#include "modmanager.h" +#include "scriptsrson.h" +#include "filesystem.h" +#include "squirrel.h" + +#include <fstream> + +void ModManager::BuildScriptsRson() +{ + spdlog::info("Building custom scripts.rson"); + fs::path MOD_SCRIPTS_RSON_PATH = fs::path(GetCompiledAssetsPath() / MOD_SCRIPTS_RSON_SUFFIX); + 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(VPK_SCRIPTS_RSON_PATH); + scriptsRson += "\n\n// START MODDED SCRIPT CONTENT\n\n"; // newline before we start custom stuff + + for (Mod& mod : m_loadedMods) + { + if (!mod.Enabled) + continue; + + // this isn't needed at all, just nice to have imo + scriptsRson += "// MOD: "; + scriptsRson += mod.Name; + scriptsRson += ":\n\n"; + + for (ModScript& script : mod.Scripts) + { + /* should create something with this format for each script + 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, std::ios::binary); + writeStream << scriptsRson; + writeStream.close(); + + ModOverrideFile overrideFile; + overrideFile.owningMod = nullptr; + overrideFile.path = VPK_SCRIPTS_RSON_PATH; + + if (m_modFiles.find(VPK_SCRIPTS_RSON_PATH) == m_modFiles.end()) + m_modFiles.insert(std::make_pair(VPK_SCRIPTS_RSON_PATH, overrideFile)); + else + m_modFiles[VPK_SCRIPTS_RSON_PATH] = overrideFile; + + // todo: for preventing dupe scripts in scripts.rson, we could actually parse when conditions with the squirrel vm, just need a way to + // get a result out of squirrelmanager.ExecuteCode this would probably be the best way to do this, imo +}
\ No newline at end of file |