diff --git a/FarmCaveSpawn/ModConfig.cs b/FarmCaveSpawn/ModConfig.cs index aa2073d..24654b0 100644 --- a/FarmCaveSpawn/ModConfig.cs +++ b/FarmCaveSpawn/ModConfig.cs @@ -1,5 +1,12 @@ namespace FarmCaveSpawn; +public enum SeasonalBehavior +{ + AllSeasons, + SeasonalOnly, + SeasonalExceptWinter, +} + #pragma warning disable SA1623 // Property summary documentation should match accessors #pragma warning disable SA1201 // Elements should appear in the correct order - fields are kept next to their accessors for this class. /// @@ -70,7 +77,7 @@ public float TreeFruitChance /// /// Should I limit myself to just fruits in season?. /// - public bool SeasonalOnly { get; set; } = false; + public SeasonalBehavior SeasonalOnly { get; set; } = SeasonalBehavior.AllSeasons; /// /// Should I allow any fruit tree product, even if it's not categorized as fruit. diff --git a/FarmCaveSpawn/ModEntry.cs b/FarmCaveSpawn/ModEntry.cs index 5e429ef..4db433f 100644 --- a/FarmCaveSpawn/ModEntry.cs +++ b/FarmCaveSpawn/ModEntry.cs @@ -147,6 +147,12 @@ private void SetUpConfig(object? sender, GameLaunchedEventArgs e) min: 0f, max: 100f); } + else if (property.PropertyType.Equals(typeof(SeasonalBehavior))) + { + helper.AddEnumOption( + property: property, + getConfig: () => this.config); + } else { this.Monitor.DebugLog($"{property.Name} unaccounted for.", LogLevel.Warn); @@ -310,7 +316,7 @@ private void SpawnFruit(object? sender, DayStartedEventArgs e) /// Tile to place fruit on. private void PlaceFruit(GameLocation location, Vector2 tile) { - int fruitToPlace = Utility.GetRandom(this.Random.NextDouble() < (this.config.TreeFruitChance / 100f) ? this.TreeFruit : this.BASE_FRUIT, this.Random); + int fruitToPlace = Utility.GetRandom(this.Random.NextDouble() < (this.config.TreeFruitChance / 100f) && this.TreeFruit.Count > 0 ? this.TreeFruit : this.BASE_FRUIT, this.Random); location.setObject(tile, new SObject(fruitToPlace, 1) { IsSpawnedObject = true, @@ -348,6 +354,7 @@ private IEnumerable IterateTiles(GameLocation location, int xstart = 1, /// /// Name of command. /// Arguments for command. + [SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Console command format.")] private void ListFruits(string command, string[] args) { if (!Context.IsWorldReady) @@ -406,13 +413,13 @@ private List GetTreeFruits() foreach (string tree in fruittrees.Values) { string[] treedata = tree.Split('/', StringSplitOptions.TrimEntries); - if (this.config.SeasonalOnly && Context.IsWorldReady) + + if ((this.config.SeasonalOnly == SeasonalBehavior.SeasonalOnly + || (this.config.SeasonalOnly == SeasonalBehavior.SeasonalExceptWinter && !currentseason.Contains("winter"))) + && !treedata[1].Contains(currentseason) + && (!currentseason.Contains("summer") || !treedata[1].Contains("island"))) { - if (!treedata[1].Contains(currentseason) - && (!currentseason.Contains("summer") || !treedata[1].Contains("island"))) - { - continue; - } + continue; } if (int.TryParse(treedata[2], out int objectIndex)) @@ -442,15 +449,7 @@ private List GetTreeFruits() } } } - if (treeFruits.Count > 0) - { - return treeFruits; - } - else - { - this.Monitor.Log($"All fruits were eliminated, defaulting to vanilla fruit list.", LogLevel.Info); - return this.VANILLA_FRUIT; - } + return treeFruits; } private void BellsAndWhistles(object? sender, OneSecondUpdateTickingEventArgs e) diff --git a/FarmCaveSpawn/docs/CHANGELOG.MD b/FarmCaveSpawn/docs/CHANGELOG.MD index 797acca..08f0350 100644 --- a/FarmCaveSpawn/docs/CHANGELOG.MD +++ b/FarmCaveSpawn/docs/CHANGELOG.MD @@ -9,6 +9,12 @@ * Figure out DGA fruit trees. +#### Version 1.0.9 + +* Fixes error items spawning in whenever no tree fruits are possible. +* Adds in a setting to exclude winter from Seasonal Only. +* Renames console command. + #### Version 1.0.8 * Corrects `UseModCave` option (would previously always use the additional locations list.) Adds new option to only use the six usual vanilla tree fruit. diff --git a/FarmCaveSpawn/i18n/default.json b/FarmCaveSpawn/i18n/default.json index 346b66f..2ead153 100644 --- a/FarmCaveSpawn/i18n/default.json +++ b/FarmCaveSpawn/i18n/default.json @@ -18,8 +18,8 @@ "UseMineCave.description": "Allows fruits to spawn in the mine entrance as well (after spawning in the Farm Cave, if Max Daily Spawns is not yet hit.", "UseVanillaFruitOnly.title": "Use Vanilla Fruit Only", "UseVanillaFruitOnly.description": "If true, will cause mod to only spawn the six vanilla tree fruit usually spawned in the fruit cave (and the four vanilla forage fruit).", - "SeasonalOnly.title": "Seasonal Fruit Only", - "SeasonalOnly.description": "Restrict to this season's fruit only", + "SeasonalOnly.title": "Seasonal Fruit", + "SeasonalOnly.description": "Allows restricting to the current season only. ", "AllowAnyTreeProduct.title": "Allow Any Tree Product", "AllowAnyTreeProduct.description": "If enabled, all products from fruit trees are allowed. If disabled, restricted to just fruit.", "EdiblesOnly.title": "Restrict to Edible", @@ -29,6 +29,9 @@ "PriceCap.title": "Price Cap", "PriceCap.description": "Removes fruit if their base price is above this.", + "config.SeasonalBehavior.AllSeasons": "Spawn from all seasons.", + "config.SeasonalBehavior.SeasonalOnly": "Current season only.", + "config.SeasonalBehavior.SeasonalExceptWinter" : "Current season, except in winter.", //Errors "ExcessRegexMatches": "Do not recognize pattern {{loc}}; skipping for now.", diff --git a/FarmCaveSpawn/manifest.json b/FarmCaveSpawn/manifest.json index 5cde558..b9604a2 100644 --- a/FarmCaveSpawn/manifest.json +++ b/FarmCaveSpawn/manifest.json @@ -2,7 +2,7 @@ "$schema": "https://smapi.io/schemas/manifest.json", "Name": "FarmCaveSpawn", "Author": "atravita", - "Version": "1.0.8", + "Version": "1.0.9", "Description": "Spawn more tree fruit in the fruit cave", "UniqueID": "atravita.FarmCaveSpawn", "EntryDll": "FarmCaveSpawn.dll",