Skip to content

Commit

Permalink
Add script to generate whizbang decks
Browse files Browse the repository at this point in the history
  • Loading branch information
azeier committed Aug 9, 2019
1 parent 6492772 commit d9c6b0a
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Hearthstone Deck Tracker/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;

Expand Down Expand Up @@ -61,3 +62,5 @@
[assembly: NeutralResourcesLanguage("en")]

[assembly: AssemblyMetadata("SquirrelAwareVersion", "1")]

[assembly: InternalsVisibleTo("ResourceGenerator")]
28 changes: 28 additions & 0 deletions Hearthstone Deck Tracker/Utility/RemoteConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ internal class ConfigData
[JsonProperty("arena")]
public ArenaData Arena { get; set; }

[JsonProperty("whizbang_decks")]
public List<WhizbangDeck> WhizbangDecks { get; set; }

internal class NewsData
{
[JsonProperty("id")]
Expand Down Expand Up @@ -67,6 +70,31 @@ internal class ArenaData
[JsonProperty("banned_secrets")]
public List<string> BannedSecrets { get; set; }
}

internal class WhizbangDeck
{

[JsonProperty("title")]
public string Title { get; set; }

[JsonProperty("class")]
public CardClass Class { get; set; }

[JsonProperty("deck_id")]
public int DeckId { get; set; }

[JsonProperty("cards")]
public List<RemoteConfigCard> Cards { get; set; }
}

internal class RemoteConfigCard
{
[JsonProperty("dbf_id")]
public int DbfId { get; set; }

[JsonProperty("count")]
public int Count { get; set; }
}
}
}
}
45 changes: 42 additions & 3 deletions ResourceGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
using System.Resources;
using HearthDb;
using HearthDb.Enums;
using HearthMirror;
using System.Linq;
using Newtonsoft.Json;
using static Hearthstone_Deck_Tracker.Utility.RemoteConfig.ConfigData;

namespace ResourceGenerator
{
Expand All @@ -14,9 +18,44 @@ internal class Program
private static void Main(string[] args)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var dir = args[0];
var tilesDir = Path.Combine(dir, args[1]);
var genDir = Path.Combine(dir, "Generated", args[1]);
switch(args[0])
{
case "tiles":
GenerateTiles(args);
break;
case "whizbang":
GenerateWhizbangDecks(args);
break;
}
}

private static void GenerateWhizbangDecks(string[] args)
{
var file = args[1];
Console.WriteLine("Ensure Hearthstone is running. Press any key to continue...");
Console.ReadKey();
Console.WriteLine("Reading decks from memory...");
Console.WriteLine("(this make take a while)");
var templateDecks = Reflection.GetTemplateDecks();
var whizbangDecks = templateDecks.Where(d => d.SortOrder < 2)
.Select(d => new WhizbangDeck
{
Title = d.Title,
Class = (CardClass)d.Class,
DeckId = d.DeckId,
Cards = d.Cards.GroupBy(c => c).Select(x => new RemoteConfigCard{ DbfId = x.Key, Count = x.Count() }).ToList(),
});
using(var sw = new StreamWriter(file))
sw.WriteLine(JsonConvert.SerializeObject(whizbangDecks, Formatting.Indented));
Console.WriteLine("Saved to " + file);
Console.ReadKey();
}

private static void GenerateTiles(string[] args)
{
var dir = args[1];
var tilesDir = Path.Combine(dir, args[2]);
var genDir = Path.Combine(dir, "Generated", args[2]);
var dict = new Dictionary<string, List<Card>>();

Directory.CreateDirectory(genDir);
Expand Down
38 changes: 38 additions & 0 deletions ResourceGenerator/ResourceGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -34,6 +49,9 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="nQuant.Core">
<HintPath>..\packages\nQuant.1.0.3\lib\net40\nQuant.Core.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -64,6 +82,26 @@
<Project>{7ed14243-e02b-4b94-af00-a67a62c282f0}</Project>
<Name>HearthDb</Name>
</ProjectReference>
<ProjectReference Include="..\HearthMirror\HearthMirror\HearthMirror.csproj">
<Project>{1694A2F8-645A-4263-A6AB-FC26323FD675}</Project>
<Name>HearthMirror</Name>
</ProjectReference>
<ProjectReference Include="..\Hearthstone Deck Tracker\Hearthstone Deck Tracker.csproj">
<Project>{E63A3F1C-E662-4E62-BE43-AF27CB9E953D}</Project>
<Name>Hearthstone Deck Tracker</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5.2">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5.2 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
1 change: 1 addition & 0 deletions ResourceGenerator/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net452" />
<package id="nQuant" version="1.0.3" targetFramework="net452" />
</packages>
2 changes: 1 addition & 1 deletion generate_resources.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
call update_card_tiles.bat

msbuild /t:ResourceGenerator /p:Configuration=Debug /p:Platform="x86"
.\ResourceGenerator\bin\x86\Debug\ResourceGenerator.exe .\Resources Tiles
.\ResourceGenerator\bin\x86\Debug\ResourceGenerator.exe tiles .\Resources Tiles
4 changes: 4 additions & 0 deletions generate_whizbang_decks.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off

msbuild /t:ResourceGenerator /p:Configuration=Debug /p:Platform="x86"
.\ResourceGenerator\bin\x86\Debug\ResourceGenerator.exe whizbang whizbang.json

0 comments on commit d9c6b0a

Please sign in to comment.