From 4ff15b9da965c541c40a11a79cb521cad744900c Mon Sep 17 00:00:00 2001 From: Nicholas Johnson Date: Tue, 1 Aug 2017 12:27:02 -0700 Subject: add weekday property to SDate (#339) --- src/StardewModdingAPI/Utilities/SDate.cs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/StardewModdingAPI/Utilities') diff --git a/src/StardewModdingAPI/Utilities/SDate.cs b/src/StardewModdingAPI/Utilities/SDate.cs index e0613491..f6650231 100644 --- a/src/StardewModdingAPI/Utilities/SDate.cs +++ b/src/StardewModdingAPI/Utilities/SDate.cs @@ -19,6 +19,8 @@ namespace StardewModdingAPI.Utilities /// The number of days in a season. private readonly int DaysInSeason = 28; + /// The Day of the Week this date has + public DayOfWeek Weekday; /********* ** Accessors @@ -32,7 +34,6 @@ namespace StardewModdingAPI.Utilities /// The year. public int Year { get; } - /********* ** Public methods *********/ @@ -64,6 +65,8 @@ namespace StardewModdingAPI.Utilities this.Day = day; this.Season = season; this.Year = year; + + this.Weekday = GetDayOfWeek(); } /// Get the current in-game date. @@ -114,6 +117,33 @@ namespace StardewModdingAPI.Utilities return $"{this.Day:00} {this.Season} Y{this.Year}"; } + /// + /// This gets the day of the week from the date + /// + /// A constant describing the day + private DayOfWeek GetDayOfWeek() + { + switch (this.Day % 7) + { + case 0: + return DayOfWeek.Sunday; + case 1: + return DayOfWeek.Monday; + case 2: + return DayOfWeek.Tuesday; + case 3: + return DayOfWeek.Wednesday; + case 4: + return DayOfWeek.Thursday; + case 5: + return DayOfWeek.Friday; + case 6: + return DayOfWeek.Saturday; + default: + return 0; + } + } + /**** ** IEquatable ****/ -- cgit From 201d54bbeb2af5d44c35ad4cf77aadb84f09e135 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 1 Aug 2017 15:35:06 -0400 Subject: standardise code & update release notes (#339) --- release-notes.md | 1 + src/StardewModdingAPI/Utilities/SDate.cs | 62 ++++++++++++++++---------------- 2 files changed, 32 insertions(+), 31 deletions(-) (limited to 'src/StardewModdingAPI/Utilities') diff --git a/release-notes.md b/release-notes.md index 14d0179c..a1d78334 100644 --- a/release-notes.md +++ b/release-notes.md @@ -17,6 +17,7 @@ For mod developers: * Added support for optional dependencies. * Added support for string versions (like `"1.0-alpha"`) in `manifest.json`. * Added `IEquatable` to `ISemanticVersion`. +* Added `SDate.DayOfWeek` field. * Removed the TrainerMod `save` and `load` commands. * Removed all deprecated code. * Removed support for mods with no `Name`, `Version`, or `UniqueID` in their manifest. diff --git a/src/StardewModdingAPI/Utilities/SDate.cs b/src/StardewModdingAPI/Utilities/SDate.cs index f6650231..bc3a2b38 100644 --- a/src/StardewModdingAPI/Utilities/SDate.cs +++ b/src/StardewModdingAPI/Utilities/SDate.cs @@ -19,8 +19,6 @@ namespace StardewModdingAPI.Utilities /// The number of days in a season. private readonly int DaysInSeason = 28; - /// The Day of the Week this date has - public DayOfWeek Weekday; /********* ** Accessors @@ -34,6 +32,12 @@ namespace StardewModdingAPI.Utilities /// The year. public int Year { get; } +#if !SMAPI_1_x + /// The day of week. + public DayOfWeek DayOfWeek { get; } +#endif + + /********* ** Public methods *********/ @@ -65,8 +69,7 @@ namespace StardewModdingAPI.Utilities this.Day = day; this.Season = season; this.Year = year; - - this.Weekday = GetDayOfWeek(); + this.DayOfWeek = this.GetDayOfWeek(); } /// Get the current in-game date. @@ -117,33 +120,6 @@ namespace StardewModdingAPI.Utilities return $"{this.Day:00} {this.Season} Y{this.Year}"; } - /// - /// This gets the day of the week from the date - /// - /// A constant describing the day - private DayOfWeek GetDayOfWeek() - { - switch (this.Day % 7) - { - case 0: - return DayOfWeek.Sunday; - case 1: - return DayOfWeek.Monday; - case 2: - return DayOfWeek.Tuesday; - case 3: - return DayOfWeek.Wednesday; - case 4: - return DayOfWeek.Thursday; - case 5: - return DayOfWeek.Friday; - case 6: - return DayOfWeek.Saturday; - default: - return 0; - } - } - /**** ** IEquatable ****/ @@ -228,6 +204,30 @@ namespace StardewModdingAPI.Utilities /********* ** Private methods *********/ + /// Get the day of week for the current date. + private DayOfWeek GetDayOfWeek() + { + switch (this.Day % 7) + { + case 0: + return DayOfWeek.Sunday; + case 1: + return DayOfWeek.Monday; + case 2: + return DayOfWeek.Tuesday; + case 3: + return DayOfWeek.Wednesday; + case 4: + return DayOfWeek.Thursday; + case 5: + return DayOfWeek.Friday; + case 6: + return DayOfWeek.Saturday; + default: + return 0; + } + } + /// Get the current season index. /// The current season wasn't recognised. private int GetSeasonIndex() -- cgit From dafebd1626b6c3b34a818f5f161289a6e32fe4af Mon Sep 17 00:00:00 2001 From: spacechase0 Date: Wed, 9 Aug 2017 16:40:10 -0400 Subject: Fix building SMAPI 1.x --- src/StardewModdingAPI/Framework/SGame.cs | 3 +++ src/StardewModdingAPI/Utilities/SDate.cs | 2 ++ 2 files changed, 5 insertions(+) (limited to 'src/StardewModdingAPI/Utilities') diff --git a/src/StardewModdingAPI/Framework/SGame.cs b/src/StardewModdingAPI/Framework/SGame.cs index 65191931..755f0274 100644 --- a/src/StardewModdingAPI/Framework/SGame.cs +++ b/src/StardewModdingAPI/Framework/SGame.cs @@ -19,6 +19,9 @@ using StardewValley.Menus; using StardewValley.Tools; using xTile.Dimensions; using xTile.Layers; +#if SMAPI_1_x +using SFarmer = StardewValley.Farmer; +#endif namespace StardewModdingAPI.Framework { diff --git a/src/StardewModdingAPI/Utilities/SDate.cs b/src/StardewModdingAPI/Utilities/SDate.cs index bc3a2b38..d7631598 100644 --- a/src/StardewModdingAPI/Utilities/SDate.cs +++ b/src/StardewModdingAPI/Utilities/SDate.cs @@ -69,7 +69,9 @@ namespace StardewModdingAPI.Utilities this.Day = day; this.Season = season; this.Year = year; +#if !SMAPI_1_x this.DayOfWeek = this.GetDayOfWeek(); +#endif } /// Get the current in-game date. -- cgit