Line 283: |
Line 283: |
| You can let users configure your mod through a <tt>config.json</tt> file. SMAPI will automatically create the file and take care of reading, normalising, and updating it. | | You can let users configure your mod through a <tt>config.json</tt> file. SMAPI will automatically create the file and take care of reading, normalising, and updating it. |
| | | |
− | ====Basic configuration====
| + | <dl> |
− | Here's the simplest way to use <tt>config.json</tt>: | + | <dt>Basic configuration</dt> |
| + | <dd>Here's the simplest way to use <tt>config.json</tt>: |
| | | |
| <ol> | | <ol> |
Line 323: |
Line 324: |
| </ol> | | </ol> |
| | | |
− | That's it! When the player launches the game, SMAPI will create the <tt>config.json</tt> file automatically if it doesn't exist yet, using the default config options you provided in your model. If you need to edit and save the config, you can use <tt>helper.SaveConfig(config)</tt>. You can access the helper in other methods using <tt>this.Helper</tt>. | + | That's it! When the player launches the game, SMAPI will create the <tt>config.json</tt> file automatically if it doesn't exist yet, using the default config options you provided in your model. If you need to edit and save the config, you can use <tt>helper.SaveConfig(config)</tt>. You can access the helper in other methods using <tt>this.Helper</tt>.</dd> |
| | | |
− | ====Custom JSON files====
| + | <dt>Custom JSON files</dt> |
| + | <dd> |
| Sometimes one <tt>config.json</tt> isn't enough, or you need to store data that's not meant to be edited by the user. This is pretty easy using the <tt>ModHelper</tt>: | | Sometimes one <tt>config.json</tt> isn't enough, or you need to store data that's not meant to be edited by the user. This is pretty easy using the <tt>ModHelper</tt>: |
| | | |
Line 341: |
Line 343: |
| | | |
| Note that <tt>ReadJsonFile</tt> will return <tt>null</tt> if the file doesn't exist. The above example will create a default instance if that happens; if you don't want to do that, just remove the <code>?? new ModData()</code> part.</li> | | Note that <tt>ReadJsonFile</tt> will return <tt>null</tt> if the file doesn't exist. The above example will create a default instance if that happens; if you don't want to do that, just remove the <code>?? new ModData()</code> part.</li> |
− | </ol> | + | </ol></dd> |
| | | |
− | ====Per-save JSON files====
| + | <dt>Per-save JSON files</dt> |
| + | <dd> |
| You can create per-save files by using the save ID in the name. If you specify a folder path (relative to your mod folder), SMAPI will create the folders automatically if needed. | | You can create per-save files by using the save ID in the name. If you specify a folder path (relative to your mod folder), SMAPI will create the folders automatically if needed. |
| | | |
Line 354: |
Line 357: |
| // write file (if needed) | | // write file (if needed) |
| this.Helper.WriteJsonFile($"data/{Constants.SaveFolderName}.json", model); | | this.Helper.WriteJsonFile($"data/{Constants.SaveFolderName}.json", model); |
− | </source> | + | </source></dd> |
| + | </dl> |
| | | |
| ===Console commands=== | | ===Console commands=== |