Script loading is quite clunky as it stands right now, given its form of a giant if else block, we would like to see it be cleaned up a bit.
Describe the solution you'd like
Instead of the if else chain in the script loader, something like the following is wanted:
map<string, std::function<CppScripts::Script*()>> ScriptLoader = {
{"scripts/test.lua", [](){ return new Test(); } },
{"scripts/foo.lua", [](){ return new Foo(); } },
// and so it goes
};
When creating the initial copy of a script, the following would be done:
map<string, std::function<CppScripts::Script*()>> ScriptLoader = {
{"scripts/test.lua", [](){ return new Test(); } },
{"scripts/foo.lua", [](){ return new Foo(); } },
// and so it goes
};
std::map<string, CppScripts::Script*> cache;
CppScripts::Script* GetScript(string script_name) {
auto itr = cache.find(script_name);
if (itr != cache.end()) return itr->second;
auto itrLoad = ScriptLoader[script_name];
if (itrLoad == ScriptLoader.end()) {
cache[script_name] = InvalidScript;
return InvalidScript;
}
auto toReturn = itrLoad->second();
cache[script_name] = toReturn;
return toReturn;
}
Repository breaking implications
During the migration, its possible an error could cause a script to be missing accidentally due to a typo or another issue
Describe alternatives you've considered
modifying windows build to support if else chains longer than 128 blocks
Additional context
Shoutouts windows for enforcing a limit that doesnt need to exist
Is your feature request related to a problem?
Script loading is quite clunky as it stands right now, given its form of a giant if else block, we would like to see it be cleaned up a bit.
Describe the solution you'd like
Instead of the if else chain in the script loader, something like the following is wanted:
When creating the initial copy of a script, the following would be done:
Repository breaking implications
During the migration, its possible an error could cause a script to be missing accidentally due to a typo or another issue
Describe alternatives you've considered
modifying windows build to support if else chains longer than 128 blocks
Additional context
Shoutouts windows for enforcing a limit that doesnt need to exist