From ce1cb1ebcd160a2276f9babd009e21ac6c070bc1 Mon Sep 17 00:00:00 2001 From: Alexander Zeier Date: Sat, 26 Nov 2016 15:45:07 +0100 Subject: [PATCH] implement ResourceGenerator to pack card tiles into resource files --- .gitignore | 2 + Hearthstone Deck Tracker.sln | 10 ++- ResourceGenerator/App.config | 6 ++ ResourceGenerator/Program.cs | 46 +++++++++++++ ResourceGenerator/Properties/AssemblyInfo.cs | 36 ++++++++++ ResourceGenerator/ResourceGenerator.csproj | 71 ++++++++++++++++++++ bootstrap.bat | 3 +- generate_resources.bat | 2 + 8 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 ResourceGenerator/App.config create mode 100644 ResourceGenerator/Program.cs create mode 100644 ResourceGenerator/Properties/AssemblyInfo.cs create mode 100644 ResourceGenerator/ResourceGenerator.csproj create mode 100644 generate_resources.bat diff --git a/.gitignore b/.gitignore index a07449e429..cf20e0110a 100644 --- a/.gitignore +++ b/.gitignore @@ -165,3 +165,5 @@ Hearthstone Deck Tracker/Resources/CHANGELOG.md HSReplay-Api/ Hearthstone Deck Tracker/Properties/Strings.* HDT-Localization/ + +Resources/Generated/ diff --git a/Hearthstone Deck Tracker.sln b/Hearthstone Deck Tracker.sln index e68c67e557..ff3d236136 100644 --- a/Hearthstone Deck Tracker.sln +++ b/Hearthstone Deck Tracker.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +VisualStudioVersion = 14.0.25123.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hearthstone Deck Tracker", "Hearthstone Deck Tracker\Hearthstone Deck Tracker.csproj", "{E63A3F1C-E662-4E62-BE43-AF27CB9E953D}" EndProject @@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HearthWatcher", "HearthWatc EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HearthWatcher.Test", "HearthWatcher.Test\HearthWatcher.Test.csproj", "{D081BCA4-14FD-4FBC-B92A-82574AB0478B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResourceGenerator", "ResourceGenerator\ResourceGenerator.csproj", "{944AFE2A-49B4-4E63-BA1D-FC49E5029F36}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 @@ -88,6 +90,12 @@ Global {D081BCA4-14FD-4FBC-B92A-82574AB0478B}.Release|x86.Build.0 = Release|x86 {D081BCA4-14FD-4FBC-B92A-82574AB0478B}.Squirrel|x86.ActiveCfg = Release|x86 {D081BCA4-14FD-4FBC-B92A-82574AB0478B}.Squirrel|x86.Build.0 = Release|x86 + {944AFE2A-49B4-4E63-BA1D-FC49E5029F36}.Debug|x86.ActiveCfg = Debug|x86 + {944AFE2A-49B4-4E63-BA1D-FC49E5029F36}.Debug|x86.Build.0 = Debug|x86 + {944AFE2A-49B4-4E63-BA1D-FC49E5029F36}.Release|x86.ActiveCfg = Release|x86 + {944AFE2A-49B4-4E63-BA1D-FC49E5029F36}.Release|x86.Build.0 = Release|x86 + {944AFE2A-49B4-4E63-BA1D-FC49E5029F36}.Squirrel|x86.ActiveCfg = Release|x86 + {944AFE2A-49B4-4E63-BA1D-FC49E5029F36}.Squirrel|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ResourceGenerator/App.config b/ResourceGenerator/App.config new file mode 100644 index 0000000000..88fa4027bd --- /dev/null +++ b/ResourceGenerator/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ResourceGenerator/Program.cs b/ResourceGenerator/Program.cs new file mode 100644 index 0000000000..048847206e --- /dev/null +++ b/ResourceGenerator/Program.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Resources; +using HearthDb; + +namespace ResourceGenerator +{ + internal class Program + { + private static void Main(string[] args) + { + var dir = args[0]; + var tilesDir = Path.Combine(dir, args[1]); + var genDir = Path.Combine(dir, "Generated", args[1]); + var dict = new Dictionary>(); + + Directory.CreateDirectory(genDir); + + foreach(var card in Cards.All) + { + var key = card.Value.Set + (card.Value.Collectible ? "" : "_NC"); + if(!dict.ContainsKey(key)) + dict[key] = new List(); + dict[key].Add(card.Value); + } + + foreach(var set in dict.Keys) + { + var file = $"{genDir}\\{set}.res"; + Console.WriteLine($"Generating {file}..."); + using(var rw = new ResourceWriter(file)) + { + foreach(var card in dict[set]) + { + var img = new FileInfo($"{tilesDir}\\{card.Id}.png"); + if(!img.Exists) + continue; + rw.AddResource(card.Id, new Bitmap(img.FullName)); + } + } + } + } + } +} diff --git a/ResourceGenerator/Properties/AssemblyInfo.cs b/ResourceGenerator/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..3b1eeb9e12 --- /dev/null +++ b/ResourceGenerator/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ResourceGenerator")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ResourceGenerator")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("944afe2a-49b4-4e63-ba1d-fc49e5029f36")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ResourceGenerator/ResourceGenerator.csproj b/ResourceGenerator/ResourceGenerator.csproj new file mode 100644 index 0000000000..984153a3ea --- /dev/null +++ b/ResourceGenerator/ResourceGenerator.csproj @@ -0,0 +1,71 @@ + + + + + Debug + AnyCPU + {944AFE2A-49B4-4E63-BA1D-FC49E5029F36} + Exe + Properties + ResourceGenerator + ResourceGenerator + v4.5.2 + 512 + true + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + + + + {7ed14243-e02b-4b94-af00-a67a62c282f0} + HearthDb + + + + + \ No newline at end of file diff --git a/bootstrap.bat b/bootstrap.bat index 6af514d45c..d2c5d9d36f 100644 --- a/bootstrap.bat +++ b/bootstrap.bat @@ -3,4 +3,5 @@ git clone https://github.com/HearthSim/HearthDb HearthDb git clone https://github.com/HearthSim/HearthMirror HearthMirror git clone https://github.com/HearthSim/HSReplay-API-Client.git HSReplay-Api git clone https://github.com/HearthSim/HDT-Localization HDT-Localization -xcopy /Y "HDT-Localization\*.resx" "Hearthstone Deck Tracker\Properties\" \ No newline at end of file +xcopy /Y "HDT-Localization\*.resx" "Hearthstone Deck Tracker\Properties\" +./generate_resources.bat \ No newline at end of file diff --git a/generate_resources.bat b/generate_resources.bat new file mode 100644 index 0000000000..0c10e57086 --- /dev/null +++ b/generate_resources.bat @@ -0,0 +1,2 @@ +msbuild /t:ResourceGenerator /p:Configuration=Debug +.\ResourceGenerator\bin\x86\Debug\ResourceGenerator.exe .\Resources Tiles \ No newline at end of file