/// <summary>Add at least one animal type to a category when the 'bfav_fa_addtypes' command is invoked.</summary> /// <param name="command">The name of the command invoked.</param> /// <param name="args">The arguments received by the command. Each word after the command name is a separate argument.</param>ary> private void AddTypes(string command, string[] args) { if (Game1.hasLoadedGame) { this.Monitor.Log($"this cannot be done after loading a save"); return; } if (args.Length > 2) { this.Monitor.Log($"use quotation marks (\") around your text if you are using spaces", LogLevel.Error); return; } if (args.Length < 1) { this.Monitor.Log($"category is required", LogLevel.Error); return; } string category = args[0].Trim(); if (!this.Config.FarmAnimals.ContainsKey(category)) { this.Monitor.Log($"{category} is not a category in config.json", LogLevel.Error); return; } if (args.Length < 2) { this.Monitor.Log($"type is required", LogLevel.Error); return; } List <string> types = new List <string>(this.Config.FarmAnimals[category].Types); List <string> newTypes = args[1].Split(',').Select(i => i.Trim()).ToList(); FarmAnimalsData farmAnimalsData = new FarmAnimalsData(); // Check if these new types are valid foreach (string newType in newTypes) { if (!farmAnimalsData.Exists(newType)) { this.Monitor.Log($"{newType} does not exist in Data/FarmAnimals", LogLevel.Error); return; } } this.Config.FarmAnimals[category].Types = types.Concat(newTypes).Distinct().ToArray(); this.HandleUpdatedConfig(); string output = this.DescribeFarmAnimalCategory(new KeyValuePair <string, ConfigFarmAnimal>(category, this.Config.FarmAnimals[category])); this.Monitor.Log(output, LogLevel.Info); }
/// <summary>Add a unique category when the 'bfav_fa_addcategory' command is invoked.</summary> /// <param name="command">The name of the command invoked.</param> /// <param name="args">The arguments received by the command. Each word after the command name is a separate argument.</param> private void AddCategory(string command, string[] args) { if (Game1.hasLoadedGame) { this.Monitor.Log($"this cannot be done after loading a save"); return; } if (args.Length > 4) { this.Monitor.Log($"use quotation marks (\") around your text if you are using spaces", LogLevel.Error); return; } if (args.Length < 1) { this.Monitor.Log($"category is required", LogLevel.Error); return; } string category = args[0].Trim(); if (this.Config.FarmAnimals.ContainsKey(category)) { this.Monitor.Log($"{category} already exists in config.json", LogLevel.Error); return; } if (args.Length < 2) { this.Monitor.Log($"type is required", LogLevel.Error); return; } List <string> types = args[1].Split(',').Select(i => i.Trim()).ToList(); FarmAnimalsData farmAnimalsData = new FarmAnimalsData(); // Check if these new types are valid foreach (string key in types) { if (!farmAnimalsData.Exists(key)) { this.Monitor.Log($"{key} does not exist in Data/FarmAnimals", LogLevel.Error); return; } } string building = args.Length < 3 ? Barn.BARN : args[2].Trim(); List <string> buildings = new List <string>(); if (building.ToLower().Equals(Coop.COOP.ToLower())) { foreach (PariteeAnimalHouse.Size size in Enum.GetValues(typeof(Coop.Size))) { buildings.Add(PariteeAnimalHouse.FormatBuilding(Coop.COOP, size)); } } else if (building.ToLower().Equals(Barn.BARN.ToLower())) { foreach (PariteeAnimalHouse.Size size in Enum.GetValues(typeof(Barn.Size))) { buildings.Add(PariteeAnimalHouse.FormatBuilding(Barn.BARN, size)); } } else { buildings = building.Split(',').Select(i => i.Trim()).ToList(); BlueprintsData blueprintsData = new BlueprintsData(); // Check if these new types are valid foreach (string key in buildings) { if (!blueprintsData.Exists(key)) { this.Monitor.Log($"{key} does not exist in Data/Blueprints", LogLevel.Error); return; } } } string animalShop = args.Length < 4 ? FarmAnimalsCommands.ANIMAL_SHOP_UNAVAILABLE : args[3].Trim().ToLower(); if (!animalShop.Equals(FarmAnimalsCommands.ANIMAL_SHOP_AVAILABLE) && !animalShop.Equals(FarmAnimalsCommands.ANIMAL_SHOP_UNAVAILABLE)) { this.Monitor.Log($"animalshop must be yes or no", LogLevel.Error); return; } ConfigFarmAnimalAnimalShop configFarmAnimalAnimalShop; try { configFarmAnimalAnimalShop = this.GetAnimalShopConfig(category, animalShop); } catch { // Messaging handled in function return; } this.Config.FarmAnimals.Add(category, new ConfigFarmAnimal()); this.Config.FarmAnimals[category].Category = category; this.Config.FarmAnimals[category].Types = types.Distinct().ToArray(); this.Config.FarmAnimals[category].Buildings = buildings.ToArray(); this.Config.FarmAnimals[category].AnimalShop = configFarmAnimalAnimalShop; this.HandleUpdatedConfig(); string output = this.DescribeFarmAnimalCategory(new KeyValuePair <string, ConfigFarmAnimal>(category, this.Config.FarmAnimals[category])); this.Monitor.Log(output, LogLevel.Info); }