From 3ae880f7e2c232a466fe50853fc5c96160756a91 Mon Sep 17 00:00:00 2001 From: Morphyum Date: Sun, 6 May 2018 14:23:08 +0200 Subject: [PATCH] *creating the needed json files from png --- ClassLibrary2/CommanderPortraitLoader.cs | 43 +++++++++++++++++++- ClassLibrary2/CommanderPortraitLoader.csproj | 8 ++++ ClassLibrary2/app.config | 11 +++++ ClassLibrary2/packages.config | 4 ++ 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 ClassLibrary2/app.config create mode 100644 ClassLibrary2/packages.config diff --git a/ClassLibrary2/CommanderPortraitLoader.cs b/ClassLibrary2/CommanderPortraitLoader.cs index b7d72b7..b081239 100644 --- a/ClassLibrary2/CommanderPortraitLoader.cs +++ b/ClassLibrary2/CommanderPortraitLoader.cs @@ -13,6 +13,7 @@ using HBS; using HBS.Collections; using BattleTech.Data; +using Newtonsoft.Json.Linq; namespace CommanderPortraitLoader { [HarmonyPatch(typeof(RenderedPortraitResult), "get_Item")] @@ -140,10 +141,10 @@ public static class CommanderPortraitLoader { public static void Init() { var harmony = HarmonyInstance.Create("de.morphyum.CommanderPortraitLoader"); harmony.PatchAll(Assembly.GetExecutingAssembly()); - + CreateJsons(); } - + // Token: 0x0600564D RID: 22093 RVA: 0x0023F158 File Offset: 0x0023D358 public static Sprite DownsampleSprite(Sprite oldSprite) { @@ -184,6 +185,30 @@ public static List GetAbilityDefsForSkill(string[][] abilityDefConsts, i } return list; } + + public static void CreateJsons() { + try { + string filePath = "mods/CommanderPortraitLoader/Portraits/"; + DirectoryInfo d1 = new DirectoryInfo(filePath); + FileInfo[] f1 = d1.GetFiles("*.png"); + foreach (FileInfo info in f1) { + CustomPreset preset = new CustomPreset(); + preset.isCommander = true; + preset.Description = new CustomDescription(); + preset.Description.Id = info.Name.Replace(".png", ""); + preset.Description.Icon = info.Name.Replace(".png", ""); + preset.Description.Name = info.Name.Replace(".png", ""); + preset.Description.Details = ""; + JObject o = (JObject)JToken.FromObject(preset); + using (StreamWriter writer = new StreamWriter(filePath + info.Name.Replace(".png", ".json"), true)) { + writer.WriteLine(o); + } + } + } catch(Exception e) { + Logger.LogError(e); + } + } + /* public static Settings LoadSettings() { try @@ -207,6 +232,20 @@ public static List GetAbilityDefsForSkill(string[][] abilityDefConsts, i public float RecoveryChance; }*/ + public class CustomPreset + { + public CustomDescription Description; + public bool isCommander; + + } + + public class CustomDescription { + public string Id; + public string Name; + public string Details; + public string Icon; + + } public class Logger { public static void LogError(Exception ex) { string filePath = "mods/CommanderPortraitLoader/Log.txt"; diff --git a/ClassLibrary2/CommanderPortraitLoader.csproj b/ClassLibrary2/CommanderPortraitLoader.csproj index 8b65a45..dab319d 100644 --- a/ClassLibrary2/CommanderPortraitLoader.csproj +++ b/ClassLibrary2/CommanderPortraitLoader.csproj @@ -36,6 +36,10 @@ ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\BATTLETECH\BattleTech_Data\Managed\Assembly-CSharp.dll + + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + True + @@ -53,6 +57,10 @@ + + + +