Skip to content

Commit

Permalink
*creating the needed json files from png
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphyum committed May 6, 2018
1 parent a569aaa commit 3ae880f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
43 changes: 41 additions & 2 deletions ClassLibrary2/CommanderPortraitLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using HBS;
using HBS.Collections;
using BattleTech.Data;
using Newtonsoft.Json.Linq;

namespace CommanderPortraitLoader {
[HarmonyPatch(typeof(RenderedPortraitResult), "get_Item")]
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -184,6 +185,30 @@ public static List<string> 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
Expand All @@ -207,6 +232,20 @@ public static List<string> 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";
Expand Down
8 changes: 8 additions & 0 deletions ClassLibrary2/CommanderPortraitLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\BATTLETECH\BattleTech_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -53,6 +57,10 @@
<Compile Include="CommanderPortraitLoader.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
11 changes: 11 additions & 0 deletions ClassLibrary2/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
4 changes: 4 additions & 0 deletions ClassLibrary2/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net452" />
</packages>

0 comments on commit 3ae880f

Please sign in to comment.