public static ChassisDef ChassisDefs(string[] chassisNames, string[] files, bool rebuild) { var chassisDef = new ChassisDef(); string toSearch = chassisNames[0].ToLower() + "_" + chassisNames[1].ToUpper(); //int index = -1; string filename; foreach (string file in files) { filename = Path.GetFileName(file); string[] split = filename.Split('_'); foreach (string s in split) { string news = s.Replace(".json", ""); if ((news == (chassisNames[1])) && (rebuild == false)) { string jsonString = File.ReadAllText(file); chassisDef = ChassisDef.FromJson(jsonString); if (chassisDef.Description.Name.Contains("__")) { LocalizationParse(chassisDef, file); } } //Rebuild is an attempt to rebuild ChassisDefs if they are missing for variants BETA Use Wisely. if ((file.Contains(chassisNames[0])) && (rebuild == true)) { string jsonString = File.ReadAllText(file); chassisDef = ChassisDef.FromJson(jsonString); break; } } } return(chassisDef); }
private static ChassisDef LocalizationParse(ChassisDef chassisDef, string file) { string jsonString = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Localization.json")); var localization = Localization.FromJson(jsonString); foreach (var obj in localization) { chassisDef.Description.UiName = chassisDef.Description.UiName.Replace("__/", ""); chassisDef.Description.UiName = chassisDef.Description.UiName.Replace("/__", ""); chassisDef.Description.Name = chassisDef.Description.Name.Replace("__/", ""); chassisDef.Description.Name = chassisDef.Description.Name.Replace("/__", ""); chassisDef.Description.Details = chassisDef.Description.Details.Replace("__/", ""); chassisDef.Description.Details = chassisDef.Description.Details.Replace("/__", ""); if (chassisDef.Description.UiName == obj.Name) { chassisDef.Description.UiName = obj.Original; } if (chassisDef.Description.Name == obj.Name) { chassisDef.Description.Name = obj.Original; } if (chassisDef.Description.Details == obj.Name) { chassisDef.Description.Details = obj.Original; } } string outputchassisDef = Newtonsoft.Json.JsonConvert.SerializeObject(chassisDef, Newtonsoft.Json.Formatting.Indented, Converter.Settings); File.WriteAllText(file, outputchassisDef); return(chassisDef); }
public static MechDef MechDefs(ChassisDef chassisDef, string bedfile) { var mechdef = new MechDef { ChassisId = chassisDef.Description.Id, HeraldryId = null, Description = new DefDescription { Cost = chassisDef.Description.Cost, Rarity = chassisDef.Description.Rarity, Purchasable = chassisDef.Description.Purchasable, UiName = chassisDef.Description.UiName + " " + chassisDef.VariantName, Id = chassisDef.Description.Id.Replace("chassisdef", "mechdef"), Name = chassisDef.Description.Name, Details = chassisDef.Description.Details, Icon = chassisDef.Description.Icon }, SimGameMechPartCost = chassisDef.Description.Cost, Version = 1, Locations = new List <MechDefLocation>(), Inventory = new List <Inventory>(), }; string[] filelines = File.ReadAllLines(bedfile); string armorline = ""; string armortypeline = ""; string sturcturetypeline = ""; int internalStructre = -1; foreach (string lines in filelines) { string newl = Reuse.RemoveSpecialCharacters(lines); newl = newl.Replace("\"", ""); if (newl.Contains("ArmorVals")) { armorline = newl; break; } if (newl.Contains("Armor")) { armortypeline = newl; } if (newl.Contains("Internal")) { sturcturetypeline = newl; } } if (!armorline.Contains("ArmorVals")) { Reuse.EndProgram("FATAL ERROR: Unable to parse ArmorVals from Bedfile"); } string[] armorvaulewords = armorline.Split(','); foreach (Location location in Enum.GetValues(typeof(Location))) { //ArmorVaule to Location If Array int frontarmorvaule = -1; int reararmorvaule = -1; if ((int)location == 0) { frontarmorvaule = 45; } else { frontarmorvaule = Convert.ToInt32(armorvaulewords[(int)location]) * 5; } if (((int)location == 3) || ((int)location == 4)) { reararmorvaule = Convert.ToInt32(armorvaulewords[6]) * 5; } if ((int)location == 5) { reararmorvaule = Convert.ToInt32(armorvaulewords[8]) * 5; } if (((int)location == 6) || ((int)location == 7)) { frontarmorvaule = Convert.ToInt32(armorvaulewords[10]) * 5; } foreach (Location chassislocation in Enum.GetValues(typeof(Location))) { if (chassisDef.Locations[(int)chassislocation].Location == location) { internalStructre = chassisDef.Locations[(int)chassislocation].InternalStructure; } } mechdef.Locations.Add(new MechDefLocation { DamageLevel = DamageLevel.Functional, Location = location, CurrentArmor = frontarmorvaule, CurrentRearArmor = reararmorvaule, CurrentInternalStructure = internalStructre, AssignedArmor = frontarmorvaule, AssignedRearArmor = reararmorvaule, }); } string armortype = ""; if (armortypeline.Contains("Standard")) { armortype = "emod_armorslots_standard"; } if (armortypeline.Contains("Ferro")) { armortype = "emod_armorslots_ferrosfibrous"; } mechdef.Inventory.Add(new Inventory { MountedLocation = Location.CenterTorso, ComponentDefId = armortype, ComponentDefType = ComponentDefType.Upgrade, HardpointSlot = -1, DamageLevel = "Functional", PrefabName = null, HasPrefabName = false, SimGameUid = "", Guid = null }); string sturcturetype = ""; if (sturcturetypeline.Contains("Standard")) { sturcturetype = "emod_structureslots_standard"; } if (sturcturetypeline.Contains("Endo")) { sturcturetype = "emod_structureslots_endosteel"; } mechdef.Inventory.Add(new Inventory { MountedLocation = Location.CenterTorso, ComponentDefId = sturcturetype, ComponentDefType = ComponentDefType.Upgrade, HardpointSlot = -1, DamageLevel = "Functional", PrefabName = null, HasPrefabName = false, SimGameUid = "", Guid = null }); return(mechdef); }
public static string ToJson(this ChassisDef self) => JsonConvert.SerializeObject(self, Converter.Settings);