| 1755 | } |
| 1756 | |
| 1757 | void 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 | |
| 1798 | void Core::onStateChange(color_ostream &out, state_change_event event) |
| 1799 | { |
nothing calls this directly
no test coverage detected