Changes

Jump to navigation Jump to search
update for SMAPI 2.0 release
Line 23: Line 23:  
|-
 
|-
 
| <tt>Version</tt>
 
| <tt>Version</tt>
| The mod's [http://semver.org/ semantic version]. Make sure you update this for each release! (The <tt>Build</tt> field is a semantic version label, like <tt>beta.2</tt> in <tt>1.0-beta.2</tt>.) SMAPI uses this for update checks, mod dependencies, and compatibility blacklists (if the mod breaks in a future version of the game). Example:
+
| The mod's [http://semver.org/ semantic version]. Make sure you update this for each release! SMAPI uses this for update checks, mod dependencies, and compatibility blacklists (if the mod breaks in a future version of the game). Example:
<source lang="javascript">
  −
"Version": {
  −
  "MajorVersion": 1,
  −
  "MinorVersion": 0,
  −
  "PatchVersion": 0,
  −
  "Build": "beta.2"
  −
}
  −
</source>
  −
 
  −
{{SMAPI upcoming
  −
|version = 2.0
  −
|content = Starting with SMAPI 2.0, you can specify a version string instead:
   
<source lang="javascript">
 
<source lang="javascript">
 
"Version": "1.0-beta.2"
 
"Version": "1.0-beta.2"
 
</source>
 
</source>
}}
   
|-
 
|-
 
| <tt>Description</tt>
 
| <tt>Description</tt>
Line 65: Line 52:  
</source>
 
</source>
   −
{{SMAPI upcoming
  −
|version = 2.0
  −
|content =
   
You can mark a dependency as optional. It will be loaded first if it's installed, otherwise it'll be ignored.
 
You can mark a dependency as optional. It will be loaded first if it's installed, otherwise it'll be ignored.
 
<source lang="javascript">
 
<source lang="javascript">
Line 77: Line 61:  
]
 
]
 
</source>
 
</source>
}}
      
===Update checks===
 
===Update checks===
{{SMAPI upcoming
+
SMAPI can detect new versions of your mod and alert the user with a link to your mod page. You can enable this by setting the <tt>UpdateKeys</tt> field with one of the following values, which tells SMAPI where to check.
|version = 2.0
  −
|content = SMAPI can detect new versions of your mod and alert the user with a link to your mod page. You can enable this by setting the <tt>UpdateKeys</tt> field with one of the following values, which tells SMAPI where to check.
      
; Chucklefish mod site
 
; Chucklefish mod site
Line 95: Line 76:  
You can specify multiple values, in which case SMAPI will check them all and list the latest version it finds:
 
You can specify multiple values, in which case SMAPI will check them all and list the latest version it finds:
 
<source lang="javascript">"UpdateKeys": [ "Chucklefish:4250", "Nexus:541", "GitHub:Pathoschild/LookupAnything" ]</source>
 
<source lang="javascript">"UpdateKeys": [ "Chucklefish:4250", "Nexus:541", "GitHub:Pathoschild/LookupAnything" ]</source>
}}
      
===Anything else===
 
===Anything else===
Line 127: Line 107:  
|-
 
|-
 
! event !! summary
 
! event !! summary
<!--
  −
|-
  −
| AssetLoading || '''[SMAPI 2.0+ only]''' Raised when an XNB file is being read into the cache. Mods can change the data here before it's cached.
  −
-->
   
|-
 
|-
 
| AfterLocaleChanged || Raised after the content language changes.
 
| AfterLocaleChanged || Raised after the content language changes.
Line 194: Line 170:     
===Input events===
 
===Input events===
{{SMAPI upcoming
  −
|version = 2.0
  −
|content =
   
<tt>InputEvents</tt> are raised when the player uses a controller, keyboard, or mouse.
 
<tt>InputEvents</tt> are raised when the player uses a controller, keyboard, or mouse.
 
<table class="wikitable">
 
<table class="wikitable">
Line 217: Line 190:  
</tr>
 
</tr>
 
</table>
 
</table>
}}
      
===Location events===
 
===Location events===
Line 449: Line 421:     
====Edit assets====
 
====Edit assets====
{{SMAPI upcoming
+
You can intercept and change any texture or data loaded by the game. (In other words, you can edit XNB data while the game is running without changing the original files.)
|version = 2.0
  −
|content = You can intercept and change any texture or data loaded by the game. (In other words, you can edit XNB data while the game is running without changing the original files.)
      
In most cases, you can just implement <tt>IAssetEditor</tt> in your <tt>Mod</tt> class to do it. This adds two methods: <tt>CanEdit&lt;T&gt;</tt> returns whether the mod can edit a particular asset, and <tt>Edit&lt;T&gt;</tt> makes any changes needed. For example, this mod lets crops grow in any season (example only, doesn't handle edge cases):
 
In most cases, you can just implement <tt>IAssetEditor</tt> in your <tt>Mod</tt> class to do it. This adds two methods: <tt>CanEdit&lt;T&gt;</tt> returns whether the mod can edit a particular asset, and <tt>Edit&lt;T&gt;</tt> makes any changes needed. For example, this mod lets crops grow in any season (example only, doesn't handle edge cases):
Line 505: Line 475:  
}
 
}
 
</source>
 
</source>
}}
      
====Inject assets====
 
====Inject assets====
{{SMAPI upcoming
+
You can inject new assets for the game to use (e.g. to add dialogue for a custom NPC). '''To edit existing assets, you should use [[#Edit assets|asset editors]] instead.''' If multiple loaders match the same asset, SMAPI will show an error and use none of them.
|version = 2.0
  −
|content = You can inject new assets for the game to use (e.g. to add dialogue for a custom NPC). '''To edit existing assets, you should use [[#Edit assets|asset editors]] instead.''' If multiple loaders match the same asset, SMAPI will show an error and use none of them.
      
In most cases, you can just implement <tt>IAssetLoader</tt> in your <tt>Mod</tt> class to do it. This adds two methods: <tt>CanLoad&lt;T&gt;</tt> returns whether the mod can load a particular asset, and <tt>Load&lt;T&gt;</tt> provides the asset data. For example, this code adds a new dialogue file for a custom NPC.
 
In most cases, you can just implement <tt>IAssetLoader</tt> in your <tt>Mod</tt> class to do it. This adds two methods: <tt>CanLoad&lt;T&gt;</tt> returns whether the mod can load a particular asset, and <tt>Load&lt;T&gt;</tt> provides the asset data. For example, this code adds a new dialogue file for a custom NPC.
Line 547: Line 514:  
}
 
}
 
</source>
 
</source>
}}
      
====Reload assets====
 
====Reload assets====
{{SMAPI upcoming
+
'''Caution:''' reloading assets is fairly expensive, so use this API judiciously to avoid impacting game performance.
|version = 2.0
  −
|content = '''Caution:''' reloading assets is fairly expensive, so use this API judiciously to avoid impacting game performance.
      
You can reload an asset by invalidating it from the cache. It will be reloaded next time the game requests it (and mods will have another chance to intercept it), and SMAPI will reload it automatically if it's a core asset that's kept in memory by the game. For example, this lets you change what clothes an NPC is wearing (by invalidating their cached sprites or portraits).
 
You can reload an asset by invalidating it from the cache. It will be reloaded next time the game requests it (and mods will have another chance to intercept it), and SMAPI will reload it automatically if it's a core asset that's kept in memory by the game. For example, this lets you change what clothes an NPC is wearing (by invalidating their cached sprites or portraits).
Line 565: Line 529:  
helper.Content.InvalidateCache<Texture2D>();
 
helper.Content.InvalidateCache<Texture2D>();
 
</source>
 
</source>
}}
      
===Logging===
 
===Logging===
Line 735: Line 698:  
|-
 
|-
 
| <tt>Context.CanPlayerMove</tt>
 
| <tt>Context.CanPlayerMove</tt>
| (SMAPI 2.0+ only) <tt>Context.IsPlayerFree</tt> and the player is free to move (e.g. not using a tool).
+
| <tt>Context.IsPlayerFree</tt> and the player is free to move (e.g. not using a tool).
 
|}
 
|}
   Line 763: Line 726:  
</source>
 
</source>
   −
{{SMAPI upcoming
+
...and check the day of week:
|version = 2.0
  −
|content = ...and check the day of week:
   
<source lang="c#">
 
<source lang="c#">
 
if (SDate.Now().DayOfWeek == DayOfWeek.Friday)
 
if (SDate.Now().DayOfWeek == DayOfWeek.Friday)
 
   ...
 
   ...
</source>}}
+
</source>
    
Note that <tt>SDate</tt> won't let you create invalid dates:
 
Note that <tt>SDate</tt> won't let you create invalid dates:
translators
8,403

edits

Navigation menu