Changes
Jump to navigation
Jump to search
← Older edit
Newer edit →
Modding:Modder Guide/APIs/Content Packs
(view source)
Revision as of 16:05, 17 December 2018
558 bytes removed
,
16:05, 17 December 2018
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
Pathoschild
translators
8,404
edits
Navigation menu
Personal tools
Create account
Log in
Namespaces
Modding
Discussion
Variants
Views
Read
View source
View history
More
Search
Navigation
Main page
Recent changes
Admin noticeboard
Help Editing
Random page
Official Links
Official Site
Official Forums
Official Merchandise
Discord
Reddit
Tools
Upload file
Special pages
Printable version