Exemplo n.º 1
0
        /// <summary>Tasks performed after the game begins a new day, including when loading a save.</summary>
        private void DayStarted(object sender, EventArgs e)
        {
            if (Context.IsMainPlayer != true)
            {
                return;
            }                                             //if the player using this mod is a multiplayer farmhand, don't do anything; most of this mod's functions should be limited to the host player

            try
            {
                Utility.Config = Helper.Data.ReadJsonFile <FarmConfig>($"data/{Constants.SaveFolderName}.json"); //load the current save's config file ([null] if it doesn't exist)
            }
            catch (Exception ex)                                                                                 //if there's an error while loading the json file, try to explain it in the user's log & then skip any further DayStarted behaviors
            {
                Utility.Monitor.Log($"Warning: Your character's config file could not be parsed correctly. Most of this mod's functions will be disabled. Please edit the file, or delete it and reload your save to generate a new config file. The original error message is displayed below.", LogLevel.Warn);
                Utility.Monitor.Log($"{ex.Message}", LogLevel.Warn);
                return;
            }

            if (Utility.Config == null)                                                             //no config file for this save?
            {
                Utility.Config = new FarmConfig();                                                  //load the default config settings
                Helper.Data.WriteJsonFile($"data/{Constants.SaveFolderName}.json", Utility.Config); //create a config file for the current save
            }

            //run the methods providing the mod's main features
            ObjectSpawner.ForageGeneration();
            ObjectSpawner.LargeObjectGeneration();
            ObjectSpawner.OreGeneration();

            //NOTE: This will reformat any changes the player has made with the default SMAPI formatting
            Helper.Data.WriteJsonFile($"data/{Constants.SaveFolderName}.json", Utility.Config);
        }
Exemplo n.º 2
0
        /// <summary>Tasks performed after the game begins a new day, including when loading a save.</summary>
        private void DayStarted(object sender, EventArgs e)
        {
            //attempt to load the config.json ModConfig file and update its settings
            //NOTE: this already happens in the Entry method, but doing it here allows certain settings to be changed while the game is running
            try
            {
                Utility.MConfig = Helper.ReadConfig <ModConfig>(); //create or load the config.json file

                Helper.WriteConfig <ModConfig>(Utility.MConfig);   //update the config.json file (e.g. to add settings from new versions of the mod)
            }
            catch (Exception ex)                                   //if the config.json file can't be parsed correctly, try to explain it in the user's log & then skip any config-related behaviors
            {
                Utility.Monitor.Log($"Warning: This mod's config.json file could not be parsed correctly. Some related settings will be disabled. Please edit the file, or delete it and reload the game to generate a new config file. The auto-generated error message is displayed below:", LogLevel.Warn);
                Utility.Monitor.Log($"----------", LogLevel.Warn); //visual break to slightly improve clarity, based on user feedback
                Utility.Monitor.Log($"{ex.Message}", LogLevel.Warn);
            }

            if (Context.IsMainPlayer != true)
            {
                return;
            }                                                       //if the player using this mod is a multiplayer farmhand, don't do anything; most of this mod's functions should be limited to the host player

            Utility.LoadFarmData(Helper);                           //load all available data files

            foreach (FarmData data in Utility.FarmDataList)         //for each loaded set of data
            {
                Utility.ReplaceProtectedSpawnsOvernight(data.Save); //protect unexpired spawns listed in the save data
            }

            //run the methods providing the mod's main features
            ObjectSpawner.ForageGeneration();
            ObjectSpawner.LargeObjectGeneration();
            ObjectSpawner.OreGeneration();
        }
Exemplo n.º 3
0
        /// <summary>Tasks performed after the game begins a new day, including when loading a save.</summary>
        private void DayStarted(object sender, EventArgs e)
        {
            if (Context.IsMainPlayer != true)
            {
                return;
            }                      //if the player using this mod is a multiplayer farmhand, don't do anything; most of this mod's functions should be limited to the host player

            Utility.Config = null; //avoid any errors elsewhere in the loading process
            try
            {
                Utility.Config = Helper.Data.ReadJsonFile <FarmConfig>($"data/{Constants.SaveFolderName}.json"); //load the current save's config file (null if it doesn't exist)
            }
            catch (Exception ex)                                                                                 //if there's an error while loading the json file, try to explain it in the user's log & then skip any further DayStarted behaviors
            {
                Utility.Monitor.Log($"Warning: Your character's config file ({Constants.SaveFolderName}.json) could not be parsed correctly. Most of this mod's features will be disabled. Please edit the file, or delete it and reload your save to generate a new config file. The auto-generated error message is displayed below.", LogLevel.Warn);
                Utility.Monitor.Log($"----------", LogLevel.Warn); //visual break to slightly improve clarity, based on user feedback
                Utility.Monitor.Log($"{ex.Message}", LogLevel.Warn);
                return;
            }

            if (Utility.Config == null) //no config file for this save
            {
                //attempt to load the default.json config file
                try
                {
                    Utility.Config = Helper.Data.ReadJsonFile <FarmConfig>($"data/default.json"); //load the default.json config file (null if it doesn't exist)
                }
                catch (Exception ex)                                                              //if there's an error while loading the json file, try to explain it in the user's log & then skip any further DayStarted behaviors
                {
                    Utility.Monitor.Log($"Warning: Your default config file (default.json) could not be parsed correctly, and your character doesn't have their own config file yet. Most of this mod's features will be disabled. Please edit the file, or delete it and reload your save to generate a new config file. The auto-generated error message is displayed below.", LogLevel.Warn);
                    Utility.Monitor.Log($"----------", LogLevel.Warn); //visual break to slightly improve clarity, based on user feedback
                    Utility.Monitor.Log($"{ex.Message}", LogLevel.Warn);
                    return;
                }

                if (Utility.Config == null)            //no default.json config file
                {
                    Utility.Config = new FarmConfig(); //load the (built-in) default config settings
                }

                Helper.Data.WriteJsonFile($"data/default.json", Utility.Config); //create or update the default.json config file
            }

            Helper.Data.WriteJsonFile($"data/{Constants.SaveFolderName}.json", Utility.Config); //create or update the config file for the current save

            //run the methods providing the mod's main features
            ObjectSpawner.ForageGeneration();
            ObjectSpawner.LargeObjectGeneration();
            ObjectSpawner.OreGeneration();
        }