public static Dictionary <string, string> PreFabDicPop(string[] files) { var dic = new Dictionary <string, string> { }; try { foreach (string prefabs in files) { string filename = Path.GetFileName(prefabs); string mechname = filename.Replace("chrprfmech_", "").Replace("base-001", ""); dic.Add(mechname, filename); } } catch (Exception e) { Reuse.EndProgram(e.ToString()); } return(dic); }
public static Settings LoadSettings() { string filepath = Directory.GetCurrentDirectory(); string settingfile = Path.Combine(filepath, "settings.json"); var fullPath = Path.Combine(filepath, settingfile); //var settings = new Settings(); var settings = new Settings(); if (File.Exists(fullPath)) { string jsonString = File.ReadAllText(settingfile); settings = Settings.FromJson(jsonString); } else { File.WriteAllText(fullPath, JsonConvert.SerializeObject(settings, Formatting.Indented)); Reuse.EndProgram("Settings file not found, created new default."); } if (!Directory.Exists(settings.BtInstallDir)) { Reuse.EndProgram("BT Direcotry not found at " + settings.BtInstallDir); } if (!Directory.Exists(settings.BedPath)) { Reuse.EndProgram("BED Files not found at " + settings.BedPath); } //if (!Directory.Exists(settings.ChassisDefpath)) Reuse.EndProgram("Chassis Files not found at " + settings.ChassisDefpath); try { if (!Directory.Exists(settings.OutputDir)) { Directory.CreateDirectory(settings.OutputDir); } } catch (Exception e) { Reuse.EndProgram("Error Creating Directory: " + settings.OutputDir + " " + e); } return(settings); }
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); }
static void Main() { string logMemory = ""; var settings = settingsLoad.LoadSettings(); var dlcDictionary = new Dictionary <string, string> { }; var cabDictionary = new Dictionary <string, string> { }; var btDictionary = new Dictionary <string, string> { }; var preFabDictionary = new Dictionary <string, string> { }; var gearDic = new Dictionary <string, (string, ComponentDefType)> { }; if (settings.UpdateCSV == true) { dlcDictionary = new Dictionary <string, string> { //DLCs these files are hidden in assest and have to be added by hand { "crab", "chrprfmech_crabbase-001" }, { "cyclops", "chrprfmech_cyclopsbase-001" }, { "hatchetman", "chrprfmech_hatchetmanbase-001" }, { "annihilator", "chrprfmech_annihilatorbase-001" }, { "archer", "chrprfmech_archerbase-001" }, { "assassin", "chrprfmech_assassinbase-001" }, { "bullshark", "chrprfmech_bullsharkbase-001" }, { "flea", "chrprfmech_fleabase-001" }, { "phoenixhawk", "chrprfmech_phoenixhawkbase-001" }, { "rifleman", "chrprfmech_riflemanbase-001" }, { "vulcan", "chrprfmech_vulcanbase-001" }, { "javelin", "chrprfmech_javelinmanbase-001" }, { "raven", "chrprfmech_ravenbase-001" }, }; cabDictionary = Reuse.PreFabDicPop(Directory.GetFiles(Path.Combine(settings.BtInstallDir, "mods\\CommunityAssets"), "chrprfmech*", SearchOption.AllDirectories)); btDictionary = Reuse.PreFabDicPop(Directory.GetFiles(Path.Combine(settings.BtInstallDir, "BattleTech_Data\\StreamingAssets\\data\\assetbundles"), "chrprfmech*", SearchOption.AllDirectories)); //(Count should be 177) preFabDictionary = dlcDictionary.Concat(cabDictionary).Concat(btDictionary).ToDictionary(k => k.Key, k => k.Value); //Populate Gear Dictionary Tuple (key, vaule, componentDefType) gearDic = ComponetDictionaryParse.ComDefDicPop(Directory.GetFiles(settings.BtInstallDir, "*.json", SearchOption.AllDirectories)); String csv = String.Join(Environment.NewLine, preFabDictionary.Select(d => $"{d.Key},{d.Value}")); csv = csv.Replace("(", ""); csv = csv.Replace(")", ""); String csv2 = String.Join(Environment.NewLine, gearDic.Select(d => $"{d.Key},{d.Value}")); csv2 = csv2.Replace("(", ""); csv2 = csv2.Replace(")", ""); File.WriteAllText(Path.Combine(settings.OutputDir, "preFabDictionary.csv"), csv); File.WriteAllText(Path.Combine(settings.OutputDir, "gearDic.csv"), csv2); Reuse.EndProgram("CSV files have been updated, pleaes change the settings.json to UpdateCSV=false"); } else { preFabDictionary = File.ReadLines("preFabDictionary.csv").Select(line => line.Split(',')).ToDictionary(line => line[0], line => line[1]); //gearDic = File.ReadLines("preFabDictionary.csv").Select(line => line.Split('|')).ToDictionary(line => line[0], line => line[1]); //gearDic = ComponetDictionaryParse.ComDefDicPop(Directory.GetFiles(settings.BtInstallDir, "*.json", SearchOption.AllDirectories)); /*string[] gearDicLines = File.ReadAllLines("gearDic.csv"); * foreach (string line in gearDicLines) * { * string[] split = line.Split(','); * gearDic.Add(split[0],(split[1], (ComponentDefType)Enum.Parse(typeof(ComponentDefType), split[2]))); * }*/ gearDic = File.ReadLines("gearDic.csv").Select(line => line.Split(',')).ToDictionary(line => line[0], line => (line[1], (ComponentDefType)Enum.Parse(typeof(ComponentDefType), line[2]))); } string[] chassisFiles = Directory.GetFiles(settings.ChassisDefpath, "chassis*.json", SearchOption.AllDirectories); string[] chassisNames = null; string[] bedfiles = Directory.GetFiles(settings.BedPath, "*.bed", SearchOption.AllDirectories); //Parallel.ForEach(bedfiles, (file) => foreach (var file in Directory.GetFiles(settings.BedPath, "*.bed", SearchOption.AllDirectories)) { Console.WriteLine($"Processing {file} on thread {Thread.CurrentThread.ManagedThreadId}"); bool cabCheck = MechBuilder.CabCheck(preFabDictionary, file); if (cabCheck == true) { chassisNames = MechBuilder.ChassisName(file); var chassisDef = MechBuilder.ChassisDefs(chassisNames, chassisFiles, false); if (chassisDef.Description != null) { //Console.WriteLine(file + " " + chassisDef.Description.Id); //Build MechDef from ChassisFile var mechDef = MechBuilder.MechDefs(chassisDef, file); //Add Mech Tags mechDef = MechBuilder.Tags(chassisDef, mechDef); //Add Mech Inventory "Parts" mechDef = MechBuilder.MechLocations(gearDic, mechDef, file, chassisDef); //Add Mech Engine = TTWalk * Tonnage mechDef = MechBuilder.Engines(chassisDef, mechDef, file); mechDef = MechBuilder.RoleTag(chassisDef, mechDef); string outputmechDef = Newtonsoft.Json.JsonConvert.SerializeObject(mechDef, Newtonsoft.Json.Formatting.Indented, Converter.Settings); File.WriteAllText(Path.Combine(settings.OutputDir, mechDef.Description.Id + ".json"), outputmechDef); logMemory = logMemory + Path.GetFileName(file) + "," + mechDef.Description.Id + ",Generated\r\n"; //var mechDef = MechBuilder.MechDefs(chassisDef); //break; } else { logMemory = logMemory + Path.GetFileName(file) + ",NO ChassisDef File,Not Generated\r\n"; } } else { logMemory = logMemory + Path.GetFileName(file) + ",NO CAB,Not Generated\r\n"; } //}); } Log(logMemory, settings.OutputDir); }