diff --git a/PMCGenerator/Models/Presets.cs b/PMCGenerator/Models/Presets.cs index a90bd2d..a9668b7 100644 --- a/PMCGenerator/Models/Presets.cs +++ b/PMCGenerator/Models/Presets.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; namespace PMCGenerator { diff --git a/PMCGenerator/Program.cs b/PMCGenerator/Program.cs index 9da80a6..2a9aed1 100644 --- a/PMCGenerator/Program.cs +++ b/PMCGenerator/Program.cs @@ -2,7 +2,6 @@ using Common.Extensions; using Newtonsoft.Json; using PMCGenerator.Models; -using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -14,30 +13,24 @@ namespace PMCGenerator { static void Main(string[] args) { - // take a list of preset files and spit out a drop-in-replacement mod list - var presetPath = CreateInputFolder(); var presetFiles = GetPresetFileList(presetPath); // Parse into list of strongly typed objects - var parsedPresets = new List(); - foreach (var presetFile in presetFiles) - { - var json = File.ReadAllText(presetFile); - var parsedFile = JsonConvert.DeserializeObject(json); - parsedPresets.Add(parsedFile); - } + var parsedPresets = ParsePresetJsons(presetFiles); // Create flat lists of weapons + list of mods - var flatWeaponsList = GetWeaponsFromRawFile(parsedPresets); + var flatPrimaryWeaponsList = GetWeaponsFromRawFile(parsedPresets); + var flatSecondaryWeaponsList = GetSecondaryWeaponsFromRawFile(parsedPresets); var flatModList = GetModsFromRawFile(parsedPresets); // Add weapon mods to output - var output = new { FirstPrimaryWeapon = new List(), mods = new Dictionary>>() }; - output.FirstPrimaryWeapon.AddRange(flatWeaponsList.Select(x => x.TemplateId).Distinct()); + var output = new { FirstPrimaryWeapon = new List(), Holster = new List(), mods = new Dictionary>>() }; + output.FirstPrimaryWeapon.AddRange(flatPrimaryWeaponsList.Select(x => x.TemplateId).Distinct()); + output.Holster.AddRange(flatSecondaryWeaponsList.Select(x => x.TemplateId).Distinct()); - foreach (var weapon in flatWeaponsList) + foreach (var weapon in flatPrimaryWeaponsList) { // add weapon if its not already here if (!output.mods.ContainsKey(weapon.TemplateId)) @@ -69,7 +62,7 @@ namespace PMCGenerator // Get mods where parent is not weapon and add to output foreach (var mod in flatModList.Where(x => x.ParentId != null - && !flatWeaponsList.Any(y => y.Id == x.ParentId)).ToList()) + && !flatPrimaryWeaponsList.Any(y => y.Id == x.ParentId)).ToList()) { // No parent tempalte id found, create and add mods details if (!output.mods.ContainsKey(mod.ParentTemplateId)) @@ -101,6 +94,26 @@ namespace PMCGenerator CreateJsonFile(outputPath, outputJson); } + private static List ParsePresetJsons(List presetFiles) + { + var result = new List(); + foreach (var presetFile in presetFiles) + { + var json = File.ReadAllText(presetFile); + var parsedFile = JsonConvert.DeserializeObject(json); + result.Add(parsedFile); + } + + int count = 0; + foreach (var file in result) + { + count += file.weaponbuilds.Count; + } + LoggingHelpers.LogToConsole($"{count} presets parsed"); + + return result; + } + private static List GetModsFromRawFile(List parsedPresets) { List result = new List(); @@ -120,7 +133,10 @@ namespace PMCGenerator } Module parentMod = GetModsParent(file, mod.parentId); - result.Add(new ModDetails(mod.slotId, mod._id, mod._tpl, mod.parentId, parentMod._tpl)); + if (parentMod != null) + { + result.Add(new ModDetails(mod.slotId, mod._id, mod._tpl, mod.parentId, parentMod._tpl)); + } } } } @@ -152,7 +168,7 @@ namespace PMCGenerator var result = new List(); foreach (var file in parsedPresets) { - foreach (var item in file.weaponbuilds) + foreach (var item in file.weaponbuilds.Where(x=> !x.Key.Contains("pistol"))) { Weapon weapon = item.Value; result.Add(new WeaponDetails(item.Key, weapon.items[0]._id, weapon.items[0]._tpl)); @@ -163,6 +179,22 @@ namespace PMCGenerator return result; } + private static List GetSecondaryWeaponsFromRawFile(List parsedPresets) + { + var result = new List(); + foreach (var file in parsedPresets) + { + foreach (var item in file.weaponbuilds.Where(x => x.Key.Contains("pistol"))) + { + Weapon weapon = item.Value; + result.Add(new WeaponDetails(item.Key, weapon.items[0]._id, weapon.items[0]._tpl)); + } + } + + + return result; + } + // Write json to a file private static void CreateJsonFile(string outputPath, string outputJson) { @@ -177,7 +209,7 @@ namespace PMCGenerator private static List GetPresetFileList(string presetPath) { var presetFiles = Directory.GetFiles(presetPath, "*.json", SearchOption.TopDirectoryOnly).ToList(); - Console.WriteLine($"{presetFiles.Count} preset files found"); + LoggingHelpers.LogToConsole($"{presetFiles.Count} preset files found"); return presetFiles; }