Пример #1
0
 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));
 }
Пример #2
0
        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);
        }