Changes

Jump to navigation Jump to search
→‎Providing an API: + GetApi(IModInfo mod) in SMAPI 3.17.0
Line 41: Line 41:  
</syntaxhighlight>
 
</syntaxhighlight>
 
(You can use a [https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/constructors constructor] to initialise the API if desired.)</li>
 
(You can use a [https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/constructors constructor] to initialise the API if desired.)</li>
<li>Override <samp>GetApi</samp> in your mod's entry class and return an instance of your API:
+
<li>Override <samp>GetApi</samp> in your mod's entry class and return an instance of your API. You can choose between two versions of this method:
 +
<ul>
 +
<li>Override <samp>GetApi()</samp> to provide one instance of the API to all mods. This will only be called once, and SMAPI will cache the mod instance.
 
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
 
   public override object GetApi()
 
   public override object GetApi()
Line 47: Line 49:  
       return new YourModApi();
 
       return new YourModApi();
 
   }
 
   }
</syntaxhighlight></li>
+
</syntaxhighlight>
 +
</li>
 +
<li>{{SMAPI upcoming|3.17.0|content=''Or'' Override <samp>GetApi(IModInfo mod)</samp> to provide one instance per mod. This will be called once for each mod that requests an API.
 +
 
 +
Note that this info is provided for informational purposes only (e.g. to log errors). Denying API access to specific mods is strongly discouraged and may be considered abusive.
 +
<syntaxhighlight lang="c#">
 +
  public override object GetApi(IModInfo mod)
 +
  {
 +
      return new YourModApi(mod.Manifest);
 +
  }
 +
</syntaxhighlight>}}
 +
</li>
 +
</ul>
 +
</li>
 
</ol>
 
</ol>
  
translators
8,403

edits

Navigation menu