MCPcopy Create free account
hub / github.com/DFHack/dfhack / handleLoadAndUnloadScripts

Method handleLoadAndUnloadScripts

library/Core.cpp:1757–1796  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1755}
1756
1757void Core::handleLoadAndUnloadScripts(color_ostream& out, state_change_event event) {
1758 static const X::InitVariationTable table = X::getTable(X::computeInitVariationTable(
1759 SC_WORLD_LOADED, "onLoad", "onLoadWorld", "onWorldLoaded",
1760 SC_WORLD_UNLOADED, "onUnload", "onUnloadWorld", "onWorldUnloaded",
1761 SC_MAP_LOADED, "onMapLoad", "onLoadMap",
1762 SC_MAP_UNLOADED, "onMapUnload", "onUnloadMap",
1763 SC_UNKNOWN
1764 ));
1765
1766 if (!df::global::world)
1767 return;
1768
1769 std::filesystem::path rawFolder = !isWorldLoaded() ? Filesystem::getInstallDir() : Filesystem::getBaseDir() / "save" / World::ReadWorldFolder() / "init";
1770
1771 auto i = table.find(event);
1772 if ( i != table.end() ) {
1773 const std::vector<std::string>& set = i->second;
1774
1775 // load baseline defaults
1776 this->loadScriptFile(out, getConfigPath() / "init" / ("default." + set[0] + ".init"), false);
1777
1778 loadScriptFiles(this, out, set, getConfigPath() / "init");
1779 loadScriptFiles(this, out, set, rawFolder);
1780 }
1781
1782 for (const auto& script : state_change_scripts)
1783 {
1784 if (script.event == event)
1785 {
1786 if (!script.save_specific)
1787 {
1788 loadScriptFile(out, script.path, false);
1789 }
1790 else if (script.save_specific && isWorldLoaded())
1791 {
1792 loadScriptFile(out, rawFolder / script.path, false);
1793 }
1794 }
1795 }
1796}
1797
1798void Core::onStateChange(color_ostream &out, state_change_event event)
1799{

Callers

nothing calls this directly

Calls 8

loadScriptFileMethod · 0.95
getTableFunction · 0.85
getConfigPathFunction · 0.85
loadScriptFilesFunction · 0.85
isWorldLoadedFunction · 0.70
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected