From 48eb5e6be02feae26a6e374992cfeed9d60a5757 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 9 Aug 2020 19:10:54 -0400 Subject: add support for read/writing SDate to JSON --- src/SMAPI/Utilities/SDate.cs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/SMAPI/Utilities') diff --git a/src/SMAPI/Utilities/SDate.cs b/src/SMAPI/Utilities/SDate.cs index 03230334..165667a4 100644 --- a/src/SMAPI/Utilities/SDate.cs +++ b/src/SMAPI/Utilities/SDate.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using Newtonsoft.Json; using StardewModdingAPI.Framework; using StardewValley; @@ -35,15 +36,18 @@ namespace StardewModdingAPI.Utilities /// The index of the season (where 0 is spring, 1 is summer, 2 is fall, and 3 is winter). /// This is used in some game calculations (e.g. seasonal game sprites) and methods (e.g. ). + [JsonIgnore] public int SeasonIndex { get; } /// The year. public int Year { get; } /// The day of week. + [JsonIgnore] public DayOfWeek DayOfWeek { get; } /// The number of days since the game began (starting at 1 for the first day of spring in Y1). + [JsonIgnore] public int DaysSinceStart { get; } @@ -62,6 +66,7 @@ namespace StardewModdingAPI.Utilities /// The season name. /// The year. /// One of the arguments has an invalid value (like day 35). + [JsonConstructor] public SDate(int day, string season, int year) : this(day, season, year, allowDayZero: false) { } -- cgit From c37280222dac3409f78413d90c8e50f6d410b3d1 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 23 Aug 2020 20:53:09 -0400 Subject: minor cleanup --- src/SMAPI/Utilities/SDate.cs | 1 - 1 file changed, 1 deletion(-) (limited to 'src/SMAPI/Utilities') diff --git a/src/SMAPI/Utilities/SDate.cs b/src/SMAPI/Utilities/SDate.cs index 165667a4..cd075dcc 100644 --- a/src/SMAPI/Utilities/SDate.cs +++ b/src/SMAPI/Utilities/SDate.cs @@ -269,7 +269,6 @@ namespace StardewModdingAPI.Utilities this.Year = year; this.DayOfWeek = this.GetDayOfWeek(day); this.DaysSinceStart = this.GetDaysSinceStart(day, season, year); - } /// Get whether a date represents 0 spring Y1, which is the date during the in-game intro. -- cgit From 4f3d7eaafc056a7a2b17b1657e069eb456f60f52 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 5 Sep 2020 15:00:38 -0400 Subject: make PathUtilities available to mods --- src/SMAPI/Utilities/PathUtilities.cs | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/SMAPI/Utilities/PathUtilities.cs (limited to 'src/SMAPI/Utilities') diff --git a/src/SMAPI/Utilities/PathUtilities.cs b/src/SMAPI/Utilities/PathUtilities.cs new file mode 100644 index 00000000..ea134468 --- /dev/null +++ b/src/SMAPI/Utilities/PathUtilities.cs @@ -0,0 +1,45 @@ +using System.Diagnostics.Contracts; +using ToolkitPathUtilities = StardewModdingAPI.Toolkit.Utilities.PathUtilities; + +namespace StardewModdingAPI.Utilities +{ + /// Provides utilities for normalizing file paths. + public static class PathUtilities + { + /********* + ** Public methods + *********/ + /// Get the segments from a path (e.g. /usr/bin/example => usr, bin, and example). + /// The path to split. + /// The number of segments to match. Any additional segments will be merged into the last returned part. + [Pure] + public static string[] GetSegments(string path, int? limit = null) + { + return ToolkitPathUtilities.GetSegments(path, limit); + } + + /// Normalize path separators in a file path. + /// The file path to normalize. + [Pure] + public static string NormalizePathSeparators(string path) + { + return ToolkitPathUtilities.NormalizePathSeparators(path); + } + + /// Get whether a path is relative and doesn't try to climb out of its containing folder (e.g. doesn't contain ../). + /// The path to check. + [Pure] + public static bool IsSafeRelativePath(string path) + { + return ToolkitPathUtilities.IsSafeRelativePath(path); + } + + /// Get whether a string is a valid 'slug', containing only basic characters that are safe in all contexts (e.g. filenames, URLs, etc). + /// The string to check. + [Pure] + public static bool IsSlug(string str) + { + return ToolkitPathUtilities.IsSlug(str); + } + } +} -- cgit