update ambient light when setting game time

This commit is contained in:
Jesse Plamondon-Willard 2021-02-21 18:29:14 -05:00
parent 033b385641
commit 27accf55a5
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
2 changed files with 16 additions and 11 deletions

View File

@ -12,15 +12,14 @@
* Added more aggressive memory optimization which should reduce `OutOfMemoryException` errors with some mods. * Added more aggressive memory optimization which should reduce `OutOfMemoryException` errors with some mods.
* Added more detailed error when `Stardew Valley.exe` exists but can't be loaded. * Added more detailed error when `Stardew Valley.exe` exists but can't be loaded.
* Fixed error running `install on Windows.bat` in very rare cases. * Fixed error running `install on Windows.bat` in very rare cases.
* Fixed outdoor ambient lighting not updated when you reverse time using the `world_settime` command _(in Console Commands)_.
* For mod authors: * For mod authors:
* Added early detection of disposed textures so the crash stack trace shows the actual code which used them _(in Error Handler)_.
* Added error details when an event command fails _(in Error Handler)_.
* Fixed asset propagation for `TileSheets/ChairTiles` not changing existing map seats. * Fixed asset propagation for `TileSheets/ChairTiles` not changing existing map seats.
* Fixed edge case when playing in non-English where translatable assets loaded via `IAssetLoader` would no longer be applied after returning to the title screen unless manually invalidated from the cache. * Fixed edge case when playing in non-English where translatable assets loaded via `IAssetLoader` would no longer be applied after returning to the title screen unless manually invalidated from the cache.
* For the ErrorHandler mod:
* Added early detection of disposed textures so the crash stack trace shows the actual code which used them.
* Added error details when an event command fails.
* For the web UI: * For the web UI:
* Updated for the new wiki. * Updated for the new wiki.
* Updated the JSON validator/schema for Content Patcher 1.20. * Updated the JSON validator/schema for Content Patcher 1.20.

View File

@ -1,5 +1,5 @@
using System;
using System.Linq; using System.Linq;
using Microsoft.Xna.Framework;
using StardewValley; using StardewValley;
namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World
@ -45,12 +45,8 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World
/// <param name="time">The time of day.</param> /// <param name="time">The time of day.</param>
private void SafelySetTime(int time) private void SafelySetTime(int time)
{ {
// define conversion between game time and TimeSpan
TimeSpan ToTimeSpan(int value) => new TimeSpan(0, value / 100, value % 100, 0);
int FromTimeSpan(TimeSpan span) => (span.Hours * 100) + span.Minutes;
// transition to new time // transition to new time
int intervals = (int)((ToTimeSpan(time) - ToTimeSpan(Game1.timeOfDay)).TotalMinutes / 10); int intervals = Utility.CalculateMinutesBetweenTimes(Game1.timeOfDay, time) / 10;
if (intervals > 0) if (intervals > 0)
{ {
for (int i = 0; i < intervals; i++) for (int i = 0; i < intervals; i++)
@ -60,10 +56,20 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World
{ {
for (int i = 0; i > intervals; i--) for (int i = 0; i > intervals; i--)
{ {
Game1.timeOfDay = FromTimeSpan(ToTimeSpan(Game1.timeOfDay).Subtract(TimeSpan.FromMinutes(20))); // offset 20 minutes so game updates to next interval Game1.timeOfDay = Utility.ModifyTime(Game1.timeOfDay, -20); // offset 20 mins so game updates to next interval
Game1.performTenMinuteClockUpdate(); Game1.performTenMinuteClockUpdate();
} }
} }
// reset ambient light
// White is the default non-raining color. If it's raining or dark out, UpdateGameClock
// below will update it automatically.
Game1.outdoorLight = Color.White;
Game1.ambientLight = Color.White;
// run clock update (to correct lighting, etc)
Game1.gameTimeInterval = 0;
Game1.UpdateGameClock(Game1.currentGameTime);
} }
} }
} }