Exemple #1
0
        /// <summary>Invoked when the player loads a save.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event data.</param>
        /// <remarks>Used for generating the config and loading the valid seeds.</remarks>
        private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
        {
            // get all Json Assets packs that add crops (this needs to be done through the SMAPI mod registry and reflection as the JA API doesn't expose this in it's API)
            var jaModData = this.Helper.ModRegistry.Get("SpaceChase0.JsonAssets");

            if (jaModData != null)
            {
                // get all required Json Assets data
                this.Monitor.Log("Json Assets instance found, retrieving crop mods...");
                var jaInstance = (Mod)jaModData.GetType().GetProperty("Mod", BindingFlags.Public | BindingFlags.Instance).GetValue(jaModData);
                JASeeds = GetJASeeds(jaInstance);
            }

            // clean config (remove old seeds, add new ones)
            CleanConfig();

            // save config
            this.Helper.WriteConfig(Config);

            // get the enabled seeds
            Seeds = GetAllEnabledSeeds();

            // remove any seeds that mods have foricbly excluded
            for (int i = 0; i < Seeds.Count; i++)
            {
                var seed = Seeds[i];
                if (CropsToExclude.Any(cropToExclude => cropToExclude.ToLower() == seed.CropName.ToLower()))
                {
                    this.Monitor.Log($"Forcibly removed seed: {seed}");
                    Seeds.RemoveAt(i--);
                }
            }

            // log current seeds
            foreach (var seed in Seeds)
            {
                this.Monitor.Log($"Added seed: {seed}");
            }

            // add harmony patches
            ApplyHarmonyPatches();
        }