Exemplo n.º 1
0
 public static void HandleV2(
     ModEntry mod,
     Config.V2.ModConfig deprecatedConfig,
     string targetFormat,
     out ModConfig config)
 {
     config = new ModConfig
     {
         Format    = targetFormat,
         IsEnabled = deprecatedConfig.IsEnabled
     };
     CreateContentPack(mod, deprecatedConfig);
 }
Exemplo n.º 2
0
        public static bool CreateContentPack(ModEntry mod, Config.V2.ModConfig deprecatedConfig)
        {
            var str1        = FarmAnimal.VoidChicken.ToString();
            var content1    = new Content(new List <Category>());
            var stringList1 = new List <string>();

            if (deprecatedConfig.FarmAnimals == null)
            {
                return(false);
            }
            foreach (var farmAnimal in deprecatedConfig.FarmAnimals)
            {
                var             action          = FarmAnimals.IsVanillaCategory(farmAnimal.Key) ? Category.Actions.Update : Category.Actions.Create;
                FarmAnimalStock farmAnimalStock = null;
                var             flag1           = true;
                var             flag2           = false;
                if (farmAnimal.Value.CanBePurchased())
                {
                    int.TryParse(farmAnimal.Value.AnimalShop.Price, out var _);
                    var stringList2 = new List <string>();
                    if (!deprecatedConfig.IsChickenCategory(farmAnimal.Key) || farmAnimal.Value.Types.Contains(str1) &&
                        deprecatedConfig.AreVoidFarmAnimalsInShopAlways())
                    {
                        stringList2.Add(str1);
                    }
                    var path2 = farmAnimal.Value.AnimalShop.Icon;
                    if (File.Exists(Path.Combine(ModEntry.Instance.Helper.DirectoryPath, path2)))
                    {
                        stringList1.Add(path2);
                    }
                    else
                    {
                        path2 = null;
                    }
                    farmAnimalStock = new FarmAnimalStock
                    {
                        Name        = farmAnimal.Value.AnimalShop.Name,
                        Description = farmAnimal.Value.AnimalShop.Description,
                        Icon        = path2,
                        Exclude     = stringList2
                    };
                    flag1 = false;
                    flag2 = true;
                }

                var category1 = new Category(action);
                category1.Category               = farmAnimal.Key;
                category1.Types                  = farmAnimal.Value.Types.Select(str => new FarmAnimalType(str, 0.0)).ToList();
                category1.Buildings              = farmAnimal.Value.Buildings.ToList();
                category1.AnimalShop             = farmAnimalStock;
                category1.ForceOverrideTypes     = true;
                category1.ForceOverrideBuildings = true;
                category1.ForceRemoveFromShop    = flag1;
                category1.ForceOverrideExclude   = flag2;
                var category2 = category1;
                content1.Categories.Add(category2);
            }

            if (!content1.Categories.Any())
            {
                return(false);
            }
            var migrationFullPath = ContentPack.ConfigMigrationFullPath;
            var id = Guid.NewGuid().ToString("N");

            new DirectoryInfo(migrationFullPath).Create();
            var path               = Path.Combine(migrationFullPath, "content.json");
            var content2           = content1;
            var serializerSettings = new JsonSerializerSettings();

            serializerSettings.NullValueHandling = NullValueHandling.Ignore;
            var contents = JsonConvert.SerializeObject(content2, (Formatting)1, serializerSettings);
            var jobject  = JObject.FromObject(new
            {
                Name           = ContentPack.ConfigMigrationName,
                Author         = "Anonymous",
                Version        = "1.0.0",
                Description    = "Your custom content pack for BFAV",
                UniqueID       = id,
                ContentPackFor = new
                {
                    UniqueID = "Paritee.BetterFarmAnimalVariety"
                }
            });

            File.WriteAllText(Path.Combine(migrationFullPath, "manifest.json"),
                              JsonConvert.SerializeObject(jobject, (Formatting)1));
            File.WriteAllText(path, contents);
            foreach (var path2 in stringList1)
            {
                var str2 = Path.Combine(migrationFullPath, path2);
                new FileInfo(str2).Directory.Create();
                File.Copy(Path.Combine(ModEntry.Instance.Helper.DirectoryPath, path2), str2);
            }

            LoadContentPacks.SetUpContentPacks(new List <IContentPack>
            {
                mod.Helper.ContentPacks.CreateTemporary(migrationFullPath, id, ContentPack.ConfigMigrationName,
                                                        "Your custom content pack for BFAV", "Anonymous", new SemanticVersion("1.0.0"))
            }, mod.Monitor);
            return(true);
        }