Skip to content

Commit

Permalink
DS-48 (#56)
Browse files Browse the repository at this point in the history
* DS-48 Update dependencies

* DS-48 Fix typos, update phrasing

* DS-48 Update I18n keys, add Weather to UI Config

* DS-48 Add Location to UI Config

* DS-48 Add multiple config pages

* DS-48 Add SnapshotRuleName, ZoomLevel, SnapshotDirectory,
SnapshotFileName to UI Config

* DS-48 Shift global effect controls to top of UI Config

* DS-48 Add StartTime and EndTime to UI Config

* DS-48 Add ShortcutKey to UI Config

* DS-48 Add Days to UI Config

* DS-48 Add all UI Config items to Reset method so they can be set back to default values

* DS-48 Update license and contributors list with names

* DS-48 Update Config UI options to be properly tied to correct config settings

* DS-48 Update Newtonsoft.Json from v12.0.3 to v13.0.3

* DS-48 Clean up code

* DS-48 Update manifest.json Version

* DS-48 Clean up code, update documentation

* DS-48 Add Tests folder and move warning_test_files there, add Testing documentation

* DS-48 Update weekday code to reflect Monday being first day of the week

* DS-48 Fix Days to be updated correctly when UI Config has changes saved, remove unnecessary options from UI Config

* DS-48 Fix typo

* DS-48 Update code documentation and i18n text

* DS-48 Comment out Days of the Month code and add explanation in code comment
  • Loading branch information
CompSciLauren committed Nov 26, 2023
1 parent 778e8ce commit adae7b7
Show file tree
Hide file tree
Showing 29 changed files with 1,468 additions and 454 deletions.
6 changes: 4 additions & 2 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
- Lauren Stephenson [@CompSciLauren]
- Scott Atkins [@kins-dev]
- Lauren Vu [@CompSciLauren]
- Scott Atkins [@kins-dev]
- f3wer [@f3wer]
- Atravita Mods [@atravita-mods]
7 changes: 4 additions & 3 deletions DailyScreenshot/DailyScreenshot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="Microsoft.Win32.Registry" Version="6.0.0-preview.5.21301.5" />
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.0.0" />
<PackageReference Include="Pathoschild.Stardew.ModTranslationClassBuilder" Version="2.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.1.1" />
<PackageReference Include="Pathoschild.Stardew.ModTranslationClassBuilder" Version="2.0.1" />
</ItemGroup>
</Project>
58 changes: 50 additions & 8 deletions DailyScreenshot/ModConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Runtime.Serialization;
using static DailyScreenshot.ModTrigger;

namespace DailyScreenshot
{
Expand Down Expand Up @@ -33,6 +34,11 @@ class ModConfig
/// </summary>
private string m_launchGuid;

/// <summary>
/// String to use to indicate a default name
/// </summary>
public static string DEFAULT_NAME = "Unnamed Rule 1";

/// <summary>
/// String to use to indicate a default value
/// </summary>
Expand All @@ -43,6 +49,11 @@ class ModConfig
/// </summary>
public const float DEFAULT_ZOOM = 0.25f;

/// <summary>
/// Key shortcut for taking screenshot
/// </summary>
public static SButton DEFAULT_KEY = SButton.None;

/// <summary>
/// Start of the day in Stardew Valley (6 am)
/// </summary>
Expand All @@ -56,22 +67,50 @@ class ModConfig
/// <summary>
/// Configurable toggle for auditory effects when taking screenshot.
/// </summary>
public bool auditoryEffects = true;
public bool AuditoryEffects = true;

/// <summary>
/// Configurable toggle for visual effects when taking screenshot.
/// </summary>
public bool visualEffects = true;
public bool VisualEffects = true;

/// <summary>
/// Configurable toggle for ingame notifications when taking screenshot.
/// Configurable toggle for ingame screenshot notifications when taking screenshot.
/// </summary>
public bool screenshotNotifications = true;
public bool ScreenshotNotifications = true;

/// <summary>
/// Rules loaded from the config file
/// </summary>
public List<ModRule> SnapshotRules { get; set; } = new List<ModRule>();
public List<ModRule> SnapshotRules { get; set; } = new List<ModRule>
{
CreateDefaultSnapshotRule()
};

/// <summary>
/// Default settings for a set of rules in SnapshotRules
/// </summary>
public static ModRule CreateDefaultSnapshotRule()
{
ModRule newRule = new ModRule
{
Name = DEFAULT_NAME,
ZoomLevel = DEFAULT_ZOOM,
Directory = DEFAULT_STRING,
FileName = ModRule.FileNameFlags.Default,
Trigger =
{
Days = DateFlags.Daily,
Weather = WeatherFlags.Any,
Location = LocationFlags.Farm,
Key = DEFAULT_KEY,
StartTime = DEFAULT_START_TIME,
EndTime = DEFAULT_END_TIME
}
};

return newRule;
}

// Place to put json that doesn't match properties here
// This can be used to upgrade the config file
Expand Down Expand Up @@ -99,9 +138,12 @@ public ModConfig()

public void Reset()
{
auditoryEffects = true;
visualEffects = true;
screenshotNotifications = true;
// global settings
AuditoryEffects = true;
VisualEffects = true;
ScreenshotNotifications = true;

ModEntry.g_dailySS.ResetMainSnapshotRule();
}

private T GetOldData<T>(IDictionary<string, JToken> oldDatDict, string key, T defaultValue)
Expand Down
174 changes: 174 additions & 0 deletions DailyScreenshot/ModConfigHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
using static DailyScreenshot.ModTrigger;

namespace DailyScreenshot
{

/// <summary>
/// Helper methods for checking and updating settings in the Config.
/// </summary>
public class ModConfigHelper
{
/// <summary>
/// Checks if a specific weather condition is present in the WeatherFlags
/// </summary>
/// <param name="weather">WeatherFlags to check</param>
/// <param name="targetWeather">The weather condition to check for</param>
/// <returns>True if the weather condition is present, otherwise false</returns>
public static bool IsWeatherConditionEnabled(ModTrigger.WeatherFlags weather, ModTrigger.WeatherFlags targetWeather)
{
// Check if the specific weather condition is present
return (weather & targetWeather) != 0;
}

/// <summary>
/// Updates weather with the new value for targetWeather.
/// </summary>
/// <param name="weather">WeatherFlags to check</param>
/// <param name="targetWeather">The weather condition to check for</param>
/// <param name="val">What the new value should be</param>
/// <returns>Updated value for weather</returns>
public static ModTrigger.WeatherFlags UpdateWeatherCondition(ModTrigger.WeatherFlags weather, ModTrigger.WeatherFlags targetWeather, bool val)
{
if (val)
{
// If targetWeather is true, add it to weather
weather |= targetWeather;
}
else
{
// If targetWeather is false, remove it from weather
weather &= ~targetWeather;
}

return weather;
}

/// <summary>
/// Checks if a specific location condition is present in the LocationFlags
/// </summary>
/// <param name="location">LocationFlags to check</param>
/// <param name="targetLocation">The location condition to check for</param>
/// <returns>True if the location condition is present, otherwise false</returns>
public static bool IsLocationConditionEnabled(ModTrigger.LocationFlags location, ModTrigger.LocationFlags targetLocation)
{
// Check if the specific location condition is present
return (location & targetLocation) != 0;
}

/// <summary>
/// Updates location with the new value for targetLocation.
/// </summary>
/// <param name="location">LocationFlags to check</param>
/// <param name="targetLocation">The location condition to check for</param>
/// <param name="val">What the new value should be</param>
/// <returns>Updated value for location</returns>
public static ModTrigger.LocationFlags UpdateLocationCondition(ModTrigger.LocationFlags location, ModTrigger.LocationFlags targetLocation, bool val)
{
if (val)
{
// If targetLocation is true, add it to location
location |= targetLocation;
}
else
{
// If targetLocation is false, remove it from location
location &= ~targetLocation;
}

return location;
}

/// <summary>
/// Checks if a specific date condition is present in the DateFlags
/// </summary>
/// <param name="date">DateFlags to check</param>
/// <param name="targetDate">The date condition to check for</param>
/// <returns>True if the date condition is present, otherwise false</returns>
public static bool IsDateConditionEnabled(ModTrigger.DateFlags date, ModTrigger.DateFlags targetDate)
{
// Check if the specific date condition is present
return (date & targetDate) != 0;
}

/// <summary>
/// Checks whether the new value for the date condition is actually a new value or if it's the same as what's already present in the config.
/// </summary>
/// <param name="date">DateFlags to check</param>
/// <param name="targetDate">The date condition to check for</param>
/// <param name="val">What the new value should be</param>
/// <returns>True if date condition is already set, otherwise false</returns>
public static bool IsDateConditionAlreadySet(ModTrigger.DateFlags date, ModTrigger.DateFlags targetDate, bool val)
{
if (val)
{
// If trying to set the date to true, check if it's already true
return (date & targetDate) != 0;
}
else
{
// If trying to set the date to false, check if it's already false
return (date & targetDate) == 0;
}
}

/// <summary>
/// Updates date with the new value for targetDate.
/// </summary>
/// <param name="date">DateFlags to check</param>
/// <param name="targetDate">The date condition to check for</param>
/// <param name="val">What the new value should be</param>
/// <returns>Updated value for date</returns>
public static ModTrigger.DateFlags UpdateDateCondition(ModTrigger.DateFlags date, ModTrigger.DateFlags targetDate, bool val)
{
// If updating a specific day or other flags, proceed as before
if (val)
{
// If targetDate is true, add it to date
date |= targetDate;
}
else
{
// If targetDate is false, remove it from date
date &= ~targetDate;
}

return date;
}

/// <summary>
/// Checks if a specific fileName condition is present in the FileNameFlags
/// </summary>
/// <param name="fileName">FileNameFlags to check</param>
/// <param name="targetDate">The fileName condition to check for</param>
/// <returns>True if the fileName condition is present, otherwise false</returns>
public static bool IsFileNameConditionEnabled(ModRule.FileNameFlags fileName, ModRule.FileNameFlags targetFileName)
{
// Check if the specific fileName condition is present
return (fileName & targetFileName) != 0;
}

/// <summary>
/// Updates fileName with the new value for targetFileName.
/// </summary>
/// <param name="fileName">FileNameFlags to check</param>
/// <param name="targetFileName">The fileName condition to check for</param>
/// <param name="val">What the new value should be</param>
/// <returns>Updated value for fileName</returns>
public static ModRule.FileNameFlags UpdateFileNameCondition(ModRule.FileNameFlags fileName, ModRule.FileNameFlags targetFileName, bool val)
{
if (val)
{
// If targetFileName is true, add it to fileName
fileName |= targetFileName;
}
else
{
// If targetFileName is false, remove it from fileName
fileName &= ~targetFileName;
}

return fileName;
}
}

}
Loading

0 comments on commit adae7b7

Please sign in to comment.