-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy textured emblems to generated mod (#1455)
- Loading branch information
1 parent
ec9b13d
commit 0058cfc
Showing
3 changed files
with
86 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string>{ "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<string>{ "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); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters