Changes

Jump to navigation Jump to search
→‎Read mod assets: rework text, add JSON files in SMAPI 2.7
Line 25: Line 25:  
==Read assets==
 
==Read assets==
 
===Read mod assets===
 
===Read mod assets===
You can read custom assets from your mod folder. You can load <tt>.png</tt> images, <tt>.tbin</tt> maps, or packed <tt>.xnb</tt> asset files. The normal convention is to have custom asset files in an <tt>assets</tt> subfolder, though that's not required. To read a file, you specify the type and path relative to your mod folder. For example:
+
You can read custom assets from your mod folder. The normal convention is to have them in an <tt>assets</tt> subfolder, though that's not required. To read a file, you specify the type and path relative to your mod folder. For example:
 
<source lang="c#">
 
<source lang="c#">
 
// read a PNG file
 
// read a PNG file
Line 36: Line 36:  
IDictionary<string, string> data = helper.Content.Load<Dictionary<string, string>>("assets/data.xnb", ContentSource.ModFolder);
 
IDictionary<string, string> data = helper.Content.Load<Dictionary<string, string>>("assets/data.xnb", ContentSource.ModFolder);
 
</source>
 
</source>
 +
 +
The supported file types are...
 +
 +
{| class="wikitable"
 +
|-
 +
! file extension
 +
! in-game type
 +
! notes
 +
|-
 +
| <tt>.xnb</tt>
 +
| ''any''
 +
| A packed file, like those in the game's <tt>Content</tt> folder. Not recommended since it's harder to edit and maintain.
 +
|-
 +
| <tt>.json</tt>
 +
| <tt>''any''</tt>
 +
| {{SMAPI upcoming|2.7|A data file, typically used to store <tt>Dictionary&lt;int, string&gt;</tt> or <tt>Dictionary&lt;string, string&gt;</tt> data.}}
 +
|-
 +
| <tt>.png</tt>
 +
| <tt>[https://docs.microsoft.com/en-us/previous-versions/windows/xna/bb199316%28v%3dxnagamestudio.41%29 Texture2D]</tt>
 +
| An image file. You can use this to load textures, spritesheets, tilesheets, etc.
 +
|-
 +
| <tt>.tbin</tt>
 +
| <tt>xTile.Map</tt>
 +
| A map file, which can be used to create or modify an in-game location. SMAPI will automatically match tilesheets to image files in the same folder as the map if they exist; otherwise the game will check the <tt>Content</tt> folders for them.
 +
|}
    
Some usage notes:
 
Some usage notes:
 
* Don't worry about which path separators you use; SMAPI will normalise them automatically.
 
* Don't worry about which path separators you use; SMAPI will normalise them automatically.
* When you load a <tt>.tbin</tt> map file, SMAPI will automatically fix any tilesheet references. For example, let's say your map references a file named <tt>tilesheet.png</tt>; SMAPI will automatically reference a <tt>tilesheet.png</tt> file in the same folder if it exists, otherwise it will use the game's default <tt>Content</tt> folders.
   
* To avoid performance issues, don't call <tt>content.Load<T></tt> repeatedly in draw code. Instead, load your asset once and reuse it.
 
* To avoid performance issues, don't call <tt>content.Load<T></tt> repeatedly in draw code. Instead, load your asset once and reuse it.
  
translators
8,445

edits

Navigation menu