From 43ebf4fcabf0e8e7d493687f27639f5e7a89c38f Mon Sep 17 00:00:00 2001 From: Nicholas Johnson Date: Sat, 29 Dec 2018 00:35:55 -0800 Subject: [PATCH] DNT final fix, pending reports. Lunar Disturbances updated to 2.9.3 and work done to get a workaround for the moon. i18n work still pending Updated some text on the API handler to be more clear. --- DynamicNightTime/Patches/GameClockPatch.cs | 31 ++- LunarDisturbances/LunarDisturbances.cs | 243 +++++++++--------- LunarDisturbances/MoonConfig.cs | 1 + LunarDisturbances/README.md | 7 + LunarDisturbances/manifest.json | 4 +- .../Stardew Valley/SDVUtilities.cs | 4 +- 6 files changed, 160 insertions(+), 130 deletions(-) diff --git a/DynamicNightTime/Patches/GameClockPatch.cs b/DynamicNightTime/Patches/GameClockPatch.cs index 4e0d676..354aa84 100644 --- a/DynamicNightTime/Patches/GameClockPatch.cs +++ b/DynamicNightTime/Patches/GameClockPatch.cs @@ -110,7 +110,6 @@ public static void Postfix() float percentage = (minEff / SDVTime.MinutesBetweenTwoIntTimes(sunset, astroTwilight)); 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 (DynamicNightTime.LunarDisturbancesLoaded && DynamicNightTime.MoonAPI.IsMoonUp(Game1.timeOfDay)) @@ -134,17 +133,33 @@ public static void Postfix() destColor.B = B; } - 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 - if (Game1.timeOfDay >= astroTwilight) { - Game1.outdoorLight = (Game1.eveningColor * .93f); - if ((DynamicNightTime.LunarDisturbancesLoaded && DynamicNightTime.MoonAPI.IsMoonUp(Game1.timeOfDay))) { - Game1.outdoorLight = SDVUtilities.SubtractTwoColors(Game1.outdoorLight, moonLight); + if (Game1.timeOfDay >= astroTwilight){ + + Color destColor = Game1.eveningColor * .93f; + + if ((DynamicNightTime.LunarDisturbancesLoaded && DynamicNightTime.MoonAPI.IsMoonUp(Game1.timeOfDay))) { + int rRaw = (int)(destColor.R - moonLight.R); + int gRaw = (int)(Game1.outdoorLight.G - moonLight.G); + int bRaw = (int)(Game1.outdoorLight.B - moonLight.B); + + byte R = 0, G = 0, B = 0; + + R = DynamicNightTime.ClampByteValue(rRaw); + G = DynamicNightTime.ClampByteValue(gRaw); + B = DynamicNightTime.ClampByteValue(bRaw); + destColor = new Color + { + R = R, + G = G, + B = B, + A = Game1.outdoorLight.A + }; + + Game1.outdoorLight = destColor; } } } diff --git a/LunarDisturbances/LunarDisturbances.cs b/LunarDisturbances/LunarDisturbances.cs index c8c1bb9..f9cd48b 100644 --- a/LunarDisturbances/LunarDisturbances.cs +++ b/LunarDisturbances/LunarDisturbances.cs @@ -43,65 +43,36 @@ public override void Entry(IModHelper helper) OurMoon = new SDVMoon(ModConfig, Dice, Helper.Translation); OurIcons = new Sprites.Icons(Helper.Content); - GameEvents.FirstUpdateTick += GameEvents_FirstUpdateTick; - GameEvents.OneSecondTick += GameEvents_OneSecondTick; - GraphicsEvents.OnPostRenderGuiEvent += DrawOverMenus; - PlayerEvents.Warped += LocationEvents_CurrentLocationChanged; - TimeEvents.TimeOfDayChanged += TenMinuteUpdate; - TimeEvents.AfterDayStarted += HandleNewDay; - MenuEvents.MenuChanged += MenuEvents_MenuChanged; - SaveEvents.BeforeSave += OnEndOfDay; - GameEvents.UpdateTick += CheckForChanges; - SaveEvents.AfterReturnToTitle += ResetMod; + helper.Events.GameLoop.GameLaunched += GameLoop_GameLaunched; + helper.Events.GameLoop.UpdateTicked += GameLoop_UpdateTicked; + helper.Events.GameLoop.TimeChanged += GameLoop_TimeChanged; + helper.Events.GameLoop.DayStarted += GameLoop_DayStarted; + helper.Events.GameLoop.Saving += GameLoop_Saving; + helper.Events.GameLoop.UpdateTicked += ChangesPerTick; + helper.Events.Display.RenderedActiveMenu += Display_RenderedActiveMenu; + helper.Events.Display.MenuChanged += Display_MenuChanged; + helper.Events.Player.Warped += Player_Warped; + helper.Events.GameLoop.ReturnedToTitle += GameLoop_ReturnedToTitle; } - private void OutputLight(string arg1, string[] arg2) - { - Monitor.Log($"The outdoor light is {Game1.outdoorLight.ToString()}. The ambient light is {Game1.ambientLight.ToString()}"); - } - - private void GameEvents_FirstUpdateTick(object sender, EventArgs e) + private void GameLoop_ReturnedToTitle(object sender, ReturnedToTitleEventArgs e) { - JAAPi = SDVUtilities.GetModApi(Monitor, Helper, "spacechase0.JsonAssets", "1.1"); - - if (JAAPi != null) - { - UseJsonAssetsApi = true; - JAAPi.AddedItemsToShop += JAAPi_AddedItemsToShop; - Monitor.Log("JsonAssets Integration enabled", LogLevel.Info); - } + OurMoon.Reset(); } - private void DrawOverMenus(object sender, EventArgs e) + private void ChangesPerTick(object sender, UpdateTickedEventArgs e) { - bool outro = false; - //revised this so it properly draws over the canon moon. :v - if (Game1.activeClickableMenu is ShippingMenu ourMenu) - { - outro = Helper.Reflection.GetField(ourMenu, "outro").GetValue(); - } - - if (Game1.showingEndOfNightStuff && !Game1.wasRainingYesterday && !outro && Game1.activeClickableMenu is ShippingMenu currMenu) + if (IsEclipse && ResetTicker > 0) { - float scale = Game1.pixelZoom * 1.25f; - - if (Game1.viewport.Width < 1024) - scale = Game1.pixelZoom *.8f; - if (Game1.viewport.Width < 810) - scale = Game1.pixelZoom * .6f; - if (Game1.viewport.Width < 700) - scale = Game1.pixelZoom * .35f; - - Game1.spriteBatch.Draw(OurIcons.MoonSource, new Vector2(Game1.viewport.Width - 65 * Game1.pixelZoom, Game1.pixelZoom), OurIcons.GetNightMoonSprite(SDVMoon.GetLunarPhaseForDay(SDate.Now().AddDays(-1))), Color.LightBlue, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1f); + Monitor.Log("Eclipse code firing"); + Game1.globalOutdoorLighting = .5f; + Game1.ambientLight = nightColor; + Game1.currentLocation.switchOutNightTiles(); + ResetTicker = 0; } } - /// - /// This function handles the end of the day. - /// - /// - /// - private void OnEndOfDay(object sender, EventArgs e) + private void GameLoop_Saving(object sender, SavingEventArgs e) { if (!Context.IsMainPlayer) return; @@ -123,40 +94,31 @@ private void OnEndOfDay(object sender, EventArgs e) OurMoon.HandleMoonAtSleep(Game1.getFarm()); } - /// - /// This handles location changes - /// - /// The sender - /// Parameters - private void LocationEvents_CurrentLocationChanged(object sender, EventArgsPlayerWarped e) + private void GameLoop_SaveCreating(object sender, SaveCreatingEventArgs e) { - if (IsEclipse) - { - Game1.globalOutdoorLighting = .5f; - Game1.currentLocation.switchOutNightTiles(); - Game1.ambientLight = nightColor; + if (!Context.IsMainPlayer) + return; - if (!Game1.currentLocation.IsOutdoors && Game1.currentLocation is DecoratableLocation) + //cleanup any spawned monsters + foreach (GameLocation l in Game1.locations) + { + for (int index = l.characters.Count - 1; index >= 0; --index) { - var loc = Game1.currentLocation as DecoratableLocation; - foreach (Furniture f in loc.furniture) - { - if (f.furniture_type.Value == Furniture.window) - Helper.Reflection.GetMethod(f, "addLights").Invoke(new object[] { Game1.currentLocation }); - } + if (l.characters[index] is Monster && !(l.characters[index] is GreenSlime)) + l.characters.RemoveAt(index); } } - if (OurMoon.CurrentPhase == MoonPhase.BloodMoon) - { - Game1.currentLocation.waterColor.Value = OurMoon.BloodMoonWater; - } + if (IsEclipse) + IsEclipse = false; + + //moon works after frost does + OurMoon.HandleMoonAtSleep(Game1.getFarm()); } - private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) + + private void Display_MenuChanged(object sender, MenuChangedEventArgs e) { - if (e.NewMenu is null) - Monitor.Log("e.NewMenu is null"); if (!UseJsonAssetsApi) { if (e.NewMenu is ShopMenu menu && menu.portraitPerson != null) @@ -181,32 +143,41 @@ private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged } } - /// - /// This checks for things every second. - /// - /// Object sending - /// event params - private void CheckForChanges(object sender, EventArgs e) + private void GameLoop_DayStarted(object sender, DayStartedEventArgs e) { - if (IsEclipse && ResetTicker > 0) + if (OurMoon.GetMoonRiseTime() <= 0600 || OurMoon.GetMoonRiseTime() >= 2600 && ModConfig.ShowMoonPhase) + Game1.addHUDMessage(new HUDMessage(Helper.Translation.Get("moon-text.moonriseBefore6", new { moonPhase = OurMoon.GetLunarPhase().ToString(), riseTime = OurMoon.GetMoonRiseTime() }))); + + if (OurMoon == null) { - Monitor.Log("Eclipse code firing"); - Game1.globalOutdoorLighting = .5f; - Game1.ambientLight = nightColor; - Game1.currentLocation.switchOutNightTiles(); - ResetTicker = 0; + Monitor.Log("OurMoon is null"); + return; + } + + if (Dice.NextDouble() < ModConfig.EclipseChance && ModConfig.EclipseOn && OurMoon.CurrentPhase == MoonPhase.FullMoon && + SDate.Now().DaysSinceStart > 2) + { + IsEclipse = true; + var n = new HUDMessage("It looks like a rare solar eclipse will darken the sky all day!") + { + color = Color.SeaGreen, + fadeIn = true, + timeLeft = 4000, + noIcon = true + }; + Game1.addHUDMessage(n); + + Monitor.Log("There's a solar eclipse today!", LogLevel.Info); } + + OurMoon.OnNewDay(); + OurMoon.HandleMoonAfterWake(); } - /// - /// Handles the ten minute update tick - /// - /// Sender - /// Parameters - private void TenMinuteUpdate(object sender, EventArgsIntChanged e) + private void GameLoop_TimeChanged(object sender, TimeChangedEventArgs e) { if (Game1.timeOfDay == OurMoon.GetMoonRiseTime() && ModConfig.ShowMoonPhase) - Game1.addHUDMessage(new HUDMessage(Helper.Translation.Get("moon-text.moonrise", new { moonPhase = OurMoon.GetLunarPhase().ToString()}))); + Game1.addHUDMessage(new HUDMessage(Helper.Translation.Get("moon-text.moonrise", new { moonPhase = OurMoon.GetLunarPhase().ToString() }))); if (Game1.timeOfDay == OurMoon.GetMoonSetTime() && ModConfig.ShowMoonPhase) Game1.addHUDMessage(new HUDMessage(Helper.Translation.Get("moon-text.moonset", new { moonPhase = OurMoon.GetLunarPhase().ToString() }))); @@ -253,43 +224,62 @@ private void TenMinuteUpdate(object sender, EventArgsIntChanged e) OurMoon.TenMinuteUpdate(); } - private void ResetMod(object sender, EventArgs e) + private void Player_Warped(object sender, WarpedEventArgs e) { - OurMoon.Reset(); - } - - private void HandleNewDay(object sender, EventArgs e) - { - if (OurMoon.GetMoonRiseTime() <= 0600 || OurMoon.GetMoonRiseTime() >= 2600 && ModConfig.ShowMoonPhase) - Game1.addHUDMessage(new HUDMessage(Helper.Translation.Get("moon-text.moonriseBefore6", new { moonPhase = OurMoon.GetLunarPhase().ToString(), riseTime = OurMoon.GetMoonRiseTime() }))); - - if (OurMoon == null) + if (!(e.IsLocalPlayer)) { - Monitor.Log("OurMoon is null"); return; } - if (Dice.NextDouble() < ModConfig.EclipseChance && ModConfig.EclipseOn && OurMoon.CurrentPhase == MoonPhase.FullMoon && - SDate.Now().DaysSinceStart > 2) + + if (IsEclipse) { - IsEclipse = true; - var n = new HUDMessage("It looks like a rare solar eclipse will darken the sky all day!") + Game1.globalOutdoorLighting = .5f; + Game1.currentLocation.switchOutNightTiles(); + Game1.ambientLight = nightColor; + + if (!Game1.currentLocation.IsOutdoors && Game1.currentLocation is DecoratableLocation) { - color = Color.SeaGreen, - fadeIn = true, - timeLeft = 4000, - noIcon = true - }; - Game1.addHUDMessage(n); + var loc = Game1.currentLocation as DecoratableLocation; + foreach (Furniture f in loc.furniture) + { + if (f.furniture_type.Value == Furniture.window) + Helper.Reflection.GetMethod(f, "addLights").Invoke(new object[] { Game1.currentLocation }); + } + } + } - Monitor.Log("There's a solar eclipse today!", LogLevel.Info); + if (OurMoon.CurrentPhase == MoonPhase.BloodMoon) + { + Game1.currentLocation.waterColor.Value = OurMoon.BloodMoonWater; } + } - OurMoon.OnNewDay(); - OurMoon.HandleMoonAfterWake(); + private void Display_RenderedActiveMenu(object sender, RenderedActiveMenuEventArgs e) + { + bool outro = false; + //revised this so it properly draws over the canon moon. :v + if (Game1.activeClickableMenu is ShippingMenu ourMenu) + { + outro = Helper.Reflection.GetField(ourMenu, "outro").GetValue(); + } + + if (Game1.showingEndOfNightStuff && !Game1.wasRainingYesterday && !outro && Game1.activeClickableMenu is ShippingMenu currMenu && ModConfig.ShowMoonInEndOfNight) + { + float scale = Game1.pixelZoom * 1.25f; + + if (Game1.viewport.Width < 1024) + scale = Game1.pixelZoom * .8f; + if (Game1.viewport.Width < 810) + scale = Game1.pixelZoom * .6f; + if (Game1.viewport.Width < 700) + scale = Game1.pixelZoom * .35f; + + Game1.spriteBatch.Draw(OurIcons.MoonSource, new Vector2(Game1.viewport.Width - 65 * Game1.pixelZoom, Game1.pixelZoom), OurIcons.GetNightMoonSprite(SDVMoon.GetLunarPhaseForDay(SDate.Now().AddDays(-1))), Color.LightBlue, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 1f); + } } - private void GameEvents_OneSecondTick(object sender, EventArgs e) + private void GameLoop_UpdateTicked(object sender, UpdateTickedEventArgs e) { if (Context.IsPlayerFree) { @@ -308,6 +298,23 @@ private void GameEvents_OneSecondTick(object sender, EventArgs e) } } + private void GameLoop_GameLaunched(object sender, GameLaunchedEventArgs e) + { + JAAPi = SDVUtilities.GetModApi(Monitor, Helper, "spacechase0.JsonAssets", "1.1"); + + if (JAAPi != null) + { + UseJsonAssetsApi = true; + JAAPi.AddedItemsToShop += JAAPi_AddedItemsToShop; + Monitor.Log("JsonAssets Integration enabled", LogLevel.Info); + } + } + + private void OutputLight(string arg1, string[] arg2) + { + Monitor.Log($"The outdoor light is {Game1.outdoorLight.ToString()}. The ambient light is {Game1.ambientLight.ToString()}"); + } + private void JAAPi_AddedItemsToShop(object sender, EventArgs e) { if (Game1.activeClickableMenu is ShopMenu menu) diff --git a/LunarDisturbances/MoonConfig.cs b/LunarDisturbances/MoonConfig.cs index d236acc..3d4b90b 100644 --- a/LunarDisturbances/MoonConfig.cs +++ b/LunarDisturbances/MoonConfig.cs @@ -7,6 +7,7 @@ public class MoonConfig public bool EclipseOn = true; public double EclipseChance = .015; public bool ShowMoonPhase = true; + public bool ShowMoonInEndOfNight = true; public bool SpawnMonsters = true; public bool SpawnMonstersAllFarms = false; public bool HazardousMoonEvents = false; diff --git a/LunarDisturbances/README.md b/LunarDisturbances/README.md index 404bd6b..893b049 100644 --- a/LunarDisturbances/README.md +++ b/LunarDisturbances/README.md @@ -25,6 +25,13 @@ Thankfully, they don't appear to spawn on wedding and festival days.. -- monsters spawn every 10 real-world seconds if you are outside. ## Changelog +1.0.8 +- Feature to turn off moon display added +- Updates for SMAPI 3.0 started. +- Moon no longer watches you break down your financial report. +- Some debug lines removed +- Updated the integration logger text + 1.0.7 - Updated for SDV 1.3.32 - API updated for moon rise and set times diff --git a/LunarDisturbances/manifest.json b/LunarDisturbances/manifest.json index 7bce300..f7df7dd 100644 --- a/LunarDisturbances/manifest.json +++ b/LunarDisturbances/manifest.json @@ -1,10 +1,10 @@ { "Name": "Lunar Disturbances", "Author": "KoihimeNakamura", - "Version": "1.0.7", + "Version": "1.0.8", "Description": "Adds a moon to more than just one day, and adds events based on it, including eclipses", "UniqueID": "KoihimeNakamura.LunarDisturbances", "EntryDll": "LunarDisturbances.dll", - "MinimumApiVersion": "2.7", + "MinimumApiVersion": "2.9.3", "UpdateKeys": ["Nexus:2208"] } \ No newline at end of file diff --git a/TwilightCoreShared/Stardew Valley/SDVUtilities.cs b/TwilightCoreShared/Stardew Valley/SDVUtilities.cs index 44fc1ed..0bae66f 100644 --- a/TwilightCoreShared/Stardew Valley/SDVUtilities.cs +++ b/TwilightCoreShared/Stardew Valley/SDVUtilities.cs @@ -124,7 +124,7 @@ public static T GetModApi(IMonitor Monitor, IModHelper Helper, string name, s if (api != null) { - Monitor.Log($"{name} {modManifest.Manifest.Version} Integration enabled", LogLevel.Info); + Monitor.Log($"{name} {modManifest.Manifest.Version} integration feature enabled", LogLevel.Info); } return api; @@ -133,7 +133,7 @@ public static T GetModApi(IMonitor Monitor, IModHelper Helper, string name, s Monitor.Log($"{name} detected, but not of a sufficient version. Req:{minVersion} Detected:{modManifest.Manifest.Version}. Skipping..", LogLevel.Debug); } else - Monitor.Log($"{name} not present. Skipping Integration.", LogLevel.Debug); + Monitor.Log($"{name} not present. Skipping integration feature.", LogLevel.Debug); return null; }