Changes

Jump to navigation Jump to search
update for SMAPI 2.9.3
Line 12: Line 12:  
You can get a list of content packs installed for your mod, and access the files within it:
 
You can get a list of content packs installed for your mod, and access the files within it:
 
<source lang="c#">
 
<source lang="c#">
foreach(IContentPack contentPack in this.Helper.GetContentPacks())
+
foreach(IContentPack contentPack in this.Helper.ContentPacks.GetOwned())
 
{
 
{
 
   this.Monitor.Log($"Reading content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}");
 
   this.Monitor.Log($"Reading content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}");
Line 29: Line 29:  
</source>
 
</source>
   −
{{SMAPI upcoming|2.10|
+
In specialised cases, you can create a temporary content pack for a given directory path:
You can get a list of content packs installed for your mod, and access the files within it:
  −
<source lang="c#">
  −
foreach(IContentPack contentPack in this.Helper.ContentPacks.GetOwned())
  −
{
  −
  this.Monitor.Log($"Reading content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}");
  −
 
  −
    // read a JSON file
  −
    YourDataFile data = contentPack.ReadJsonFile<YourDataFile>("content.json");
  −
 
  −
    // load an asset or image
  −
    Texture2D image = contentPack.LoadAsset<Texture2D>("image.png");
  −
}
  −
</source>
  −
 
  −
In specialised cases, you can create a fake content pack for a given directory path:
   
<source lang="c#">
 
<source lang="c#">
 
// create with random manifest data
 
// create with random manifest data
Line 61: Line 46:  
);
 
);
 
</source>
 
</source>
}}
      
{{modding guide footer
 
{{modding guide footer
translators
8,404

edits

Navigation menu