Changes

→‎Data structures: update for SMAPI 3.9 and new best practices
Line 127: Line 127:  
</syntaxhighlight>
 
</syntaxhighlight>
   −
You can use <tt>SButton</tt> values directly in your [[../Config|config model]], and they'll be represented by their names:
+
You can use <tt>SButton</tt> values directly in your [[../Config|config model]], but <tt>[[#KeybindList|KeybindList]]</tt> is recommended instead in most cases.
 +
 
 +
===KeybindList===
 +
SMAPI's <tt>KeybindList</tt> utility lets you manage an arbitrary set of keybindings. A ''keybind list'' has any number of ''keybinds'', each of which has any number of [[#SButton|button codes]]. For example, the keybind list <code>"F2, LeftShift + S"</code> would be pressed if (a) <tt>F2</tt> is pressed, ''or'' (b) both <tt>LeftShift</tt> and <tt>S</tt> are pressed.
 +
 
 +
You can use a <tt>KeybindList</tt> directly in [[../Config|your <tt>config.json</tt> model]]:
 +
 
 
{| class="wikitable"
 
{| class="wikitable"
 +
|-
 +
! C# model
 +
! &nbsp;
 +
! JSON file
 +
|-
 
| <syntaxhighlight lang="c#">
 
| <syntaxhighlight lang="c#">
internal class ModConfig
+
class ModConfig
 
{
 
{
   public SButton DoThingButton { get; set; } = SButton.LeftControl;
+
   public KeybindList ToggleKey { get; set; } = KeybindList.Parse("Shift + F2");
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 138: Line 149:  
| <syntaxhighlight lang="json">
 
| <syntaxhighlight lang="json">
 
{
 
{
   "DoThingButton": "LeftControl"
+
   "ToggleKey": "Shift + F2"
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
|}
 
|}
  −
===KeybindList===
  −
SMAPI's <tt>KeybindList</tt> utility lets you manage an arbitrary set of keybindings. A ''keybind list'' has any number of ''keybinds'', each of which has any number of [[#SButton|button codes]]. For example, the keybind list <code>"F2, LeftShift + S"</code> would be pressed if (a) <tt>F2</tt> is pressed, ''or'' (b) both <tt>LeftShift</tt> and <tt>S</tt> are pressed.
  −
  −
You can use a <tt>KeybindList</tt> directly in [[../Config|your <tt>config.json</tt> model]]:
  −
  −
<syntaxhighlight lang="c#">
  −
class ModConfig
  −
{
  −
  public KeybindList ToggleKey { get; set; } = KeybindList.Parse("Shift + F2");
  −
}
  −
</syntaxhighlight>
      
And you can then check whether it's pressed directly in your code. For example, in a [[../Events|<tt>ButtonsChanged</tt> event handler]]:
 
And you can then check whether it's pressed directly in your code. For example, in a [[../Events|<tt>ButtonsChanged</tt> event handler]]:
translators
8,404

edits