diff --git a/CustomizableClock/CustomizableClock.csproj b/CustomizableClock/CustomizableClock.csproj index 3c0eebd..341f33f 100644 --- a/CustomizableClock/CustomizableClock.csproj +++ b/CustomizableClock/CustomizableClock.csproj @@ -36,6 +36,7 @@ TRACE prompt 4 + x86 diff --git a/DynamicNightTime/DynamicNightTime.cs b/DynamicNightTime/DynamicNightTime.cs index ce715e8..e63ac14 100644 --- a/DynamicNightTime/DynamicNightTime.cs +++ b/DynamicNightTime/DynamicNightTime.cs @@ -88,40 +88,47 @@ public override void Entry(IModHelper helper) Monitor.Log($"Postfixing {UpdateGameClock} with {postfixClock}", LogLevel.Trace); harmony.Patch(UpdateGameClock, null, new HarmonyMethod(postfixClock)); - GameEvents.FirstUpdateTick += GameEvents_FirstUpdateTick; - TimeEvents.AfterDayStarted += HandleNewDay; - SaveEvents.AfterReturnToTitle += HandleReturn; - TimeEvents.TimeOfDayChanged += HandleTimeChanges; - + helper.Events.GameLoop.GameLaunched += GameLoop_GameLaunched; + helper.Events.GameLoop.DayStarted += GameLoop_DayStarted; + helper.Events.GameLoop.ReturnedToTitle += GameLoop_ReturnedToTitle; + helper.Events.GameLoop.TimeChanged += GameLoop_TimeChanged; + Helper.ConsoleCommands.Add("debug_cycleinfo", "Outputs the cycle information", OutputInformation); Helper.ConsoleCommands.Add("debug_outdoorlight", "Outputs the outdoor light information", OutputLight); Helper.ConsoleCommands.Add("debug_setlatitude", "Sets Latitude", SetLatitude); } - private void GameEvents_FirstUpdateTick(object sender, EventArgs e) + private void GameLoop_TimeChanged(object sender, TimeChangedEventArgs e) { - //testing for ZA MOON, YOUR HIGHNESS. - MoonAPI = SDVUtilities.GetModApi(Monitor, Helper, "KoihimeNakamura.LunarDisturbances", "1.0.7"); + /* + //handle ambient light changes. + if (!Game1.currentLocation.IsOutdoors && Game1.currentLocation is DecoratableLocation locB) + { + Game1.ambientLight = Game1.isDarkOut() || locB.LightLevel > 0.0 ? new Color(180, 180, 0) : Color.White; + } + */ - if (MoonAPI != null) - LunarDisturbancesLoaded = true; - } + //handle the game being bad at night->day :| + if (Game1.timeOfDay < GetSunriseTime()) + { + Game1.currentLocation.switchOutNightTiles(); + isNightOut = true; + } - private void SetLatitude(string arg1, string[] arg2) - { - if (arg2.Length > 0) + if (Game1.timeOfDay >= GetSunriseTime() && isNightOut) { - NightConfig.Latitude = Convert.ToDouble(arg2[0]); + Game1.currentLocation.addLightGlows(); + isNightOut = false; } } - private void HandleReturn(object sender, EventArgs e) + private void GameLoop_ReturnedToTitle(object sender, ReturnedToTitleEventArgs e) { resetOnWakeup = false; } - private void HandleNewDay(object sender, EventArgs e) + private void GameLoop_DayStarted(object sender, DayStartedEventArgs e) { if (Game1.isDarkOut() && !Game1.currentLocation.IsOutdoors && Game1.currentLocation is DecoratableLocation loc && !resetOnWakeup) { @@ -135,25 +142,20 @@ private void HandleNewDay(object sender, EventArgs e) resetOnWakeup = false; } - private void HandleTimeChanges(object sender, EventArgsIntChanged e) + private void GameLoop_GameLaunched(object sender, GameLaunchedEventArgs e) { - //handle ambient light changes. - if (!Game1.currentLocation.IsOutdoors && Game1.currentLocation is DecoratableLocation locB) - { - Game1.ambientLight = Game1.isDarkOut() || locB.LightLevel > 0.0 ? new Color(180, 180, 0) : Color.White; - } - - //handle the game being bad at night->day :| - if (Game1.timeOfDay < GetSunriseTime()) - { - Game1.currentLocation.switchOutNightTiles(); - isNightOut = true; - } + //testing for ZA MOON, YOUR HIGHNESS. + MoonAPI = SDVUtilities.GetModApi(Monitor, Helper, "KoihimeNakamura.LunarDisturbances", "1.0.7"); - if (Game1.timeOfDay >= GetSunriseTime() && isNightOut) + if (MoonAPI != null) + LunarDisturbancesLoaded = true; + } + + private void SetLatitude(string arg1, string[] arg2) + { + if (arg2.Length > 0) { - Game1.currentLocation.addLightGlows(); - isNightOut = false; + NightConfig.Latitude = Convert.ToDouble(arg2[0]); } } @@ -229,6 +231,21 @@ public static Color GetLunarLightDifference(int timeOfDay) return new Color(colorValR, colorValG, colorValB); } + + public static byte ClampByteValue(int raw) + { + + byte R = 0; + + if (raw >= 0 && raw <= 255) + R = (byte)raw; + else if (raw < 0) + R = (byte)0; + else if (raw > 255) + R = (byte)255; + + return R; + } public static int GetSunriseTime() => GetSunrise().ReturnIntTime(); public static SDVTime GetMorningAstroTwilight() => GetTimeAtHourAngle(-0.314159265); diff --git a/DynamicNightTime/DynamicNightTime.csproj b/DynamicNightTime/DynamicNightTime.csproj index 0a3e961..7343095 100644 --- a/DynamicNightTime/DynamicNightTime.csproj +++ b/DynamicNightTime/DynamicNightTime.csproj @@ -35,6 +35,7 @@ TRACE prompt 4 + x86 diff --git a/DynamicNightTime/Patches/GameClockPatch.cs b/DynamicNightTime/Patches/GameClockPatch.cs index a71bee8..4e0d676 100644 --- a/DynamicNightTime/Patches/GameClockPatch.cs +++ b/DynamicNightTime/Patches/GameClockPatch.cs @@ -108,24 +108,36 @@ public static void Postfix() { float minEff = SDVTime.MinutesBetweenTwoIntTimes(Game1.timeOfDay, sunset) + (float)Math.Min(10.0, Game1.gameTimeInterval / 700); float percentage = (minEff / SDVTime.MinutesBetweenTwoIntTimes(sunset, astroTwilight)); - Color destColor = new Color((byte)(0 + (227*percentage)), (byte)(98 + (111 * percentage)), (byte)(193 - (35 * percentage)), (byte)(255 - (17 * percentage))); - Game1.outdoorLight = destColor; + Color destColor = new Color(r: (byte)(0 + (227*percentage)), g: (byte)(98 + (111 * percentage)), b: (byte)(193 - (193 * percentage)), a:(byte)(255 - (17 * percentage))); + + DynamicNightTime.Logger.Log($"Destination color is {destColor}", StardewModdingAPI.LogLevel.Info); //[222,222,15] - if (Game1.timeOfDay > Game1.getModeratelyDarkTime() && (DynamicNightTime.LunarDisturbancesLoaded && DynamicNightTime.MoonAPI.IsMoonUp(Game1.timeOfDay))) + + if (DynamicNightTime.LunarDisturbancesLoaded && DynamicNightTime.MoonAPI.IsMoonUp(Game1.timeOfDay)) { //start adding the moon in naval light minEff = SDVTime.MinutesBetweenTwoIntTimes(Game1.timeOfDay, Game1.getModeratelyDarkTime()) + (float)Math.Min(10.0, Game1.gameTimeInterval / 700); percentage = (minEff / SDVTime.MinutesBetweenTwoIntTimes(Game1.getModeratelyDarkTime(), astroTwilight)); + + int rRaw = (int)(destColor.R - (moonLight.R * percentage)); + int gRaw = (int)(destColor.G - (moonLight.G * percentage)); + int bRaw = (int)(destColor.B - (moonLight.B * percentage)); - byte R = (byte)(destColor.R - (moonLight.R * percentage)); - byte G = (byte)(destColor.G - (moonLight.G * percentage)); - byte B = (byte)(destColor.B - (moonLight.B * percentage)); + byte R = 0, G = 0, B = 0; - Game1.outdoorLight = new Color(R,G,B, Game1.outdoorLight.A); + R = DynamicNightTime.ClampByteValue(rRaw); + G = DynamicNightTime.ClampByteValue(gRaw); + B = DynamicNightTime.ClampByteValue(bRaw); + + destColor.R = R; + destColor.G = G; + destColor.B = B; } - //Game1.outdoorLight = SDVUtilities.SubtractTwoColors(destColor, moonLight); - //DynamicNightTime.Logger.Log($"The color is being set to {Game1.outdoorLight} from {destColor} with the moon being {moonLight}"); + DynamicNightTime.Logger.Log($"Destination color is {destColor}", StardewModdingAPI.LogLevel.Info); + DynamicNightTime.Logger.Log($"Outdoor color is {Game1.outdoorLight}", StardewModdingAPI.LogLevel.Info); + Game1.outdoorLight = destColor; + DynamicNightTime.Logger.Log($"Outdoor color is {Game1.outdoorLight}", StardewModdingAPI.LogLevel.Info); } //astro diff --git a/DynamicNightTime/manifest.json b/DynamicNightTime/manifest.json index 9e40322..50e7f39 100644 --- a/DynamicNightTime/manifest.json +++ b/DynamicNightTime/manifest.json @@ -1,10 +1,10 @@ { "Name": "Dynamic Night Time", "Author": "knakamura", - "Version": "1.2.1", + "Version": "1.2.4", "Description": "Dynamic Night Time", "UniqueID": "knakamura.dynamicnighttime", "EntryDll": "DynamicNightTime.dll", - "MinimumApiVersion": "2.8", + "MinimumApiVersion": "2.9.3", "UpdateKeys": [ "Nexus:2072" ] } diff --git a/SummitReborn/SummitReborn.csproj b/SummitReborn/SummitReborn.csproj index def3f40..23a135c 100644 --- a/SummitReborn/SummitReborn.csproj +++ b/SummitReborn/SummitReborn.csproj @@ -36,6 +36,7 @@ TRACE prompt 4 + x86