Line 1: |
Line 1: |
| {{../../header}} | | {{../../header}} |
| | | |
− | ===Content packs===
| + | A '''content pack''' is a special type of mod that isn't run by SMAPI directly, but contains files your own mod can read. |
− | A content pack is a sub-mod containing files your mod can read. These are installed just like a regular SMAPI mod, but don't do anything on their own. These must specify your mod in their <tt>manifest.json</tt>. See [[Modding:Content packs]] for more info about content packs. | |
| | | |
− | SMAPI provides a method to get content packs loaded for your mod, and each content pack has an API you can use to read its files:
| + | __TOC__ |
| + | ==Content pack format== |
| + | A content pack is a folder containing a <tt>manifest.json</tt> file which specifies your mod in its <tt>ContentPackFor</tt> field (see [[../Manifest|manifest]]). The format beyond is up to you to define. For example, {{nexus mod|1915|Content Patcher}} requires a <tt>content.json</tt> file, but that's not validated by SMAPI itself. Instead, SMAPI provides an API you can use to read any other file you need from the content pack. |
| + | |
| + | See [[Modding:Content packs]] for more info about content packs. |
| + | |
| + | ==Content pack API== |
| + | 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.GetContentPacks()) |
| { | | { |
− | // read content pack manifest
| + | 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}");
| |
| | | |
| // read a JSON file | | // read a JSON file |
Line 17: |
Line 22: |
| Texture2D image = contentPack.LoadAsset<Texture2D>("image.png"); | | Texture2D image = contentPack.LoadAsset<Texture2D>("image.png"); |
| } | | } |
| + | </source> |
| + | |
| + | If you need to pass a content pack asset name to game code, you can use its <tt>GetActualAssetKey</tt> method: |
| + | <source lang="c#"> |
| + | tilesheet.ImageSource = contentPack.GetActualAssetKey("image.png"); |
| </source> | | </source> |