This wiki is a read-only version of the Stardew Valley Wiki. The official editable wiki maintained by ConcernedApe can be found at stardewvalleywiki.com

Changes

Jump to: navigation, search

Modding:Modder Guide/APIs/Utilities

1,272 bytes added, 18:53, 5 September 2020
+ PathUtilities, group sections
SMAPI provides some C# objects you can use to simplify your code.
==Metadata=====Constants===
The <tt>Constants</tt> class provides metadata about SMAPI and the game.
|}
===Context===
The <tt>Context</tt> class provides information about the game state and player control:
|}
==Helpers=====Dates===
Use <tt>SDate</tt> for calculating in-game dates. You start by creating a date:
<source lang="c#">
|}
==Input=File paths==={{SMAPI's <tt>SButton</tt> constants uniquely represent controller, keyboard, and mouse button presses or clicks. See the [[../Inputupcoming|Input]] page for more info3.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> &rarr; <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===
Use <tt>SemanticVersion</tt> to manipulate and compare versions per the [http://semver.org/ Semantic Versioning 2.0 standard]. Example usage:
<source lang="c#">
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.
Protected, translators
5,421
edits

Navigation menu