Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy textured emblems to generated mod #1455

Merged
merged 1 commit into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions ImperatorToCK3/Outputter/CoatOfArmsEmblemsOutputter.cs
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);
}
}
59 changes: 0 additions & 59 deletions ImperatorToCK3/Outputter/ColoredEmblemsOutputter.cs

This file was deleted.

2 changes: 1 addition & 1 deletion ImperatorToCK3/Outputter/WorldOutputter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down