Changes

remove {{SMAPI upcoming|4.0.0}}
Line 17: Line 17:  
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
 
/// <summary>The main entry point for the mod.</summary>
 
/// <summary>The main entry point for the mod.</summary>
public class ModEntry : Mod
+
internal sealed class ModEntry : Mod
 
{
 
{
 
     /**********
 
     /**********
Line 33: Line 33:  
     /// <param name="sender">The event sender.</param>
 
     /// <param name="sender">The event sender.</param>
 
     /// <param name="e">The event arguments.</param>
 
     /// <param name="e">The event arguments.</param>
     private void OnDayStarted(object sender, DayStartedEventArgs e)
+
     private void OnDayStarted(object? sender, DayStartedEventArgs e)
 
     {
 
     {
       this.Monitor.Log("A new day dawns!");
+
       this.Monitor.Log("A new day dawns!", LogLevel.Info);
 
     }
 
     }
 
}
 
}
Line 41: Line 41:     
Tip: you don't need to memorise the method arguments. In Visual Studio, type <code>helper.Events.GameLoop.SaveLoaded +=</code> and press {{key|TAB}} to auto-create a method. (There doesn't seem to be an equivalent feature in MonoDevelop.)
 
Tip: you don't need to memorise the method arguments. In Visual Studio, type <code>helper.Events.GameLoop.SaveLoaded +=</code> and press {{key|TAB}} to auto-create a method. (There doesn't seem to be an equivalent feature in MonoDevelop.)
 +
 +
<samp>sender</samp> is part of the C# event pattern, and is unused by SMAPI.
    
===How do events fit into the game?===
 
===How do events fit into the game?===
Line 64: Line 66:     
===Content===
 
===Content===
{{SMAPI upcoming|4.0.0|content=
  −
   
<samp>this.Helper.Events.Content</samp> has events related to assets loaded from the content pipeline.
 
<samp>this.Helper.Events.Content</samp> has events related to assets loaded from the content pipeline.
   −
{{{!}} class="wikitable"
+
{| class="wikitable"
{{!}}-
+
|-
 
! event
 
! event
 
! summary
 
! summary
Line 83: Line 83:  
  |arg name 1 = <samp>e.Name</samp>
 
  |arg name 1 = <samp>e.Name</samp>
 
  |arg type 1 = <samp>IAssetName</samp>
 
  |arg type 1 = <samp>IAssetName</samp>
  |arg desc 1 = The name of the asset being requested. This includes utility methods to parse the value, like <code>e.Name.IsEquivalentTo("Portraits/Abigail")</code> (which handles any differences in formatting for you).
+
  |arg desc 1 = The name of the asset being requested, including the locale code if any (like the <samp>.fr-FR</samp> in <samp>Data/Bundles.fr-FR</samp>). This includes utility methods to parse the value, like <code>e.Name.IsEquivalentTo("Portraits/Abigail")</code> (which handles any differences in formatting for you).
   −
  |arg name 2 = <samp>e.LoadFrom(...)</samp>
+
  |arg name 2 = <samp>e.NameWithoutLocale</samp>
  |arg type 2 = ''method''
+
|arg type 2 = <samp>IAssetName</samp>
  |arg desc 2 = Call this method to provide the initial instance for the asset, instead of trying to load it from the game's <samp>Content</samp> folder. For example:
+
|arg desc 2 = Equivalent to <samp>e.Name</samp> but without the locale code (if any). For example, if <samp>e.Name</samp> is <samp>Data/Bundles.fr-FR</samp>, this field will contain <samp>Data/Bundles</samp>.
 +
 
 +
|arg name 3 = <samp>e.LoadFrom(...)</samp>
 +
  |arg type 3 = ''method''
 +
  |arg desc 3 = Call this method to provide the initial instance for the asset, instead of trying to load it from the game's <samp>Content</samp> folder. For example:
 
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
e.LoadFrom(() => this.Helper.Content.Load<Texture2D>("assets/portraits.png"));
+
e.LoadFrom(() => this.Helper.Content.Load<Texture2D>("assets/portraits.png"), AssetLoadPriority.Medium);
 
</syntaxhighlight>
 
</syntaxhighlight>
   Line 96: Line 100:  
* Each asset can logically only have one initial instance. If multiple loads apply at the same time, SMAPI will raise an error and ignore all of them. If you're making changes to the existing asset instead of replacing it, you should use the <samp>Edit</samp> method instead to avoid those limitations and improve mod compatibility.
 
* Each asset can logically only have one initial instance. If multiple loads apply at the same time, SMAPI will raise an error and ignore all of them. If you're making changes to the existing asset instead of replacing it, you should use the <samp>Edit</samp> method instead to avoid those limitations and improve mod compatibility.
   −
  |arg name 3 = <samp>e.LoadFromModFile<T>(...)</samp>
+
  |arg name 4 = <samp>e.LoadFromModFile<T>(...)</samp>
  |arg type 3 = ''method''
+
  |arg type 4 = ''method''
  |arg desc 3 = Call this method to provide the initial instance for the asset by loading a file from your mod folder. For example:
+
  |arg desc 4 = Call this method to provide the initial instance for the asset by loading a file from your mod folder. For example:
 
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
e.LoadFromModFile<Texture2D>("assets/portraits.png");
+
e.LoadFromModFile<Texture2D>("assets/portraits.png", AssetLoadPriority.Medium);
 
</syntaxhighlight>
 
</syntaxhighlight>
    
See usage notes on <samp>e.LoadFrom</samp>.
 
See usage notes on <samp>e.LoadFrom</samp>.
   −
  |arg name 4 = <samp>e.Edit(...)</samp>
+
  |arg name 5 = <samp>e.Edit(...)</samp>
  |arg type 4 = ''method''
+
  |arg type 5 = ''method''
  |arg desc 4 = Call this method to apply edits to the asset after it's loaded. For example:
+
  |arg desc 5 = Call this method to apply edits to the asset after it's loaded. For example:
 
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
 
e.Edit(asset =>
 
e.Edit(asset =>
Line 129: Line 133:  
  |arg name 1 = <samp>e.Names</samp>
 
  |arg name 1 = <samp>e.Names</samp>
 
  |arg type 1 = <samp>IReadOnlySet<IAssetName></samp>
 
  |arg type 1 = <samp>IReadOnlySet<IAssetName></samp>
  |arg desc 1 = The asset names that were invalidated. These include utility methods to parse the values, like <code>name.IsEquivalentTo("Portraits/Abigail")</code> (which handles any differences in formatting for you).
+
  |arg desc 1 = The asset names that were invalidated, including the locale code if any (like the <samp>.fr-FR</samp> in <samp>Data/Bundles.fr-FR</samp>). These include utility methods to parse the values, like <code>name.IsEquivalentTo("Portraits/Abigail")</code> (which handles any differences in formatting for you).
 +
 
 +
|arg name 2 = <samp>e.NamesWithoutLocale</samp>
 +
|arg type 2 = <samp>IReadOnlySet<IAssetName></samp>
 +
|arg desc 2 = Equivalent to <samp>e.Names</samp> but without the locale code (if any). For example, if <samp>e.Names</samp> contains <samp>Data/Bundles.fr-FR</samp>, this field will contain <samp>Data/Bundles</samp>.
 
}}
 
}}
 
{{/event
 
{{/event
Line 140: Line 148:  
  |arg name 1 = <samp>e.Name</samp>
 
  |arg name 1 = <samp>e.Name</samp>
 
  |arg type 1 = <samp>IAssetName</samp>
 
  |arg type 1 = <samp>IAssetName</samp>
  |arg desc 1 = The name of the asset that was loaded. This includes utility methods to parse the value, like <code>e.Name.IsEquivalentTo("Portraits/Abigail")</code> (which handles any differences in formatting for you).
+
  |arg desc 1 = The name of the asset that was loaded, including the locale code if any (like the <samp>.fr-FR</samp> in <samp>Data/Bundles.fr-FR</samp>). This includes utility methods to parse the value, like <code>e.Name.IsEquivalentTo("Portraits/Abigail")</code> (which handles any differences in formatting for you).
 +
 
 +
|arg name 2 = <samp>e.NameWithoutLocale</samp>
 +
|arg type 2 = <samp>IAssetName</samp>
 +
|arg desc 2 = Equivalent to <samp>e.Name</samp> but without the locale code (if any). For example, if <samp>e.Name</samp> is <samp>Data/Bundles.fr-FR</samp>, this field will contain <samp>Data/Bundles</samp>.
 
}}
 
}}
{{!}}}
+
{{/event
 +
|group = Content
 +
|name  = LocaleChanged
 +
|desc  = Raised after the game language changes. For non-English players, this may be raised during startup when the game switches to the previously selected language.
 +
 
 +
|arg name 1 = <samp>e.OldLanguage</samp>
 +
|arg type 1 = <samp>LanguageCode</samp>
 +
|arg desc 1 = The previous value for the game's language enum. For a custom language, this is always <samp>LanguageCode.mod</samp>.
 +
 
 +
|arg name 2 = <samp>e.OldLocale</samp>
 +
|arg type 2 = <samp>string</samp>
 +
|arg desc 2 = The previous value for the locale code. This is the locale code as it appears in asset names, like <samp>fr-FR</samp> in <samp>Maps/springobjects.fr-FR</samp>. The locale code for English is an empty string.
 +
 
 +
|arg name 3 = <samp>e.NewLanguage</samp>
 +
|arg type 3 = <samp>LanguageCode</samp>
 +
|arg desc 3 = The new value for the game's language enum. See notes on <samp>OldLanguage</samp>.
 +
 
 +
|arg name 4 = <samp>e.NewLocale</samp>
 +
|arg type 4 = <samp>string</samp>
 +
|arg desc 4 = The previous value for the locale code. See notes on <samp>OldLocale</samp>.
 
}}
 
}}
 +
|}
    
===Display===
 
===Display===
Line 177: Line 209:  
  |group = Display
 
  |group = Display
 
  |name  = Rendered
 
  |name  = Rendered
  |desc  = Raised after the game draws to the sprite patch in a draw tick, just before the final sprite batch is rendered to the screen. Since the game may open/close the sprite batch multiple times in a draw tick, the sprite batch may not contain everything being drawn and some things may already be rendered to the screen. Content drawn to the sprite batch at this point will be drawn over all vanilla content (including menus, HUD, and cursor).
+
  |desc  = Raised after the game draws to the sprite batch in a draw tick, just before the final sprite batch is rendered to the screen. Since the game may open/close the sprite batch multiple times in a draw tick, the sprite batch may not contain everything being drawn and some things may already be rendered to the screen. Content drawn to the sprite batch at this point will be drawn over all vanilla content (including menus, HUD, and cursor).
    
  |arg name 1 = <samp>e.SpriteBatch</samp>
 
  |arg name 1 = <samp>e.SpriteBatch</samp>
Line 195: Line 227:  
  |group = Display
 
  |group = Display
 
  |name  = RenderedWorld
 
  |name  = RenderedWorld
  |desc  = Raised after the game world is drawn to the sprite patch, before it's rendered to the screen. Content drawn to the sprite batch at this point will be drawn over the world, but under any active menu, HUD elements, or cursor.
+
  |desc  = Raised after the game world is drawn to the sprite batch, before it's rendered to the screen. Content drawn to the sprite batch at this point will be drawn over the world, but under any active menu, HUD elements, or cursor.
    
  |arg name 1 = <samp>e.SpriteBatch</samp>
 
  |arg name 1 = <samp>e.SpriteBatch</samp>
Line 249: Line 281:  
  |arg type 2 = <samp>Point</samp>
 
  |arg type 2 = <samp>Point</samp>
 
  |arg desc 2 = The new window width (<samp>e.NewSize.X</samp>) and height (<samp>e.NewSize.Y</samp>).
 
  |arg desc 2 = The new window width (<samp>e.NewSize.X</samp>) and height (<samp>e.NewSize.Y</samp>).
 +
}}
 +
{{/event
 +
|group = Display
 +
|name  = RenderingStep
 +
|desc  = ''(Specialized)'' Raised before the game draws a specific step in the rendering cycle. This gives more granular control over render logic, but is more vulnerable to changes in game updates. Consider using one of the other render events if possible.
 +
 +
|arg name 1 = <samp>e.SpriteBatch</samp>
 +
|arg type 1 = <samp>SpriteBatch</samp>
 +
|arg desc 1 = The sprite batch being drawn. Add anything you want to appear on-screen to this sprite batch.
 +
 +
|arg name 2 = <samp>e.Step</samp>
 +
|arg type 2 = <samp>RenderSteps</samp>
 +
|arg desc 2 = The step being rendered in the draw cycle.
 +
}}
 +
{{/event
 +
|group = Display
 +
|name  = RenderedStep
 +
|desc  = ''(Specialized)'' Raised after the game draws a specific step in the rendering cycle.  This gives more granular control over render logic, but is more vulnerable to changes in game updates. Consider using one of the other render events if possible.
 +
 +
|arg name 1 = <samp>e.SpriteBatch</samp>
 +
|arg type 1 = <samp>SpriteBatch</samp>
 +
|arg desc 1 = The sprite batch being drawn. Add anything you want to appear on-screen to this sprite batch.
 +
 +
|arg name 2 = <samp>e.Step</samp>
 +
|arg type 2 = <samp>RenderSteps</samp>
 +
|arg desc 2 = The step being rendered in the draw cycle.
 
}}
 
}}
 
|}
 
|}
Line 838: Line 896:  
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
 
/// <summary>The main entry point for the mod.</summary>
 
/// <summary>The main entry point for the mod.</summary>
public class ModEntry : Mod
+
internal sealed class ModEntry : Mod
 
{
 
{
 
     /*********
 
     /*********
Line 881: Line 939:  
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
 
/// <summary>The main entry point for the mod.</summary>
 
/// <summary>The main entry point for the mod.</summary>
public class ModEntry : Mod
+
internal sealed class ModEntry : Mod
 
{
 
{
 
     /*********
 
     /*********
translators
8,404

edits