From b0b7a8f5dca0cede88229cea91f66c50be8fcdb3 Mon Sep 17 00:00:00 2001 From: Joshua Navarro Date: Mon, 24 Dec 2018 12:36:03 -0800 Subject: [PATCH] Finished darker night. --- .../Framework/Environment/DarkerNight.cs | 37 +++++++++++++++++-- GeneralMods/Revitalize/ModCore.cs | 8 +++- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/GeneralMods/Revitalize/Framework/Environment/DarkerNight.cs b/GeneralMods/Revitalize/Framework/Environment/DarkerNight.cs index fa4c5d6a..c2e86615 100644 --- a/GeneralMods/Revitalize/Framework/Environment/DarkerNight.cs +++ b/GeneralMods/Revitalize/Framework/Environment/DarkerNight.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using Revitalize.Framework.Illuminate; using System.IO; +using Microsoft.Xna.Framework; namespace Revitalize.Framework.Environment { @@ -18,6 +19,8 @@ namespace Revitalize.Framework.Environment public static DarkerNightConfig Config; + private static Color CalculatedColor; + public static void InitializeConfig() { if (File.Exists(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, "Configs", "DarkerNightConfig.json"))) @@ -31,15 +34,41 @@ namespace Revitalize.Framework.Environment } } - public static void setDarkerNightColor() + public static void SetDarkerColor() + { + if (Game1.player.currentLocation.IsOutdoors && Game1.timeOfDay >= Game1.getStartingToGetDarkTime()) + { + Game1.outdoorLight = CalculatedColor; + } + } + + + public static void CalculateDarkerNightColor() { if (Game1.player == null) return; - if (Game1.player.currentLocation.IsOutdoors && Game1.timeOfDay>= Game1.getTrulyDarkTime()) + + //Calculate original lighting. + if (Game1.timeOfDay >= Game1.getTrulyDarkTime()) + { + float num = Math.Min(0.93f, (float)(0.75 + ((double)((int)((double)(Game1.timeOfDay - Game1.timeOfDay % 100) + (double)(Game1.timeOfDay % 100 / 10) * 16.6599998474121) - Game1.getTrulyDarkTime()) + (double)Game1.gameTimeInterval / 7000.0 * 16.6000003814697) * 0.000624999986030161)); + Game1.outdoorLight = (Game1.isRaining ? Game1.ambientLight : Game1.eveningColor) * num; + } + else if (Game1.timeOfDay >= Game1.getStartingToGetDarkTime()) + { + float num = Math.Min(0.93f, (float)(0.300000011920929 + ((double)((int)((double)(Game1.timeOfDay - Game1.timeOfDay % 100) + (double)(Game1.timeOfDay % 100 / 10) * 16.6599998474121) - Game1.getStartingToGetDarkTime()) + (double)Game1.gameTimeInterval / 7000.0 * 16.6000003814697) * 0.00224999990314245)); + Game1.outdoorLight = (Game1.isRaining ? Game1.ambientLight : Game1.eveningColor) * num; + } + + Revitalize.ModCore.log("OUT: " + Game1.outdoorLight); + + int red = Game1.outdoorLight.R; + + if (Game1.player.currentLocation.IsOutdoors && Game1.timeOfDay>= Game1.getStartingToGetDarkTime()) { //Game1.ambientLight = Game1.ambientLight.GreyScaleAverage(); - Game1.outdoorLight = Game1.ambientLight*Config.DarknessIntensity; + CalculatedColor = Game1.ambientLight* ( (red+30) / 255f) * Config.DarknessIntensity; - Revitalize.ModCore.log("OUT: " + Game1.outdoorLight); + Revitalize.ModCore.log("OUT: " + CalculatedColor); Revitalize.ModCore.log("Ambient"+Game1.ambientLight); } } diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index 2026cf8b..c8e6f9c4 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -35,6 +35,7 @@ namespace Revitalize ModHelper.Events.GameLoop.SaveLoaded += GameLoop_SaveLoaded; ModHelper.Events.GameLoop.TimeChanged += GameLoop_TimeChanged; + ModHelper.Events.GameLoop.UpdateTicked += GameLoop_UpdateTicked; } @@ -49,9 +50,14 @@ namespace Revitalize } + private void GameLoop_UpdateTicked(object sender, StardewModdingAPI.Events.UpdateTickedEventArgs e) + { + DarkerNight.SetDarkerColor(); + } + private void GameLoop_TimeChanged(object sender, StardewModdingAPI.Events.TimeChangedEventArgs e) { - DarkerNight.setDarkerNightColor(); + DarkerNight.CalculateDarkerNightColor(); } private void GameLoop_SaveLoaded(object sender, StardewModdingAPI.Events.SaveLoadedEventArgs e)