Update 'Migrating from loose files'

Lucas Schwiderski 2023-11-14 15:05:43 +01:00
parent ceea670738
commit 66937b2c89

@ -1,6 +1,13 @@
> **NOTE**: If this is your first time migrating a mod, I strongly suggest going through [Building your first mod](Building-your-first-mod) once, to play around with and get a feel for the new file structure, as well as how to use DTMT to build the mod bundles. > **NOTE**: If this is your first time migrating a mod, I strongly suggest going through [Building your first mod](Building-your-first-mod) once, to play around with and get a feel for the new file structure, as well as how to use DTMT to build the mod bundles.
## Automatically Migration requires two steps:
1. Rework the project structure and create necessary files to package files into bundles
2. Adjust certain parts of your code
## 1. Rework project structure
### Automatically
For most projects, the built-in migration command should be enough to convert a mod to the DTMT project structure: For most projects, the built-in migration command should be enough to convert a mod to the DTMT project structure:
@ -10,12 +17,12 @@ For most projects, the built-in migration command should be enough to convert a
3. In a Command Prompt (or similar terminal application, e.g. [Windows Terminal](https://learn.microsoft.com/en-us/windows/terminal/install)), execute `dtmt migrate C:\path\to\my_mod.id C:\projects` 3. In a Command Prompt (or similar terminal application, e.g. [Windows Terminal](https://learn.microsoft.com/en-us/windows/terminal/install)), execute `dtmt migrate C:\path\to\my_mod.id C:\projects`
4. Navigate to `C:\projects\<mod_id>` and execute `dtmt build` and `dtmt package` 4. Navigate to `C:\projects\<mod_id>` and execute `dtmt build` and `dtmt package`
## Manually ### Manually
To migrate Lua files from a loose file structure to something that can be built into mod bundles with DTMT, the following is needed: If the automated way doesn't work for you, or you want to dig in and see how it's done, you'll need the following:
- a `dtmt.cfg` that defines the mod's metadata, entry points and packages - a `dtmt.cfg` that defines the mod's metadata, entry points and packages
- at least one `.package` file that includes your Lua files - at least one `.package` file that lists your files to be bundled
One way to quickly generate a skeleton would be to use `dtmt new` in a new location as outlined in [Building your first mod](Building-your-first-mod), then move files over from your old location. One way to quickly generate a skeleton would be to use `dtmt new` in a new location as outlined in [Building your first mod](Building-your-first-mod), then move files over from your old location.
@ -53,3 +60,9 @@ A suggested final file structure looks as follows:
All additional Lua files can then be dropped into `scripts/mods/DMF` (sub-directories are supported) and can be `require`d in-game with the full path, e.g. `require("scripts/mods/DMF/my_extra_file")`. All additional Lua files can then be dropped into `scripts/mods/DMF` (sub-directories are supported) and can be `require`d in-game with the full path, e.g. `require("scripts/mods/DMF/my_extra_file")`.
Modding veterans from VT2 may recognize this file structure 🙂 Modding veterans from VT2 may recognize this file structure 🙂
## 2. Adjust code
- All script loading must happen via the regular Lua `require` or `dofile`. Functions like `mod:io_dofile` don't work anymore.
You can default to using `mod:require` and `mod:dofile`, which switch internally to do "the right thing" for either bundled or non-bundled mods.
- `mod:add_require_path()` only works for non-bundled mods. Any scripts in bundled mods are already available via `require` (hence the point above)