예제 #1
0
        public static void DoLoad()
        {
            if (!Game1.IsMasterGame)
            {
                return;
            }

            ModEntry.Log("DeepWoodsSettings.DoLoad()", StardewModdingAPI.LogLevel.Trace);

            // load data
            DeepWoodsState = ModEntry.GetHelper().Data.ReadSaveData <DeepWoodsStateData>("data");
            if (DeepWoodsState == null)
            {
                // legacy file
                FileInfo legacyFile = new FileInfo($"{Constants.CurrentSavePath}/{SAVE_FILE_NAME}.json");
                ModEntry.Log("DeepWoodsSettings.DoLoad: Couldn't find savedata, trying legacy save: " + legacyFile.FullName, StardewModdingAPI.LogLevel.Trace);
                if (legacyFile.Exists)
                {
                    ModEntry.Log("DeepWoodsSettings.DoLoad: Loading legacy save.", StardewModdingAPI.LogLevel.Trace);
                    DeepWoodsState = JsonConvert.DeserializeObject <DeepWoodsStateData>(File.ReadAllText(legacyFile.FullName));
                }
            }
            if (DeepWoodsState == null)
            {
                ModEntry.Log("DeepWoodsSettings.DoLoad: No savedata, falling back to default.", StardewModdingAPI.LogLevel.Trace);
                DeepWoodsState = new DeepWoodsStateData();
            }

            // init settings
            ModEntry.Log("DeepWoodsSettings.DoLoad: Loading settings.", StardewModdingAPI.LogLevel.Trace);
            DeepWoodsSettings settings = ModEntry.GetHelper().ReadConfig <DeepWoodsSettings>();

            if (settings == null)
            {
                ModEntry.Log("Settings are null, using defaults.", StardewModdingAPI.LogLevel.Trace);
                Settings = new DeepWoodsSettings();
            }
            else
            {
                ModEntry.Log("Settings loaded successfully.", StardewModdingAPI.LogLevel.Trace);
                Settings = settings;

                if (Settings.WoodsPassage.AddBuildingTiles.Length == 0 &&
                    Settings.WoodsPassage.DeleteBuildingTiles.Length == 0 &&
                    Settings.WoodsPassage.WarpLocations.Length == 0)
                {
                    Settings.WoodsPassage = new WoodsPassageSettings();
                }
            }

            ModEntry.Log("DeepWoodsSettings.DoLoad: Done.", StardewModdingAPI.LogLevel.Trace);
        }
예제 #2
0
        public static void FixLighting()
        {
            if (Game1.currentLocation is DeepWoods || Game1.currentLocation is Woods)
            {
                int darkOutDelta = Game1.timeOfDay - Game1.getTrulyDarkTime();
                if (darkOutDelta > 0)
                {
                    double delta    = darkOutDelta / 100 + (darkOutDelta % 100 / 60.0) + ((Game1.gameTimeInterval / (double)Game1.realMilliSecondsPerGameTenMinutes) / 6.0);
                    double maxDelta = (2400 - Game1.getTrulyDarkTime()) / 100.0;

                    double ratio = Math.Min(1.0, delta / maxDelta);

                    if (ratio <= 0.0)
                    {
                        Game1.ambientLight = DAY_LIGHT;
                    }
                    else if (ratio >= 1.0)
                    {
                        Game1.ambientLight = NIGHT_LIGHT;
                    }
                    else
                    {
                        Color dayLightFactorized   = DAY_LIGHT * (float)(1.0 - ratio);
                        Color nightLightFactorized = NIGHT_LIGHT * (float)ratio;
                        Game1.ambientLight.R = (byte)Math.Min(255, dayLightFactorized.R + nightLightFactorized.R);
                        Game1.ambientLight.G = (byte)Math.Min(255, dayLightFactorized.G + nightLightFactorized.G);
                        Game1.ambientLight.B = (byte)Math.Min(255, dayLightFactorized.B + nightLightFactorized.B);
                        Game1.ambientLight.A = 255;
                    }
                }
                else
                {
                    Game1.ambientLight = DAY_LIGHT;
                }

                Game1.outdoorLight = Game1.ambientLight;
                DeepWoodsManager.isModifiedLighting = true;
            }
            else
            {
                if (DeepWoodsManager.isModifiedLighting &&
                    Game1.timeOfDay < Game1.getStartingToGetDarkTime() &&
                    !Game1.isRaining &&
                    !ModEntry.GetHelper().ModRegistry.IsLoaded("knakamura.dynamicnighttime"))
                {
                    Game1.outdoorLight = Color.White;
                }
                DeepWoodsManager.isModifiedLighting = false;
            }
        }
예제 #3
0
        public static void DoSave()
        {
            if (!Game1.IsMasterGame)
            {
                return;
            }

            // save data
            ModEntry.GetHelper().Data.WriteSaveData("data", DeepWoodsState);

            // remove legacy file
            FileInfo legacyFile = new FileInfo($"{Constants.CurrentSavePath}/{SAVE_FILE_NAME}.json");

            if (legacyFile.Exists)
            {
                legacyFile.Delete();
            }
        }