public static ExtraCropInformation ParseString(string input) { ExtraCropInformation extraCropInfo = new ExtraCropInformation(); string[] extraCropParts = input.Split(' '); if (bool.TryParse(extraCropParts[0], out bool boolValue)) { extraCropInfo.CanGetExtraCrops = boolValue; } else { Globals.ConsoleError($"Tried to parse {extraCropParts[0]} into a boolean for extra crop info while parsing: {input}"); return(null); } if (extraCropInfo.CanGetExtraCrops) { int intValue; if (int.TryParse(extraCropParts[1], out intValue)) { extraCropInfo.MinExtra = intValue; } else { Globals.ConsoleError($"Tried to parse {extraCropParts[1]} into the minimum extra crops while parsing: {input}"); return(null); } if (int.TryParse(extraCropParts[2], out intValue)) { extraCropInfo.MaxExtra = intValue; } else { Globals.ConsoleError($"Tried to parse {extraCropParts[2]} into the maximum extra crops while parsing: {input}"); return(null); } if (int.TryParse(extraCropParts[3], out intValue)) { extraCropInfo.AdditionalExtraPerFramingLevel = intValue; } else { Globals.ConsoleError($"Tried to parse {extraCropParts[3]} into the additional extra per farming level while parsing: {input}"); return(null); } if (double.TryParse(extraCropParts[4], out double value)) { extraCropInfo.ChanceOfExtra = value; } else { Globals.ConsoleError($"Tried to parse {extraCropParts[4]} into the chance of extra crops while parsing: {input}"); return(null); } } return(extraCropInfo); }
/// <summary> /// Parses a string from the Crops data file into a CropGrowthInformation object /// </summary> /// <param name="input"></param> /// <returns></returns> public static CropGrowthInformation ParseString(string input) { CropGrowthInformation cropGrowthInfo = new CropGrowthInformation(); int result; string[] fields = input.Split('/'); if (fields.Length != 9) { Globals.ConsoleError($"Invalid string passed when parsing crop info: {input}"); return(null); } // Growth stages string[] growthStages = fields[(int)CropGrowthFields.GrowthStages].Split(' '); foreach (string growthStage in growthStages) { if (int.TryParse(growthStage, out result)) { cropGrowthInfo.GrowthStages.Add(result); } else { Globals.ConsoleError($"Tried to parse {growthStage} into a growth stage when parsing: {input}"); return(null); } } // Seasons string[] seasonStrings = fields[(int)CropGrowthFields.Seasons].Split(' '); foreach (string seasonString in seasonStrings) { switch (seasonString.ToLower()) { case "spring": cropGrowthInfo.GrowingSeasons.Add(Seasons.Spring); break; case "summer": cropGrowthInfo.GrowingSeasons.Add(Seasons.Summer); break; case "fall": cropGrowthInfo.GrowingSeasons.Add(Seasons.Fall); break; case "winter": cropGrowthInfo.GrowingSeasons.Add(Seasons.Winter); break; default: Globals.ConsoleError($"Tries to parse {seasonString} into a season when parsing: {input}"); return(null); } } // Graphic id string graphicId = fields[(int)CropGrowthFields.GraphicId]; if (int.TryParse(graphicId, out result)) { cropGrowthInfo.GraphicId = result; } else { Globals.ConsoleError($"Tried to parse {result} into a graphic id when parsing: {input}"); return(null); } // Crop Id string cropId = fields[(int)CropGrowthFields.CropId]; if (int.TryParse(cropId, out result)) { cropGrowthInfo.CropId = result; } else { Globals.ConsoleError($"Tried to parse {result} into a crop id when parsing: {input}"); return(null); } // Amount per harvest string daysToRegrow = fields[(int)CropGrowthFields.DaysToRegrow]; if (int.TryParse(daysToRegrow, out result)) { cropGrowthInfo.DaysToRegrow = result; } else { Globals.ConsoleError($"Tried to parse {result} into the amount per harvest when parsing: {input}"); return(null); } // Can scythe string canScythe = fields[(int)CropGrowthFields.CanScythe]; if (int.TryParse(canScythe, out result)) { cropGrowthInfo.CanScythe = result == 1; } else { Globals.ConsoleError($"Tried to parse {result} into the CanScythe flag id when parsing: {input}"); return(null); } // Extra crop info string extraCropInfoString = fields[(int)CropGrowthFields.ExtraCropInfo]; cropGrowthInfo.ExtraCropInfo = ExtraCropInformation.ParseString(extraCropInfoString); if (cropGrowthInfo.ExtraCropInfo == null) { return(null); } // Is trellis crop string isTrellisCropString = fields[(int)CropGrowthFields.IsTrellisCrop]; if (bool.TryParse(isTrellisCropString, out bool boolResult)) { cropGrowthInfo.IsTrellisCrop = boolResult; } else { Globals.ConsoleError($"Tried to parse {isTrellisCropString} into the isTrellisCrop boolean when parsing: {input}"); return(null); } // Tint color info string tintColorInfoString = fields[(int)CropGrowthFields.TintColorInfo]; cropGrowthInfo.TintColorInfo = TintColorInformation.ParseString(tintColorInfoString); if (cropGrowthInfo.TintColorInfo == null) { return(null); } return(cropGrowthInfo); }