public static void UniqueFarmAnimalCategory(string category) { if (FarmAnimals.ReadCache().CategoryExists(category)) { throw new ArgumentException("\"" + category + "\" category already exists"); } }
public static void FarmAnimalCanBePurchased(string category) { if (!FarmAnimals.CanBePurchased(category)) { throw new NotImplementedException("\"" + category + "\" is not available in the animal shop"); } }
public static void FarmAnimalCategoryExists(string category) { if (!FarmAnimals.CategoryExists(category)) { throw new NotImplementedException(category + " category does not exist"); } }
public void HandleCreateAction(IContentPack contentPack, Category category) { Assert.UniqueFarmAnimalCategory(category.Category); Assert.UniqueValues(category.Types.Select(o => o.Type).ToList()); category.Types = category.Types.Select(o => CastSpritesToFullPaths(o, contentPack.DirectoryPath)).ToList(); if (category.CanBePurchased()) { category.AnimalShop.Icon = Path.Combine(contentPack.DirectoryPath, ModEntry.Instance.Helper.Content.NormalizeAssetName(category.AnimalShop.Icon)); } FarmAnimals.AddOrReplaceCategory(new FarmAnimalCategory(category)); }
public void Edit <T>(IAssetData asset) { if (!asset.AssetNameEquals(Content.DataFarmAnimalsContentPath)) { return; } var data = asset.AsDictionary <string, string>().Data; var locale = asset.Locale.Split('-')[0]; foreach (var farmAnimalType in FarmAnimals.GetCategories().SelectMany(o => (IEnumerable <FarmAnimalType>)o.Types)) { if (farmAnimalType.Data != null) { data[farmAnimalType.Type] = farmAnimalType.LocalizeData(locale); data[farmAnimalType.Type] = SanitizeData(farmAnimalType.Data); } } Monitor.Log("Data/FarmAnimals:\n" + string.Join("\n", data.Select(o => o.Key + ": " + o.Value))); }
public void HandleRemoveAction(IContentPack contentPack, Category category) { Assert.FarmAnimalCategoryExists(category.Category); FarmAnimals.RemoveCategory(category.Category); }
public void HandleUpdateAction(IContentPack contentPack, Category category) { var category1 = FarmAnimals.GetCategory(category.Category) ?? new FarmAnimalCategory(category); if (category.Types != null) { var list = category.Types.Select(o => CastSpritesToFullPaths(o, contentPack.DirectoryPath)).ToList(); if (category.ForceOverrideTypes) { category1.Types = list; } else { foreach (var farmAnimalType1 in list) { var type = farmAnimalType1; if (category1.Types.FirstOrDefault(o => o.Type == type.Type) != null) { var farmAnimalType2 = type; } else { category1.Types.Add(type); } } } } if (category.Buildings != null) { category1.Buildings = category.ForceOverrideBuildings ? category.Buildings : category1.Buildings.Union(category.Buildings).ToList(); } if (category.ForceRemoveFromShop) { category1.AnimalShop = null; } else if (category.AnimalShop != null) { if (!category1.CanBePurchased()) { category1.AnimalShop = new FarmAnimalStock(); } if (category.AnimalShop.Name != null) { category1.AnimalShop.Name = category.AnimalShop.Name; } if (category.AnimalShop.Description != null) { category1.AnimalShop.Description = category.AnimalShop.Description; } if (category.AnimalShop.Icon != null) { category1.AnimalShop.Icon = Path.Combine(contentPack.DirectoryPath, ModEntry.Instance.Helper.Content.NormalizeAssetName(category.AnimalShop.Icon)); } if (category.AnimalShop.Exclude != null) { category1.AnimalShop.Exclude = category.ForceOverrideExclude || category1.AnimalShop.Exclude == null ? category.AnimalShop.Exclude : category1.AnimalShop.Exclude.Union(category.AnimalShop.Exclude).ToList(); } } FarmAnimals.AddOrReplaceCategory(category1); }