Exemple #1
0
        /*********
        ** Private methods
        *********/
        private void SaveEvents_AfterLoad(object sender, EventArgs e)
        {
            this.Config = this.Helper.ReadConfig <ModConfig>();

            this.PlowEnabled    = this.Config.PlowEnabled;
            this.PlantEnabled   = this.Config.PlantEnabled;
            this.GrowEnabled    = this.Config.GrowEnabled;
            this.HarvestEnabled = this.Config.HarvestEnabled;

            this.PlantRadius   = this.Config.PlantRadius;
            this.GrowRadius    = this.Config.GrowRadius;
            this.HarvestRadius = this.Config.HarvestRadius;

            this.PlowWidth  = this.Config.PlowWidth;
            this.PlowHeight = this.Config.PlowHeight;

            this.Fertilizer = this.Config.Fertilizer;

            this.LoggingEnabled = this.Config.LoggingEnabled;

            if (this.Config.PlowWidth < 1)
            {
                this.PlowWidth = 1;
                if (this.PlowEnabled)
                {
                    this.Monitor.Log("Plow width must be at least 1. Defaulted to 1");
                }
            }
            else
            {
                this.PlowWidth = this.Config.PlowWidth;
            }

            if (this.Config.PlowHeight < 1)
            {
                this.PlowHeight = 1;
                if (this.PlowEnabled)
                {
                    this.Monitor.Log("Plow height must be at least 1. Defaulted to 1");
                }
            }
            else
            {
                this.PlowHeight = this.Config.PlowHeight;
            }

            if (this.Config.PlantRadius < 0)
            {
                this.PlantRadius = 0;
                if (this.Config.PlantEnabled)
                {
                    this.Monitor.Log("Plant Radius must be 0 or greater.  Defaulted to 0");
                }
            }
            else
            {
                this.PlantRadius = this.Config.PlantRadius;
            }

            if (this.Config.GrowRadius < 0)
            {
                this.GrowRadius = 0;
                if (this.Config.GrowEnabled)
                {
                    this.Monitor.Log("Grow Radius must be 0 or greater.  Defaulted to 0");
                }
            }
            else
            {
                this.GrowRadius = this.Config.GrowRadius;
            }

            if (this.Config.HarvestRadius < 0)
            {
                this.HarvestRadius = 0;
                if (this.Config.PlantEnabled)
                {
                    this.Monitor.Log("Harvest Radius must be 0 or greater.  Defaulted to 0");
                }
            }
            else
            {
                this.HarvestRadius = this.Config.HarvestRadius;
            }

            if (!Enum.TryParse(this.Config.PlowKey, true, out this.PlowKey))
            {
                this.PlowKey = Keys.Z;
                if (this.PlowEnabled)
                {
                    this.Monitor.Log("Error parsing plow key. Defaulted to Z");
                }
            }

            if (!Enum.TryParse(this.Config.PlantKey, true, out this.PlantKey))
            {
                this.PlantKey = Keys.A;
                if (this.PlantEnabled)
                {
                    this.Monitor.Log("Error parsing plant key. Defaulted to A");
                }
            }

            if (!Enum.TryParse(this.Config.GrowKey, true, out this.GrowKey))
            {
                this.GrowKey = Keys.S;
                if (this.GrowEnabled)
                {
                    this.Monitor.Log("Error parsing grow key. Defaulted to S");
                }
            }

            if (!Enum.TryParse(this.Config.HarvestKey, true, out this.HarvestKey))
            {
                this.HarvestKey = Keys.D;
                if (this.HarvestEnabled)
                {
                    this.Monitor.Log("Error parsing harvest key. Defaulted to D");
                }
            }

            this.GrassKey     = Keys.Q;
            this.CustomSickle = new ModSickle(47, this.Config.HarvestRadius, this.Vector);
            this.CustomHoe    = new Hoe {
                UpgradeLevel = this.ToolLevel
            };
        }
        /*********
        ** Private methods
        *********/
        /// <summary>Raised after the player loads a save slot.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
        {
            this.Config = this.Helper.ReadConfig <ModConfig>();

            this.PlowEnabled    = this.Config.PlowEnabled;
            this.PlantEnabled   = this.Config.PlantEnabled;
            this.GrowEnabled    = this.Config.GrowEnabled;
            this.HarvestEnabled = this.Config.HarvestEnabled;

            this.PlantRadius   = this.Config.PlantRadius;
            this.GrowRadius    = this.Config.GrowRadius;
            this.HarvestRadius = this.Config.HarvestRadius;

            this.PlowWidth  = this.Config.PlowWidth;
            this.PlowHeight = this.Config.PlowHeight;

            this.Fertilizer = this.Config.Fertilizer;

            this.LoggingEnabled = this.Config.LoggingEnabled;

            if (this.Config.PlowWidth < 1)
            {
                this.PlowWidth = 1;
                if (this.PlowEnabled)
                {
                    this.Monitor.Log($"Plow width must be at least 1; defaulted to {this.PlowWidth}.");
                }
            }
            else
            {
                this.PlowWidth = this.Config.PlowWidth;
            }

            if (this.Config.PlowHeight < 1)
            {
                this.PlowHeight = 1;
                if (this.PlowEnabled)
                {
                    this.Monitor.Log($"Plow height must be at least 1; defaulted to {this.PlowHeight}.");
                }
            }
            else
            {
                this.PlowHeight = this.Config.PlowHeight;
            }

            if (this.Config.PlantRadius < 0)
            {
                this.PlantRadius = 0;
                if (this.Config.PlantEnabled)
                {
                    this.Monitor.Log($"Plant Radius must be 0 or greater; defaulted to {this.PlantRadius}.");
                }
            }
            else
            {
                this.PlantRadius = this.Config.PlantRadius;
            }

            if (this.Config.GrowRadius < 0)
            {
                this.GrowRadius = 0;
                if (this.Config.GrowEnabled)
                {
                    this.Monitor.Log($"Grow Radius must be 0 or greater; defaulted to {this.GrowRadius}.");
                }
            }
            else
            {
                this.GrowRadius = this.Config.GrowRadius;
            }

            if (this.Config.HarvestRadius < 0)
            {
                this.HarvestRadius = 0;
                if (this.Config.PlantEnabled)
                {
                    this.Monitor.Log($"Harvest Radius must be 0 or greater; defaulted to {this.HarvestRadius}.");
                }
            }
            else
            {
                this.HarvestRadius = this.Config.HarvestRadius;
            }

            if (!Enum.TryParse(this.Config.PlowKey, true, out this.PlowKey))
            {
                this.PlowKey = SButton.Z;
                if (this.PlowEnabled)
                {
                    this.Monitor.Log($"Error parsing plow key; defaulted to {this.PlowKey}.");
                }
            }

            if (!Enum.TryParse(this.Config.PlantKey, true, out this.PlantKey))
            {
                this.PlantKey = SButton.A;
                if (this.PlantEnabled)
                {
                    this.Monitor.Log($"Error parsing plant key; defaulted to {this.PlantKey}.");
                }
            }

            if (!Enum.TryParse(this.Config.GrowKey, true, out this.GrowKey))
            {
                this.GrowKey = SButton.S;
                if (this.GrowEnabled)
                {
                    this.Monitor.Log($"Error parsing grow key; defaulted to {this.GrowKey}.");
                }
            }

            if (!Enum.TryParse(this.Config.HarvestKey, true, out this.HarvestKey))
            {
                this.HarvestKey = SButton.D;
                if (this.HarvestEnabled)
                {
                    this.Monitor.Log($"Error parsing harvest key; defaulted to {this.HarvestKey}.");
                }
            }

            this.GrassKey     = SButton.Q;
            this.CustomSickle = new ModSickle(47, this.Config.HarvestRadius, this.Vector);
            this.CustomHoe    = new Hoe {
                UpgradeLevel = this.ToolLevel
            };
        }