Changes

Jump to navigation Jump to search
→‎Metadata: + mod path
Line 4: Line 4:     
==Metadata==
 
==Metadata==
 +
===Mod path===
 +
SMAPI APIs use relative paths, so you rarely need the absolute path:
 +
<source lang="c#">
 +
var data = helper.Data.ReadJsonFile<SomeDataModel>("assets/data.json");
 +
</source>
 +
 +
When you do need an absolute path, note that the '''mod's install path is not consistent'''. The game is installed to different paths, Nexus mods are often unzipped into a folder like <tt>Mods/Your Mod Name 1.27.5-541-1-27-5-1598664794/YourModFolder</tt> by default, and players can organize their mod folders like <tt>Mods/For single-player/YourModFolder</tt>. You should use the <code>this.Helper.DirectoryPath</code> to get an absolute path if you need it:
 +
<source lang="c#">
 +
string filePath = Path.Combine(this.Helper.DirectoryPath, "assets", "data.json");
 +
var file = new FileInfo(filePath);
 +
</source>
 +
 +
See ''[[#Constants|Constants]]'' for other paths.
 +
 
===Constants===
 
===Constants===
 
The <tt>Constants</tt> class provides metadata about SMAPI and the game.
 
The <tt>Constants</tt> class provides metadata about SMAPI and the game.
translators
8,403

edits

Navigation menu