Skip to content

Commit

Permalink
DNT bug fixing and comaptiblity with SMAPI 3. Some x86 cpu changes th…
Browse files Browse the repository at this point in the history
…at apparently never take
  • Loading branch information
Sakorona committed Dec 28, 2018
1 parent b550f47 commit db35acd
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 44 deletions.
1 change: 1 addition & 0 deletions CustomizableClock/CustomizableClock.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down
83 changes: 50 additions & 33 deletions DynamicNightTime/DynamicNightTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ILunarDisturbancesAPI>(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)
{
Expand All @@ -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<ILunarDisturbancesAPI>(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]);
}
}

Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions DynamicNightTime/DynamicNightTime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down
30 changes: 21 additions & 9 deletions DynamicNightTime/Patches/GameClockPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions DynamicNightTime/manifest.json
Original file line number Diff line number Diff line change
@@ -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" ]
}
1 change: 1 addition & 0 deletions SummitReborn/SummitReborn.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down

0 comments on commit db35acd

Please sign in to comment.