2018-12-25 04:00:58 +08:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
2018-12-25 04:36:03 +08:00
|
|
|
using Microsoft.Xna.Framework;
|
2018-12-30 18:00:05 +08:00
|
|
|
using StardewValley;
|
2018-12-25 04:00:58 +08:00
|
|
|
|
|
|
|
namespace Revitalize.Framework.Environment
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Deals with making night time darker in Stardew.</summary>
|
2018-12-25 04:00:58 +08:00
|
|
|
public class DarkerNight
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Darkness intensity.</summary>
|
2018-12-25 04:00:58 +08:00
|
|
|
public static float IncrediblyDark = 0.9f;
|
2018-12-30 18:00:05 +08:00
|
|
|
|
|
|
|
/// <summary>Darkness intensity.</summary>
|
2018-12-25 04:00:58 +08:00
|
|
|
public static float VeryDark = 0.75f;
|
2018-12-30 18:00:05 +08:00
|
|
|
|
|
|
|
/// <summary>Darkness intensity.</summary>
|
2018-12-25 04:00:58 +08:00
|
|
|
public static float SomewhatDark = 0.50f;
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>The config file.</summary>
|
2018-12-25 04:00:58 +08:00
|
|
|
public static DarkerNightConfig Config;
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>The calculated night color.</summary>
|
2018-12-25 04:36:03 +08:00
|
|
|
private static Color CalculatedColor;
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Initializes the config for DarkerNight.</summary>
|
2018-12-25 04:00:58 +08:00
|
|
|
public static void InitializeConfig()
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
if (File.Exists(Path.Combine(ModCore.ModHelper.DirectoryPath, "Configs", "DarkerNightConfig.json")))
|
|
|
|
Config = ModCore.ModHelper.Data.ReadJsonFile<DarkerNightConfig>(Path.Combine("Configs", "DarkerNightConfig.json"));
|
2018-12-25 04:00:58 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Config = new DarkerNightConfig();
|
2018-12-30 18:00:05 +08:00
|
|
|
ModCore.ModHelper.Data.WriteJsonFile<DarkerNightConfig>(Path.Combine("Configs", "DarkerNightConfig.json"), Config);
|
2018-12-25 04:00:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Sets the color of darkness at night.</summary>
|
2018-12-25 04:36:03 +08:00
|
|
|
public static void SetDarkerColor()
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
if (!Config.Enabled || Game1.player?.currentLocation == null)
|
|
|
|
return;
|
|
|
|
|
2018-12-25 04:36:03 +08:00
|
|
|
if (Game1.player.currentLocation.IsOutdoors && Game1.timeOfDay >= Game1.getStartingToGetDarkTime())
|
|
|
|
Game1.outdoorLight = CalculatedColor;
|
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Calculates how dark it should be a night.</summary>
|
2018-12-25 04:36:03 +08:00
|
|
|
public static void CalculateDarkerNightColor()
|
2018-12-25 04:00:58 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
if (!Config.Enabled || Game1.player?.currentLocation == null)
|
|
|
|
return;
|
|
|
|
|
2018-12-25 04:36:03 +08:00
|
|
|
//Calculate original lighting.
|
|
|
|
if (Game1.timeOfDay >= Game1.getTrulyDarkTime())
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
float num = Math.Min(0.93f, (float)(0.75 + ((int)(Game1.timeOfDay - Game1.timeOfDay % 100 + Game1.timeOfDay % 100 / 10 * 16.6599998474121) - Game1.getTrulyDarkTime() + Game1.gameTimeInterval / 7000.0 * 16.6000003814697) * 0.000624999986030161));
|
2018-12-25 04:36:03 +08:00
|
|
|
Game1.outdoorLight = (Game1.isRaining ? Game1.ambientLight : Game1.eveningColor) * num;
|
|
|
|
}
|
|
|
|
else if (Game1.timeOfDay >= Game1.getStartingToGetDarkTime())
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
float num = Math.Min(0.93f, (float)(0.300000011920929 + ((int)(Game1.timeOfDay - Game1.timeOfDay % 100 + Game1.timeOfDay % 100 / 10 * 16.6599998474121) - Game1.getStartingToGetDarkTime() + Game1.gameTimeInterval / 7000.0 * 16.6000003814697) * 0.00224999990314245));
|
2018-12-25 04:36:03 +08:00
|
|
|
Game1.outdoorLight = (Game1.isRaining ? Game1.ambientLight : Game1.eveningColor) * num;
|
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
ModCore.log("OUT: " + Game1.outdoorLight);
|
2018-12-25 04:36:03 +08:00
|
|
|
|
|
|
|
int red = Game1.outdoorLight.R;
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
if (Game1.player.currentLocation.IsOutdoors && Game1.timeOfDay >= Game1.getStartingToGetDarkTime())
|
2018-12-25 04:00:58 +08:00
|
|
|
{
|
|
|
|
//Game1.ambientLight = Game1.ambientLight.GreyScaleAverage();
|
2018-12-30 18:00:05 +08:00
|
|
|
CalculatedColor = Game1.ambientLight * ((red + 30) / 255f) * Config.DarknessIntensity;
|
2018-12-25 04:00:58 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
ModCore.log("OUT: " + CalculatedColor);
|
|
|
|
ModCore.log("Ambient" + Game1.ambientLight);
|
2018-12-25 04:00:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|