Line 3: |
Line 3: |
| SMAPI provides some C# objects you can use to simplify your code. | | SMAPI provides some C# objects you can use to simplify your code. |
| | | |
− | ==Constants== | + | ==Metadata== |
| + | ===Constants=== |
| The <tt>Constants</tt> class provides metadata about SMAPI and the game. | | The <tt>Constants</tt> class provides metadata about SMAPI and the game. |
| | | |
Line 39: |
Line 40: |
| |} | | |} |
| | | |
− | ==Context== | + | ===Context=== |
| The <tt>Context</tt> class provides information about the game state and player control: | | The <tt>Context</tt> class provides information about the game state and player control: |
| | | |
Line 66: |
Line 67: |
| |} | | |} |
| | | |
− | ==Dates== | + | ==Helpers== |
| + | ===Dates=== |
| Use <tt>SDate</tt> for calculating in-game dates. You start by creating a date: | | Use <tt>SDate</tt> for calculating in-game dates. You start by creating a date: |
| <source lang="c#"> | | <source lang="c#"> |
Line 132: |
Line 134: |
| |} | | |} |
| | | |
− | ==Input== | + | ===File paths=== |
− | SMAPI's <tt>SButton</tt> constants uniquely represent controller, keyboard, and mouse button presses or clicks. See the [[../Input|Input]] page for more info. | + | {{SMAPI upcoming|3.7}} |
| + | |
| + | <tt>PathUtilities</tt> provides utility methods for working with file paths, complementing the <tt>Path</tt> class provided by .NET: |
| + | |
| + | {| class="wikitable" |
| + | |- |
| + | ! method |
| + | ! usage |
| + | |- |
| + | | <code>GetSegments</code> |
| + | | Split a path into its delimited segments, like <code>/usr/bin/example</code> → <code>usr</code>, <code>bin</code>, and <code>example</code>. For example: |
| + | |
| + | <source lang="c#"> |
| + | string[] segments = PathUtilities.GetSegments(Constants.ExecutionPath); |
| + | </source> |
| + | |- |
| + | | <code>IsSafeRelativePath</code> |
| + | | Get whether a path is relative and doesn't contain directory climbing (<code>../</code>), so it's guaranteed to be within the parent folder. |
| + | |- |
| + | | <code>IsSlug</code> |
| + | | Get whether a string can be used as a 'slug', containing only basic characters that are safe in all contexts (e.g. filenames, URLs, SMAPI IDs, etc). |
| + | |- |
| + | | <code>NormalizePathSeparators</code> |
| + | | Normalize directory separators to match the format used by the current OS. For example: |
| + | |
| + | <source lang="c#">string path = PathUtilities.NormalizePathSeparators("Characters/Dialogue/Abigail"); |
| + | // Linux/Mac: "Characters/Dialogue/Abigail" |
| + | // Windows: "Characters\Dialogue\Abigail" |
| + | </source> |
| + | |} |
| + | |
| + | This is also useful for working with |
| | | |
− | ==Semantic versions== | + | ===Semantic versions=== |
| Use <tt>SemanticVersion</tt> to manipulate and compare versions per the [http://semver.org/ Semantic Versioning 2.0 standard]. Example usage: | | Use <tt>SemanticVersion</tt> to manipulate and compare versions per the [http://semver.org/ Semantic Versioning 2.0 standard]. Example usage: |
| <source lang="c#"> | | <source lang="c#"> |
Line 151: |
Line 184: |
| | | |
| Note that game versions before 1.2.0 and some mod versions are non-standard (e.g. Stardew Valley 1.11 comes ''before'' 1.2). All SMAPI versions are standard. | | Note that game versions before 1.2.0 and some mod versions are non-standard (e.g. Stardew Valley 1.11 comes ''before'' 1.2). All SMAPI versions are standard. |
| + | |
| + | ==Input== |
| + | SMAPI's <tt>SButton</tt> constants uniquely represent controller, keyboard, and mouse button presses or clicks. See the [[../Input|Input]] page for more info. |