public ModCompatResult LoadCrops(List <Crop> spring, List <Crop> summer, List <Crop> fall, List <Crop> winter, IModHelper helper) { try { DirectoryInfo baseCropFolder = new DirectoryInfo(BaseFolderName); List <string> addedCrops = new List <string>(); foreach (var folder in baseCropFolder.GetDirectories()) { foreach (var cropFile in folder.GetFiles()) { if (addedCrops.Contains(folder.Name)) { continue; } if (cropFile.Name == "crop.json") { ModCompatResult result = GetCrop(cropFile, helper, spring, summer, fall, winter); // If it was a success, just move on if (result != ModCompatResult.Success) { switch (result) { case ModCompatResult.BadFile: throw new Exception(); case ModCompatResult.DirectoryNotFound: throw new DirectoryNotFoundException(); case ModCompatResult.FileDoesNotExist: throw new FileNotFoundException(); default: break; } } } // Keep track of the ones we've added // for some reason it was adding them 3 times... addedCrops.Add(folder.Name); } } return(ModCompatResult.Success); } catch (DirectoryNotFoundException) { return(ModCompatResult.DirectoryNotFound); } catch (FileNotFoundException) { return(ModCompatResult.FileDoesNotExist); } catch (Exception) { return(ModCompatResult.BadFile); } }
public override void Entry(IModHelper helper) { MyHelper = helper; MyConfig = MyHelper.ReadConfig <ModConfig>(); if (MyConfig.IncludeBaseGameCrops) { SpringCrops = SetSpringCrops(); SummerCrops = SetSummerCrops(); FallCrops = SetFallCrops(); WinterCrops = new List <Crop>(); } else { SpringCrops = new List <Crop>(); SummerCrops = new List <Crop>(); FallCrops = new List <Crop>(); WinterCrops = new List <Crop>(); } List <ModCompat> modsToShow = new List <ModCompat>(); // Load Mods if (MyConfig.PPJAFruitsAndVeggiesPath != "") { this.Monitor.Log("Loading [PPJA] Fruits and Veggies", LogLevel.Info); ModCompat ppjaFruitsAndVeggies = new ModCompat("[PPJA] Fruits and Veggies", MyConfig.PPJAFruitsAndVeggiesPath + @"\[JA] Fruits and Veggies\Crops\"); modsToShow.Add(ppjaFruitsAndVeggies); } if (MyConfig.PPJAFantasyCropsPath != "") { this.Monitor.Log("Loading [PPJA] Fantasy Crops", LogLevel.Info); ModCompat ppjaFruitsAndVeggies = new ModCompat("[PPJA] Fantasy Crops", MyConfig.PPJAFantasyCropsPath + @"\[JA] Fantasy Crops\Crops\"); modsToShow.Add(ppjaFruitsAndVeggies); } if (MyConfig.PPJAAncientCropsPath != "") { this.Monitor.Log("Loading [PPJA] Ancient Crops", LogLevel.Info); ModCompat ppjaFruitsAndVeggies = new ModCompat("[PPJA] Ancient Crops", MyConfig.PPJAAncientCropsPath + @"\[JA] Ancient Crops\Crops\"); modsToShow.Add(ppjaFruitsAndVeggies); } if (MyConfig.PPJACannabisKitPath != "") { this.Monitor.Log("Loading [PPJA] Cannabis Kit", LogLevel.Info); ModCompat ppjaFruitsAndVeggies = new ModCompat("[PPJA] Cannabis Kit", MyConfig.PPJACannabisKitPath + @"\[JA] Cannabis Kit\Crops\"); modsToShow.Add(ppjaFruitsAndVeggies); } if (MyConfig.BonstersFruitAndVeggiesPath != "") { this.Monitor.Log("Loading Bonster's Fruit & Veggies", LogLevel.Info); ModCompat ppjaFruitsAndVeggies = new ModCompat("Bonster's Fruit & Veggies", MyConfig.BonstersFruitAndVeggiesPath + @"\Crops\"); modsToShow.Add(ppjaFruitsAndVeggies); } foreach (ModCompat mod in modsToShow) { ModCompatResult result = mod.LoadCrops(SpringCrops, SummerCrops, FallCrops, WinterCrops, MyHelper); if (result == ModCompatResult.Success) { continue; } this.Monitor.Log($"Unable to load {mod.Name}. Error Code: {result}", LogLevel.Error); } MyHelper.Events.GameLoop.DayStarted += GameLoop_DayStarted; }