Changes

Jump to navigation Jump to search
Line 7: Line 7:  
The ''config model'' is a C# class you create, with properties representing the settings you want to store. It can contain almost anything from a few boolean fields to a complex object graph (though you should try to keep things simple for players). Here's a simple config model:
 
The ''config model'' is a C# class you create, with properties representing the settings you want to store. It can contain almost anything from a few boolean fields to a complex object graph (though you should try to keep things simple for players). Here's a simple config model:
 
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
class ModConfig
+
public sealed class ModConfig
 
{
 
{
 
   public bool ExampleBoolean { get; set; }
 
   public bool ExampleBoolean { get; set; }
Line 21: Line 21:  
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
These properties must be public.
    
===Default values===
 
===Default values===
 
You can set default values in your data model:
 
You can set default values in your data model:
 
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
class ModConfig
+
public sealed class ModConfig
 
{
 
{
 
   public bool ExampleBoolean { get; set; } = true;
 
   public bool ExampleBoolean { get; set; } = true;
Line 35: Line 37:     
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
class ModConfig
+
public sealed class ModConfig
 
{
 
{
 
   public bool ExampleBoolean { get; set; }
 
   public bool ExampleBoolean { get; set; }
Line 56: Line 58:  
<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 81: Line 83:     
That's it! When the player launches the game, SMAPI will create the <samp>config.json</samp> file automatically if it doesn't exist yet, using the default config options you provided in your model. If you need to save some changes, you can use <samp>this.Helper.WriteConfig(this.Config)</samp>.
 
That's it! When the player launches the game, SMAPI will create the <samp>config.json</samp> file automatically if it doesn't exist yet, using the default config options you provided in your model. If you need to save some changes, you can use <samp>this.Helper.WriteConfig(this.Config)</samp>.
 +
 +
Note that <samp>ReadConfig</samp> will raise an exception if the user does not provide a valid JSON.
    
==Keybind settings==
 
==Keybind settings==
 
: {{main article|Modding:Modder Guide/APIs/Input}}
 
: {{main article|Modding:Modder Guide/APIs/Input}}
   −
You can use SMAPI's [[Modding:Modder Guide/APIs/Input#KeybindList|<samp>KeybindList</samp>]] in your model to let users configure keybinds. This automatically supports multi-key or alternative bindings (e.g. to support split-screen mode):
+
You can use SMAPI's [[Modding:Modder Guide/APIs/Input#KeybindList|<samp>KeybindList</samp>]] in your model to let users configure keybinds. This automatically supports multi-key or alternative bindings (''e.g.,'' to support split-screen mode):
    
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
528

edits

Navigation menu