From 50cc6d965dd4ede112432ff3a202204ce6716a66 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 15 Jan 2023 23:13:58 -0800 Subject: [PATCH 1/4] update to new save directory structure --- ci/download-df.sh | 6 +++--- docs/Core.rst | 14 ++++++-------- docs/guides/modding-guide.rst | 3 +-- library/Core.cpp | 8 +++----- library/lua/dfhack.lua | 2 +- plugins/autogems.cpp | 2 +- plugins/rendermax/renderer_light.cpp | 4 ++-- plugins/tweak/tweaks/title-start-rename.h | 2 +- 8 files changed, 18 insertions(+), 23 deletions(-) diff --git a/ci/download-df.sh b/ci/download-df.sh index bb1e91759..8d94d54dd 100755 --- a/ci/download-df.sh +++ b/ci/download-df.sh @@ -23,7 +23,7 @@ if ! test -f "$df_tardest"; then fi done <}/raw/scripts` (only if a save is loaded) -#. :file:`raw/scripts` +#. :file:`save/{world}/scripts` (only if a save is loaded) #. :file:`hack/scripts` For example, if ``teleport`` is run, these folders are searched in order for -``teleport.lua`` or ``teleport.rb``, and the first matching file is run. +``teleport.lua``, and the first matching file is run. Script paths can be added by modifying :file:`dfhack-config/script-paths.txt`. Each line should start with one of these characters: diff --git a/docs/guides/modding-guide.rst b/docs/guides/modding-guide.rst index 9fe62bf6a..ab52e0288 100644 --- a/docs/guides/modding-guide.rst +++ b/docs/guides/modding-guide.rst @@ -61,8 +61,7 @@ be: 1. ``own-scripts/`` 2. ``dfhack-config/scripts/`` -3. ``data/save/*/raw/scripts/`` -4. ``raw/scripts/`` +3. ``save/*/scripts/`` 5. ``hack/scripts/`` The structure of the game diff --git a/library/Core.cpp b/library/Core.cpp index 78257a262..e2c983116 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -472,9 +472,8 @@ void Core::getScriptPaths(std::vector *dest) if (df::global::world && isWorldLoaded()) { string save = World::ReadWorldFolder(); if (save.size()) - dest->push_back(df_path + "/data/save/" + save + "/raw/scripts"); + dest->push_back(df_path + "/save/" + save + "/scripts"); } - dest->push_back(df_path + "/raw/scripts"); dest->push_back(df_path + "/hack/scripts"); for (auto it = script_paths[1].begin(); it != script_paths[1].end(); ++it) dest->push_back(*it); @@ -2053,7 +2052,7 @@ void Core::handleLoadAndUnloadScripts(color_ostream& out, state_change_event eve if (!df::global::world) return; - std::string rawFolder = "data/save/" + (df::global::world->cur_savegame.save_dir) + "/raw/"; + std::string rawFolder = "save/" + (df::global::world->cur_savegame.save_dir) + "/init"; auto i = table.find(event); if ( i != table.end() ) { @@ -2064,7 +2063,6 @@ void Core::handleLoadAndUnloadScripts(color_ostream& out, state_change_event eve loadScriptFiles(this, out, set, CONFIG_PATH + "init"); loadScriptFiles(this, out, set, rawFolder); - loadScriptFiles(this, out, set, rawFolder + "objects/"); } for (auto it = state_change_scripts.begin(); it != state_change_scripts.end(); ++it) @@ -2125,7 +2123,7 @@ void Core::onStateChange(color_ostream &out, state_change_event event) case SC_MAP_UNLOADED: if (world && world->cur_savegame.save_dir.size()) { - std::string save_dir = "data/save/" + world->cur_savegame.save_dir; + std::string save_dir = "save/" + world->cur_savegame.save_dir; std::string evtlogpath = save_dir + "/events-dfhack.log"; std::ofstream evtlog; evtlog.open(evtlogpath, std::ios_base::app); // append diff --git a/library/lua/dfhack.lua b/library/lua/dfhack.lua index df6302b82..a4d233a9e 100644 --- a/library/lua/dfhack.lua +++ b/library/lua/dfhack.lua @@ -871,7 +871,7 @@ end function dfhack.getSavePath() if dfhack.isWorldLoaded() then - return dfhack.getDFPath() .. '/data/save/' .. df.global.world.cur_savegame.save_dir + return dfhack.getDFPath() .. '/save/' .. df.global.world.cur_savegame.save_dir end end diff --git a/plugins/autogems.cpp b/plugins/autogems.cpp index 8cf419aba..87eaafd16 100644 --- a/plugins/autogems.cpp +++ b/plugins/autogems.cpp @@ -299,7 +299,7 @@ IMPLEMENT_VMETHOD_INTERPOSE(autogem_hook, feed); IMPLEMENT_VMETHOD_INTERPOSE(autogem_hook, render); bool read_config(color_ostream &out) { - std::string path = "data/save/" + World::ReadWorldFolder() + "/autogems.json"; + std::string path = "save/" + World::ReadWorldFolder() + "/autogems.json"; if (!Filesystem::isfile(path)) { // no need to require the config file to exist return true; diff --git a/plugins/rendermax/renderer_light.cpp b/plugins/rendermax/renderer_light.cpp index 428de3a25..d806d0c3e 100644 --- a/plugins/rendermax/renderer_light.cpp +++ b/plugins/rendermax/renderer_light.cpp @@ -1171,11 +1171,11 @@ void lightingEngineViewscreen::loadSettings() std::string rawFolder; if(df::global::world->cur_savegame.save_dir!="") { - rawFolder= "data/save/" + (df::global::world->cur_savegame.save_dir) + "/raw/"; + rawFolder= "save/" + (df::global::world->cur_savegame.save_dir) + "/"; } else { - rawFolder= "raw/"; + rawFolder= "dfhack-config/"; } const std::string settingsfile=rawFolder+"rendermax.lua"; diff --git a/plugins/tweak/tweaks/title-start-rename.h b/plugins/tweak/tweaks/title-start-rename.h index baa1552ab..289979be4 100644 --- a/plugins/tweak/tweaks/title-start-rename.h +++ b/plugins/tweak/tweaks/title-start-rename.h @@ -17,7 +17,7 @@ struct title_start_rename_hook : df::viewscreen_titlest { inline std::string full_save_dir(const std::string ®ion_name) { - return std::string("data/save/") + region_name; + return std::string("save/") + region_name; } bool do_rename() From 762cd46d14be7738464c430ec4919092882654e4 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 15 Jan 2023 23:28:01 -0800 Subject: [PATCH 2/4] look for init.d directories in the root instead of raw/ --- docs/Core.rst | 6 +++--- docs/dev/Lua API.rst | 4 ++-- docs/guides/modding-guide.rst | 14 +++++++------- library/lua/dfhack.lua | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/Core.rst b/docs/Core.rst index 28e20a827..86e357b27 100644 --- a/docs/Core.rst +++ b/docs/Core.rst @@ -216,10 +216,10 @@ after a modded save is unloaded. .. _other_init_files: -raw/init.d/\*.lua -................. +init.d/\*.lua +............. -Any lua script named ``raw/init.d/*.lua``, in the save or main DF directory, +Any lua script named ``init.d/*.lua``, in the save or main DF directory, will be run when any world or that save is loaded. diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 39bd57046..813406013 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -5883,9 +5883,9 @@ all script modules. Save init script ================ -If a save directory contains a file called ``raw/init.lua``, it is +If a save directory contains a file called ``init.lua``, it is automatically loaded and executed every time the save is loaded. -The same applies to any files called ``raw/init.d/*.lua``. Every +The same applies to any files called ``init.d/*.lua``. Every such script can define the following functions to be called by dfhack: * ``function onStateChange(op) ... end`` diff --git a/docs/guides/modding-guide.rst b/docs/guides/modding-guide.rst index ab52e0288..224448cf1 100644 --- a/docs/guides/modding-guide.rst +++ b/docs/guides/modding-guide.rst @@ -358,7 +358,7 @@ names for the mod folders within it. In the example below, we'll use a mod ID of ``example-mod`` mod will be developed in the ``/path/to/mymods/example-mod/`` directory and has a basic structure that looks like this:: - raw/init.d/example-mod.lua + init.d/example-mod.lua raw/objects/... raw/scripts/example-mod.lua raw/scripts/example-mod/... @@ -366,13 +366,13 @@ directory and has a basic structure that looks like this:: Let's go through that line by line. -* A short (one-line) script in ``raw/init.d/`` to initialise your +* A short (one-line) script in ``init.d/`` to initialise your mod when a save is loaded. * Modifications to the game raws (potentially with custom raw tokens) go in ``raw/objects/``. -* A control script in ``raw/scripts/`` that handles enabling and disabling your +* A control script in ``scripts/`` that handles enabling and disabling your mod. -* A subfolder for your mod under ``raw/scripts/`` will contain all the internal +* A subfolder for your mod under ``scripts/`` will contain all the internal scripts and/or modules used by your mod. It is a good idea to use a version control system to organize changes to your @@ -384,10 +384,10 @@ Unless you want to install your ``raw/`` folder into your DF game folder every time you make a change to your scripts, you should add your development scripts directory to your script paths in ``dfhack-config/script-paths.txt``:: - +/path/to/mymods/example-mod/raw/scripts/ + +/path/to/mymods/example-mod/scripts/ Ok, you're all set up! Now, let's take a look at an example -``raw/scripts/example-mod.lua`` file:: +``scripts/example-mod.lua`` file:: -- main setup and teardown for example-mod -- this next line indicates that the script supports the "enable" @@ -474,7 +474,7 @@ Ok, you're all set up! Now, let's take a look at an example You can call ``enable example-mod`` and ``disable example-mod`` yourself while developing, but for end users you can start your mod automatically from -``raw/init.d/example-mod.lua``:: +``init.d/example-mod.lua``:: dfhack.run_command('enable example-mod') diff --git a/library/lua/dfhack.lua b/library/lua/dfhack.lua index a4d233a9e..e2cb7069b 100644 --- a/library/lua/dfhack.lua +++ b/library/lua/dfhack.lua @@ -905,14 +905,14 @@ if dfhack.is_core_context then local path = dfhack.getSavePath() if path and op == SC_WORLD_LOADED then - loadInitFile(path, path..'/raw/init.lua') + loadInitFile(path, path..'/init.lua') - local dirlist = dfhack.internal.getDir(path..'/raw/init.d/') + local dirlist = dfhack.internal.getDir(path..'/init.d/') if dirlist then table.sort(dirlist) for i,name in ipairs(dirlist) do if string.match(name,'%.lua$') then - loadInitFile(path, path..'/raw/init.d/'..name) + loadInitFile(path, path..'/init.d/'..name) end end end From a56d62e1dc86e281fe2e99e9910bb25c43d7182b Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 15 Jan 2023 23:28:14 -0800 Subject: [PATCH 3/4] update changelog --- docs/changelog.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 0deac83e8..06c3975ca 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -42,6 +42,8 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - Scrollable widgets now react to mouse wheel events when the mouse is over the widget - the ``dfhack-config/scripts/`` folder is now searched for scripts by default - `hotkeys`: overlay hotspot widget now shows the DFHack logo in graphics mode and "DFHack" in text mode +- `script-paths`: removed "raw" directories from default script paths. now the default locations to search for scripts are ``dfhack-config/scripts``, ``save/*/scripts``, and ``hack/scripts`` +- ``init.d``: directories have moved from the ``raw`` subfolder (which no longer exists) to the root of the main DF folder or a savegame folder ## Documentation - `overlay-dev-guide`: added troubleshooting tips and common development workflows @@ -69,8 +71,6 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - ``gui.CLEAR_PEN``: now clears the background and foreground and writes to the background (before it would always write to the foreground) - ``gui.KEEP_LOWER_PEN``: a general use pen that writes associated tiles to the foreground while keeping the existing background -## Internals - ## Removed - ``fix-job-postings`` from the `workflow` plugin is now obsolete since affected savegames can no longer be loaded - Ruby is no longer a supported DFHack scripting language From 00cee1c6002107637c5fc31c68a3da6408c6e4c5 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Mon, 16 Jan 2023 11:03:51 -0800 Subject: [PATCH 4/4] fix numbered list --- docs/guides/modding-guide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/modding-guide.rst b/docs/guides/modding-guide.rst index 224448cf1..73d9407d6 100644 --- a/docs/guides/modding-guide.rst +++ b/docs/guides/modding-guide.rst @@ -62,7 +62,7 @@ be: 1. ``own-scripts/`` 2. ``dfhack-config/scripts/`` 3. ``save/*/scripts/`` -5. ``hack/scripts/`` +4. ``hack/scripts/`` The structure of the game -------------------------