diff --git a/ImperatorToCK3/Outputter/CoatOfArmsEmblemsOutputter.cs b/ImperatorToCK3/Outputter/CoatOfArmsEmblemsOutputter.cs new file mode 100644 index 000000000..818047a09 --- /dev/null +++ b/ImperatorToCK3/Outputter/CoatOfArmsEmblemsOutputter.cs @@ -0,0 +1,85 @@ +using commonItems; +using commonItems.Mods; +using ImageMagick; +using System.Collections.Generic; +using System.IO; + +namespace ImperatorToCK3.Outputter; + +public static class CoatOfArmsEmblemsOutputter { + private static bool IsBrokenColoredEmblem(string fileName, Configuration config) { + var emblemFilePath = Path.Combine( + "output", + config.OutputModName, + "gfx/coat_of_arms/colored_emblems/ce_lion.dds" + ); + // Something's wrong with ce_lion.dds. + if (fileName == "ce_lion.dds" && !File.Exists(emblemFilePath)) { + // Instead of converting a broken file from Imperator, copy closest CK3 emblem. + var wasCopied = SystemUtils.TryCopyFile( + Path.Combine(config.CK3Path, "game/gfx/coat_of_arms/colored_emblems/ce_lion_passant.dds"), + emblemFilePath + ); + if (!wasCopied) { + Logger.Warn("Couldn't copy a replacement for ce_lion.dds!"); + } + return true; + } + return false; + } + + private static void CopyColoredEmblems(Configuration config, ModFilesystem imperatorModFS) { + Logger.Info("Copying colored emblems..."); + var coloredEmblemsFolder = "gfx/coat_of_arms/colored_emblems"; + var acceptedExtensions = new HashSet{ "dds", "tga", "png" }; + + var emblemFiles = imperatorModFS.GetAllFilesInFolderRecursive(coloredEmblemsFolder); + foreach (var filePath in emblemFiles) { + if (!acceptedExtensions.Contains(CommonFunctions.GetExtension(filePath))) { + continue; + } + CopyEmblem(filePath); + } + Logger.IncrementProgress(); + + void CopyEmblem(string emblemFilePath) { + var fileName = CommonFunctions.TrimPath(emblemFilePath); + + if (IsBrokenColoredEmblem(fileName, config)) { + return; + } + // Load an image. + var image = new MagickImage(emblemFilePath); + image.Negate(channels: Channels.Red); + // Write the image to new file. + var outputPath = Path.Combine("output", config.OutputModName, "gfx/coat_of_arms/colored_emblems", fileName); + image.Write(outputPath); + } + } + + private static void CopyTexturedEmblems(Configuration config, ModFilesystem imperatorModFS) { + Logger.Info("Copying textured emblems..."); + const string texturedEmblemsFolder = "gfx/coat_of_arms/textured_emblems"; + var acceptedExtensions = new HashSet{ "dds", "tga", "png" }; + + var emblemFiles = imperatorModFS.GetAllFilesInFolderRecursive(texturedEmblemsFolder); + foreach (var filePath in emblemFiles) { + if (!acceptedExtensions.Contains(CommonFunctions.GetExtension(filePath))) { + continue; + } + + // Copy image to output path. + var fileName = CommonFunctions.TrimPath(filePath); + var outputPath = Path.Combine("output", config.OutputModName, "gfx/coat_of_arms/textured_emblems", fileName); + var wasCopied = SystemUtils.TryCopyFile(filePath, outputPath); + if (!wasCopied) { + Logger.Warn($"Failed to copy textured emblem {fileName}!"); + } + } + } + + public static void CopyEmblems(Configuration config, ModFilesystem imperatorModFS) { + CopyColoredEmblems(config, imperatorModFS); + CopyTexturedEmblems(config, imperatorModFS); + } +} diff --git a/ImperatorToCK3/Outputter/ColoredEmblemsOutputter.cs b/ImperatorToCK3/Outputter/ColoredEmblemsOutputter.cs deleted file mode 100644 index 7210b98bc..000000000 --- a/ImperatorToCK3/Outputter/ColoredEmblemsOutputter.cs +++ /dev/null @@ -1,59 +0,0 @@ -using commonItems; -using commonItems.Mods; -using ImageMagick; -using System.Collections.Generic; -using System.IO; - -namespace ImperatorToCK3.Outputter; - -public static class ColoredEmblemsOutputter { - private static bool IsBrokenEmblem(string fileName, Configuration config) { - var emblemFilePath = Path.Combine( - "output", - config.OutputModName, - "gfx", "coat_of_arms", "colored_emblems", "ce_lion.dds" - ); - // something's wrong with ce_lion.dds - if (fileName == "ce_lion.dds" && !File.Exists(emblemFilePath)) { - // instead of converting a broken file from Imperator, copy closest CK3 emblem - var wasCopied = SystemUtils.TryCopyFile( - Path.Combine(config.CK3Path, "game", "gfx", "coat_of_arms", "colored_emblems", "ce_lion_passant.dds"), - emblemFilePath - ); - if (!wasCopied) { - Logger.Warn("Couldn't copy a replacement for ce_lion.dds!"); - } - return true; - } - return false; - } - - public static void CopyColoredEmblems(Configuration config, ModFilesystem imperatorModFS) { - Logger.Info("Copying colored emblems..."); - var coloredEmblemsFolder = Path.Combine("gfx", "coat_of_arms", "colored_emblems"); - var acceptedExtensions = new HashSet{ "dds", "tga", "png" }; - - var emblemFiles = imperatorModFS.GetAllFilesInFolderRecursive(coloredEmblemsFolder); - foreach (var filePath in emblemFiles) { - if (!acceptedExtensions.Contains(CommonFunctions.GetExtension(filePath))) { - continue; - } - CopyEmblem(filePath); - } - Logger.IncrementProgress(); - - void CopyEmblem(string emblemFilePath) { - var fileName = CommonFunctions.TrimPath(emblemFilePath); - - if (IsBrokenEmblem(fileName, config)) { - return; - } - // Load an image. - var image = new MagickImage(emblemFilePath); - image.Negate(channels: Channels.Red); - // Write the image to new file. - var outputPath = Path.Combine("output", config.OutputModName, "gfx", "coat_of_arms", "colored_emblems", fileName); - image.Write(outputPath); - } - } -} diff --git a/ImperatorToCK3/Outputter/WorldOutputter.cs b/ImperatorToCK3/Outputter/WorldOutputter.cs index cf49c54f1..d320a426f 100644 --- a/ImperatorToCK3/Outputter/WorldOutputter.cs +++ b/ImperatorToCK3/Outputter/WorldOutputter.cs @@ -69,7 +69,7 @@ public static void OutputWorld(World ck3World, Imperator.World imperatorWorld, C NamedColorsOutputter.OutputNamedColors(outputName, imperatorWorld.NamedColors, ck3World.NamedColors); - ColoredEmblemsOutputter.CopyColoredEmblems(config, imperatorWorld.ModFS); + CoatOfArmsEmblemsOutputter.CopyEmblems(config, imperatorWorld.ModFS); CoatOfArmsOutputter.OutputCoas(outputName, ck3World.LandedTitles, ck3World.Dynasties); CoatOfArmsOutputter.CopyCoaPatterns(imperatorWorld.ModFS, outputPath);