Line 3: |
Line 3: |
| SMAPI simplifies mod development by providing APIs and events you can use, which are documented below. See [[Modding:Creating a SMAPI mod]] for a guide to creating a new SMAPI mod. | | SMAPI simplifies mod development by providing APIs and events you can use, which are documented below. See [[Modding:Creating a SMAPI mod]] for a guide to creating a new SMAPI mod. |
| | | |
− | ==Mod APIs==
| + | ==Events== |
− | ===Events===
| |
| SMAPI publishes several C# events that tell you when something happens. For example, if you want to do something after the player loads their save, you can add this to your <tt>Entry</tt> method: | | SMAPI publishes several C# events that tell you when something happens. For example, if you want to do something after the player loads their save, you can add this to your <tt>Entry</tt> method: |
| | | |
Line 24: |
Line 23: |
| </source> | | </source> |
| | | |
− | Here are the available events:
| + | The available events are documented below. |
− | <ul>
| + | |
− | <li id="content-events">
| + | ===Content events=== |
− | '''<tt>ContentEvents</tt>''' are raised when the game loads content from its XNB files or changes locale.
| + | <tt>ContentEvents</tt> are raised when the game loads content from its XNB files or changes locale. |
| {| class="wikitable" | | {| class="wikitable" |
| |- | | |- |
Line 38: |
Line 37: |
| | AfterLocaleChanged || Raised after the content language changes. | | | AfterLocaleChanged || Raised after the content language changes. |
| |} | | |} |
− | </li>
| |
| | | |
− | <li id="control-events">
| + | ===Control events=== |
− | '''<tt>ControlEvents</tt>''' are raised when the player uses a controller, keyboard, or mouse. They're raised before the game handles the input, so it's possible to selectively prevent the game from responding to it. (That's beyond the scope of this guide, but it involves overwriting <tt>Game1.oldKBState</tt>, <tt>Game1.oldMouseState</tt>, and <tt>Game1.oldPadState</tt>.)
| + | <tt>ControlEvents</tt> are raised when the player uses a controller, keyboard, or mouse. They're raised before the game handles the input, so it's possible to selectively prevent the game from responding to it. (That's beyond the scope of this guide, but it involves overwriting <tt>Game1.oldKBState</tt>, <tt>Game1.oldMouseState</tt>, and <tt>Game1.oldPadState</tt>.) |
| | | |
| Most of these events are split into two variants, <tt>XPressed</tt> and <tt>XReleased</tt>. The <tt>Pressed</tt> variant is raised when the player presses the button (holding the button down only triggers the event once), and the <tt>Released</tt> variant is raised when they release it. | | Most of these events are split into two variants, <tt>XPressed</tt> and <tt>XReleased</tt>. The <tt>Pressed</tt> variant is raised when the player presses the button (holding the button down only triggers the event once), and the <tt>Released</tt> variant is raised when they release it. |
Line 59: |
Line 57: |
| | MouseChanged || Raised after the game's <tt>MouseState</tt> changed. That happens when the player moves the mouse, scrolls the mouse wheel, or presses/releases a button. | | | MouseChanged || Raised after the game's <tt>MouseState</tt> changed. That happens when the player moves the mouse, scrolls the mouse wheel, or presses/releases a button. |
| |} | | |} |
− | </li>
| |
| | | |
− | <li id="game-events">
| + | ===Game events=== |
− | '''<tt>GameEvents</tt>''' are raised when the game changes state.
| + | <tt>GameEvents</tt> are raised when the game changes state. |
| | | |
| {| class="wikitable" | | {| class="wikitable" |
Line 84: |
Line 81: |
| | OneSecondTick || Raised every 60th tick (≈once per second). | | | OneSecondTick || Raised every 60th tick (≈once per second). |
| |} | | |} |
− | </li>
| |
| | | |
− | <li id="graphics-events">
| + | ===Graphics events=== |
− | '''<tt>GraphicsEvents</tt>''' are raised during the game's draw loop, when the game is rendering content to the window.
| + | <tt>GraphicsEvents</tt> are raised during the game's draw loop, when the game is rendering content to the window. |
| | | |
| {| class="wikitable" | | {| class="wikitable" |
Line 101: |
Line 97: |
| | Resize || Raised after the game window is resized. | | | Resize || Raised after the game window is resized. |
| |} | | |} |
− | </li>
| |
| | | |
− | <li id="location-events">
| + | ===Location events=== |
− | '''<tt>LocationEvents</tt>''' are raised when the player transitions between game locations, a location is added or removed, or the objects in the current location change.
| + | <tt>LocationEvents</tt> are raised when the player transitions between game locations, a location is added or removed, or the objects in the current location change. |
| | | |
| {| class="wikitable" | | {| class="wikitable" |
Line 116: |
Line 111: |
| | LocationsChanged || Raised after a game location is added or removed. Handlers are passed the new list of locations as an argument. | | | LocationsChanged || Raised after a game location is added or removed. Handlers are passed the new list of locations as an argument. |
| |} | | |} |
− | </li>
| |
| | | |
− | <li id="control-events">
| + | ===Menu events=== |
− | '''<tt>MenuEvents</tt>''' are raised when a game menu is opened or closed (including internal menus like the title screen).
| + | <tt>MenuEvents</tt> are raised when a game menu is opened or closed (including internal menus like the title screen). |
| | | |
| {| class="wikitable" | | {| class="wikitable" |
Line 129: |
Line 123: |
| | MenuClosed || Raised after a game menu is closed. Handlers are given the previous menu. | | | MenuClosed || Raised after a game menu is closed. Handlers are given the previous menu. |
| |} | | |} |
− | </li>
| |
| | | |
− | <li id="mine-events">
| + | ===Mine events=== |
− | '''<tt>MineEvents</tt>''' are raised when something happens in [[The Mines]].
| + | <tt>MineEvents</tt> are raised when something happens in [[The Mines]]. |
| | | |
| {| class="wikitable" | | {| class="wikitable" |
Line 140: |
Line 133: |
| | MineLevelChanged || Raised after the player warps to a new level of the mine. Handlers are passed the previous and new mine level as arguments. | | | MineLevelChanged || Raised after the player warps to a new level of the mine. Handlers are passed the previous and new mine level as arguments. |
| |} | | |} |
− | </li>
| |
| | | |
− | <li id="player-events">
| + | ===Player events=== |
− | '''<tt>PlayerEvents</tt>''' are raised when the player data changes.
| + | <tt>PlayerEvents</tt> are raised when the player data changes. |
| | | |
| {| class="wikitable" | | {| class="wikitable" |
Line 153: |
Line 145: |
| | LeveledUp || Raised after the player levels up a skill. This happens as soon as they level up, not when the game notifies the player after their character goes to bed. | | | LeveledUp || Raised after the player levels up a skill. This happens as soon as they level up, not when the game notifies the player after their character goes to bed. |
| |} | | |} |
− | </li>
| |
| | | |
− | <li id="save-events">
| + | ===Save events=== |
− | '''<tt>SaveEvents</tt>''' are raised when the player saves or loads the game.
| + | <tt>SaveEvents</tt> are raised when the player saves or loads the game. |
| | | |
| {| class="wikitable" | | {| class="wikitable" |
Line 170: |
Line 161: |
| | AfterReturnToTitle || Raised after the player exits to the title screen. | | | AfterReturnToTitle || Raised after the player exits to the title screen. |
| |} | | |} |
− | </li>
| |
| | | |
− | <li id="time-events">
| + | ===Time events=== |
− | '''<tt>TimeEvents</tt>''' are raised when the in-game date or time changes.
| + | <tt>TimeEvents</tt> are raised when the in-game date or time changes. |
| | | |
| {| class="wikitable" | | {| class="wikitable" |
Line 189: |
Line 179: |
| | YearOfGameChanged || Raised after the year changes. | | | YearOfGameChanged || Raised after the year changes. |
| |} | | |} |
− | </li>
| |
− | </ul>
| |
| | | |
| + | ==Mod APIs== |
| ===Configuration=== | | ===Configuration=== |
| You can let users configure your mod through a <tt>config.json</tt> file. SMAPI will automatically create the file and take care of reading, normalising, and updating it. | | You can let users configure your mod through a <tt>config.json</tt> file. SMAPI will automatically create the file and take care of reading, normalising, and updating it. |