Skip to content

Commit

Permalink
DNT final fix, pending reports. Lunar Disturbances updated to 2.9.3 a…
Browse files Browse the repository at this point in the history
…nd work done to get a workaround for the moon. i18n work still pending

Updated some text on the API handler to be more clear.
  • Loading branch information
Sakorona committed Dec 29, 2018
1 parent db35acd commit 43ebf4f
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 130 deletions.
31 changes: 23 additions & 8 deletions DynamicNightTime/Patches/GameClockPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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;
}
}
}
Expand Down
243 changes: 125 additions & 118 deletions LunarDisturbances/LunarDisturbances.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integrations.IJsonAssetsApi>(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<bool>(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;
}
}

/// <summary>
/// This function handles the end of the day.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnEndOfDay(object sender, EventArgs e)
private void GameLoop_Saving(object sender, SavingEventArgs e)
{
if (!Context.IsMainPlayer)
return;
Expand All @@ -123,40 +94,31 @@ private void OnEndOfDay(object sender, EventArgs e)
OurMoon.HandleMoonAtSleep(Game1.getFarm());
}

/// <summary>
/// This handles location changes
/// </summary>
/// <param name="sender">The sender</param>
/// <param name="e">Parameters</param>
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)
Expand All @@ -181,32 +143,41 @@ private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged
}
}

/// <summary>
/// This checks for things every second.
/// </summary>
/// <param name="sender">Object sending</param>
/// <param name="e">event params</param>
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();
}

/// <summary>
/// Handles the ten minute update tick
/// </summary>
/// <param name="sender">Sender</param>
/// <param name="e">Parameters</param>
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() })));
Expand Down Expand Up @@ -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<bool>(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)
{
Expand All @@ -308,6 +298,23 @@ private void GameEvents_OneSecondTick(object sender, EventArgs e)
}
}

private void GameLoop_GameLaunched(object sender, GameLaunchedEventArgs e)
{
JAAPi = SDVUtilities.GetModApi<Integrations.IJsonAssetsApi>(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)
Expand Down
1 change: 1 addition & 0 deletions LunarDisturbances/MoonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions LunarDisturbances/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 43ebf4f

Please sign in to comment.