Skip to content

Commit

Permalink
Read localization from mods (#241)
Browse files Browse the repository at this point in the history
* Ask for Imp docs dir instead of Imp mods dir

* loadModDirectory

* Read localization from mods

* No mods in configuration

* tests

* cleanup

* Update CMakeLists.txt

* PR tweaks

* Newer save

* Update CMakeLists.txt

* Update CMakeLists.txt

* Update ZipLib

* Update CMakeLists.txt
  • Loading branch information
IhateTrains authored Jun 30, 2021
1 parent 4e46726 commit f1a847e
Show file tree
Hide file tree
Showing 46 changed files with 691 additions and 2,831,753 deletions.
5 changes: 4 additions & 1 deletion ImperatorToCK3.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "ZipLib\extlibs\zlib\zlib.vcxproj", "{BAEB16B3-DB4C-432F-9E6A-2ACADEA0691D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImperatorToCK3Tests", "ImperatorToCK3Tests\ImperatorToCK3Tests.vcxproj", "{2252FE41-5CF1-4585-9EED-10087D112F1F}"
ProjectSection(ProjectDependencies) = postProject
{5C9FD859-DDF9-4510-8397-B329B0AE8C48} = {5C9FD859-DDF9-4510-8397-B329B0AE8C48}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Fronter", "Fronter\Fronter.vcxproj", "{D4E43E3D-E131-466D-9AA7-704C2298EACC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Release|x64 = Release|x64
Debug|x64 = Debug|x64
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{74636764-298A-4772-818D-AA5734CB74B1}.Debug|x64.ActiveCfg = Debug|x64
Expand Down
2 changes: 2 additions & 0 deletions ImperatorToCK3/Data_Files/configuration_l_english.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ l_english:
IMPFOLDERTIP: "The path on your computer where Imperator: Rome is installed"
IMPMOD: "Imperator: Rome Mod Directory"
IMPMODTIP: "The path on your computer where Imperator: Rome stores mods"
IMPDOC: "Imperator: Rome Documents Directory"
IMPDOCTIP: "The path on your computer where Imperator: Rome keeps temporary files"

CK3GAME: "Crusader Kings III"
CK3FOLDER: "Crusader Kings III Install Directory"
Expand Down
8 changes: 4 additions & 4 deletions ImperatorToCK3/Data_Files/fronter-configuration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ requiredFolder = {
searchPathID = 859580
}
requiredFolder = {
name = ImperatorModsDirectory
displayName = IMPMOD
tooltip = IMPMODTIP
name = ImperatorDocDirectory
displayName = IMPDOC
tooltip = IMPDOCTIP
mandatory = true
searchPathType = windowsUsersFolder
searchPath = "Paradox Interactive\Imperator\mod"
searchPath = "Paradox Interactive\Imperator"
}
requiredFolder = {
name = CK3directory
Expand Down
4 changes: 4 additions & 0 deletions ImperatorToCK3/ImperatorToCK3.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@
<ClCompile Include="Source\Imperator\Genes\AccessoryGeneTemplate.cpp" />
<ClCompile Include="Source\Imperator\Genes\WeightBlock.cpp" />
<ClCompile Include="Source\Imperator\ImperatorWorld.cpp" />
<ClCompile Include="Source\Imperator\ModLoader\ModLoader.cpp" />
<ClCompile Include="Source\Imperator\ModLoader\ModParser.cpp" />
<ClCompile Include="Source\Imperator\Provinces\PopFactory.cpp" />
<ClCompile Include="Source\Imperator\Provinces\Pops.cpp" />
<ClCompile Include="Source\Imperator\Provinces\Province.cpp" />
Expand Down Expand Up @@ -298,6 +300,8 @@
<ClInclude Include="Source\Imperator\Genes\AccessoryGeneTemplate.h" />
<ClInclude Include="Source\Imperator\Genes\WeightBlock.h" />
<ClInclude Include="Source\Imperator\ImperatorWorld.h" />
<ClInclude Include="Source\Imperator\ModLoader\ModLoader.h" />
<ClInclude Include="Source\Imperator\ModLoader\ModParser.h" />
<ClInclude Include="Source\Imperator\Provinces\Pop.h" />
<ClInclude Include="Source\Imperator\Provinces\PopFactory.h" />
<ClInclude Include="Source\Imperator\Provinces\Pops.h" />
Expand Down
15 changes: 15 additions & 0 deletions ImperatorToCK3/ImperatorToCK3.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
<Filter Include="Mappers\DeathReasonMapper">
<UniqueIdentifier>{8843f4f5-af76-4860-b3c3-bbbcc7f1274b}</UniqueIdentifier>
</Filter>
<Filter Include="Imperator\ModLoader">
<UniqueIdentifier>{7e2fec00-2a16-466b-85b8-86e5de690244}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Source\CK3Outputter\CK3WorldOutputter.h">
Expand Down Expand Up @@ -412,6 +415,12 @@
<ClInclude Include="Source\CommonUtilities\ContainerField.h">
<Filter>CommonUtilities</Filter>
</ClInclude>
<ClInclude Include="Source\Imperator\ModLoader\ModLoader.h">
<Filter>Imperator\ModLoader</Filter>
</ClInclude>
<ClInclude Include="Source\Imperator\ModLoader\ModParser.h">
<Filter>Imperator\ModLoader</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Source\main.cpp" />
Expand Down Expand Up @@ -707,6 +716,12 @@
<ClCompile Include="Source\CommonUtilities\ContainerField.cpp">
<Filter>CommonUtilities</Filter>
</ClCompile>
<ClCompile Include="Source\Imperator\ModLoader\ModLoader.cpp">
<Filter>Imperator\ModLoader</Filter>
</ClCompile>
<ClCompile Include="Source\Imperator\ModLoader\ModParser.cpp">
<Filter>Imperator\ModLoader</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="Resources\rakaly.dll">
Expand Down
26 changes: 13 additions & 13 deletions ImperatorToCK3/Source/CK3/CK3World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ using std::optional;


CK3::World::World(const Imperator::World& impWorld, const Configuration& theConfiguration, const commonItems::ConverterVersion& converterVersion) {
LOG(LogLevel::Info) << "*** Hello CK3, let's get painting. ***";
Log(LogLevel::Info) << "*** Hello CK3, let's get painting. ***";
// Scraping localizations from Imperator so we may know proper names for our countries.
localizationMapper.scrapeLocalizations(theConfiguration, map<string, string>()); // passes an empty map as second arg because we don't actually load mods yet
localizationMapper.scrapeLocalizations(theConfiguration, impWorld.getMods());

// Loading Imperator CoAs to use them for generated CK3 titles
coaMapper = mappers::CoaMapper(theConfiguration);
Expand Down Expand Up @@ -73,12 +73,12 @@ CK3::World::World(const Imperator::World& impWorld, const Configuration& theConf


void CK3::World::importImperatorCharacters(const Imperator::World& impWorld, const bool ConvertBirthAndDeathDates = true, const date endDate = date(867, 1, 1)) {
LOG(LogLevel::Info) << "-> Importing Imperator Characters";
Log(LogLevel::Info) << "-> Importing Imperator Characters";

for (const auto& character : impWorld.getCharacters()) {
importImperatorCharacter(character, ConvertBirthAndDeathDates, endDate);
}
LOG(LogLevel::Info) << ">> " << characters.size() << " total characters recognized.";
Log(LogLevel::Info) << ">> " << characters.size() << " total characters recognized.";
}


Expand All @@ -103,14 +103,14 @@ void CK3::World::importImperatorCharacter(const pair<unsigned long long, shared_


void CK3::World::importImperatorCountries(const map<unsigned long long, shared_ptr<Imperator::Country>>& imperatorCountries) {
LOG(LogLevel::Info) << "-> Importing Imperator Countries";
Log(LogLevel::Info) << "-> Importing Imperator Countries";

// landedTitles holds all titles imported from CK3. We'll now overwrite some and
// add new ones from Imperator tags.
for (const auto& title : imperatorCountries) {
importImperatorCountry(title, imperatorCountries);
}
LOG(LogLevel::Info) << ">> " << getTitles().size() << " total countries recognized.";
Log(LogLevel::Info) << ">> " << getTitles().size() << " total countries recognized.";
}


Expand Down Expand Up @@ -142,7 +142,7 @@ void CK3::World::importImperatorCountry(const pair<unsigned long long, shared_pt


void CK3::World::importVanillaProvinces(const string& ck3Path) {
LOG(LogLevel::Info) << "-> Importing Vanilla Provinces";
Log(LogLevel::Info) << "-> Importing Vanilla Provinces";
// ---- Loading history/provinces
auto fileNames = commonItems::GetAllFilesInFolderRecursive(ck3Path + "/game/history/provinces");
for (const auto& fileName : fileNames) {
Expand Down Expand Up @@ -193,12 +193,12 @@ void CK3::World::importVanillaProvinces(const string& ck3Path) {
}


LOG(LogLevel::Info) << ">> Loaded " << provinces.size() << " province definitions.";
Log(LogLevel::Info) << ">> Loaded " << provinces.size() << " province definitions.";
}


void CK3::World::importImperatorProvinces(const Imperator::World& impWorld) {
LOG(LogLevel::Info) << "-> Importing Imperator Provinces";
Log(LogLevel::Info) << "-> Importing Imperator Provinces";
auto counter = 0;
// Imperator provinces map to a subset of CK3 provinces. We'll only rewrite those we are responsible for.
for (const auto& [provinceID, province] : provinces) {
Expand All @@ -218,7 +218,7 @@ void CK3::World::importImperatorProvinces(const Imperator::World& impWorld) {
// And finally, initialize it.
++counter;
}
LOG(LogLevel::Info) << ">> " << impWorld.getProvinces().size() << " Imperator provinces imported into " << counter << " CK3 provinces.";
Log(LogLevel::Info) << ">> " << impWorld.getProvinces().size() << " Imperator provinces imported into " << counter << " CK3 provinces.";
}


Expand Down Expand Up @@ -293,7 +293,7 @@ void CK3::World::overWriteCountiesHistory() {
for (const auto& title : getTitles() | std::views::values) {
if (title->getRank()==TitleRank::county && title->capitalBaronyProvince > 0) { // title is a county and its capital province has a valid ID (0 is not a valid province in CK3)
if (!provinces.contains(title->capitalBaronyProvince))
LOG(LogLevel::Warning) << "Capital barony province not found " << title->capitalBaronyProvince;
Log(LogLevel::Warning) << "Capital barony province not found " << title->capitalBaronyProvince;
else {
const auto& impProvince = provinces.find(title->capitalBaronyProvince)->second->getImperatorProvince();
if (impProvince) {
Expand Down Expand Up @@ -427,7 +427,7 @@ void CK3::World::linkMothersAndFathers() {


void CK3::World::importImperatorFamilies(const Imperator::World& impWorld) {
LOG(LogLevel::Info) << "-> Importing Imperator Families";
Log(LogLevel::Info) << "-> Importing Imperator Families";

// dynasties only holds dynasties converted from Imperator families, as vanilla ones aren't modified
for (const auto& family : impWorld.getFamilies() | std::views::values) {
Expand All @@ -437,5 +437,5 @@ void CK3::World::importImperatorFamilies(const Imperator::World& impWorld) {
auto newDynasty = make_shared<Dynasty>(*family, localizationMapper);
dynasties.emplace(newDynasty->getID(), newDynasty);
}
LOG(LogLevel::Info) << ">> " << dynasties.size() << " total families imported.";
Log(LogLevel::Info) << ">> " << dynasties.size() << " total families imported.";
}
4 changes: 2 additions & 2 deletions ImperatorToCK3/Source/CK3/Titles/TitlesHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

CK3::TitlesHistory::TitlesHistory(const std::string& folderPath) {
auto filenames = commonItems::GetAllFilesInFolderRecursive(folderPath);
LOG(LogLevel::Info) << "-> Parsing title history.";
Log(LogLevel::Info) << "-> Parsing title history.";
registerKeys();
for (const auto& fileName : filenames) {
parseFile(folderPath + "/" + fileName);
}
clearRegisteredKeywords();
LOG(LogLevel::Info) << "<> Loaded " << historyMap.size() << " title histories.";
Log(LogLevel::Info) << "<> Loaded " << historyMap.size() << " title histories.";
}

std::optional<CK3::TitleHistory> CK3::TitlesHistory::popTitleHistory(const std::string& titleName) {
Expand Down
20 changes: 10 additions & 10 deletions ImperatorToCK3/Source/CK3Outputter/CK3WorldOutputter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,42 @@ void createFolders(const std::string& outputName);


void CK3::outputWorld(const World& CK3World, const Configuration& theConfiguration) {
LOG(LogLevel::Info) << "<- Clearing the output mod folder";
Log(LogLevel::Info) << "<- Clearing the output mod folder";
std::filesystem::remove_all("output/" + theConfiguration.getOutputModName());

const auto& outputName = theConfiguration.getOutputModName();
createModFolder(outputName);
outputModFile(outputName);

LOG(LogLevel::Info) << "<- Creating folders";
Log(LogLevel::Info) << "<- Creating folders";
createFolders(outputName);

LOG(LogLevel::Info) << "<- Writing Characters";
Log(LogLevel::Info) << "<- Writing Characters";
outputCharacters(outputName, CK3World.getCharacters());

LOG(LogLevel::Info) << "<- Writing Dynasties";
Log(LogLevel::Info) << "<- Writing Dynasties";
outputDynasties(outputName, CK3World.getDynasties());

LOG(LogLevel::Info) << "<- Writing Provinces";
Log(LogLevel::Info) << "<- Writing Provinces";
outputHistoryProvinces(outputName, CK3World.getProvinces(), CK3World.getTitles());

LOG(LogLevel::Info) << "<- Writing Landed Titles";
Log(LogLevel::Info) << "<- Writing Landed Titles";
outputTitles(outputName, theConfiguration.getCK3Path(), CK3World.getTitles(), theConfiguration.getImperatorDeJure());

LOG(LogLevel::Info) << "<- Writing Localization";
Log(LogLevel::Info) << "<- Writing Localization";
outputLocalization(theConfiguration.getImperatorPath(), outputName, CK3World, theConfiguration.getImperatorDeJure());

LOG(LogLevel::Info) << "<- Copying named colors";
Log(LogLevel::Info) << "<- Copying named colors";
commonItems::TryCopyFile(theConfiguration.getImperatorPath()+"/game/common/named_colors/default_colors.txt",
"output/" + theConfiguration.getOutputModName() + "/common/named_colors/imp_colors.txt");

LOG(LogLevel::Info) << "<- Copying Coats of Arms";
Log(LogLevel::Info) << "<- Copying Coats of Arms";
copyColoredEmblems(theConfiguration, outputName);
outputCoas(outputName, CK3World.getTitles());
commonItems::CopyFolder(theConfiguration.getImperatorPath() + "/game/gfx/coat_of_arms/patterns",
"output/" + theConfiguration.getOutputModName() + "/gfx/coat_of_arms/patterns");

LOG(LogLevel::Info) << "<- Copying blankMod files to output";
Log(LogLevel::Info) << "<- Copying blankMod files to output";
commonItems::CopyFolder("blankMod/output", "output/" + theConfiguration.getOutputModName());
}

Expand Down
10 changes: 5 additions & 5 deletions ImperatorToCK3/Source/Configuration/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ auto laFabricaDeColor = commonItems::Color::Factory{};


Configuration::Configuration(const commonItems::ConverterVersion& converterVersion) {
LOG(LogLevel::Info) << "Reading configuration file";
Log(LogLevel::Info) << "Reading configuration file";
registerKeys();
parseFile("configuration.txt");
clearRegisteredKeywords();
Expand All @@ -38,7 +38,7 @@ void Configuration::registerKeys() {
Log(LogLevel::Info) << "Save Game set to: " << SaveGamePath;
});
registerKeyword("ImperatorDirectory", [this](std::istream& theStream) { ImperatorPath = commonItems::getString(theStream); });
registerKeyword("ImperatorModsDirectory", [this](std::istream& theStream) { ImperatorModsPath = commonItems::getString(theStream); });
registerKeyword("ImperatorDocDirectory", [this](std::istream& theStream) { ImperatorDocsPath = commonItems::getString(theStream); });
registerKeyword("CK3directory", [this](std::istream& theStream) { CK3Path = commonItems::getString(theStream); });
registerKeyword("CK3ModsDirectory", [this](std::istream& theStream) { CK3ModsPath = commonItems::getString(theStream); });
registerKeyword("output_name", [this](std::istream& theStream) {
Expand Down Expand Up @@ -71,7 +71,7 @@ void Configuration::verifyImperatorPath() const {
throw std::runtime_error(ImperatorPath + " does not exist!");
if (!commonItems::DoesFileExist(ImperatorPath + "/binaries/imperator.exe"))
throw std::runtime_error(ImperatorPath + " does not contain Imperator: Rome!");
LOG(LogLevel::Info) << "\tI:R install path is " << ImperatorPath;
Log(LogLevel::Info) << "\tI:R install path is " << ImperatorPath;
}


Expand All @@ -80,7 +80,7 @@ void Configuration::verifyCK3Path() const {
throw std::runtime_error(CK3Path + " does not exist!");
if (!commonItems::DoesFileExist(CK3Path + "/binaries/ck3.exe"))
throw std::runtime_error(CK3Path + " does not contain Crusader Kings III!");
LOG(LogLevel::Info) << "\tCK3 install path is " << CK3Path;
Log(LogLevel::Info) << "\tCK3 install path is " << CK3Path;
}


Expand All @@ -93,7 +93,7 @@ void Configuration::setOutputName() {
outputModName = replaceCharacter(outputModName, ' ');

outputModName = commonItems::normalizeUTF8Path(outputModName);
LOG(LogLevel::Info) << "Using output name " << outputModName;
Log(LogLevel::Info) << "Using output name " << outputModName;
}

void Configuration::verifyImperatorVersion(const commonItems::ConverterVersion& converterVersion) const {
Expand Down
6 changes: 4 additions & 2 deletions ImperatorToCK3/Source/Configuration/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@



#include <set>
#include "ConverterVersion.h"
#include "Parser.h"



class Configuration: commonItems::parser {
public:
Configuration(const commonItems::ConverterVersion& converterVersion);
Expand All @@ -16,7 +18,7 @@ class Configuration: commonItems::parser {

[[nodiscard]] const auto& getSaveGamePath() const { return SaveGamePath; }
[[nodiscard]] const auto& getImperatorPath() const { return ImperatorPath; }
[[nodiscard]] const auto& getImperatorModsPath() const { return ImperatorModsPath; }
[[nodiscard]] const auto& getImperatorDocsPath() const { return ImperatorDocsPath; }
[[nodiscard]] const auto& getCK3Path() const { return CK3Path; }
[[nodiscard]] const auto& getCK3ModsPath() const { return CK3ModsPath; }
[[nodiscard]] const auto& getOutputModName() const { return outputModName; }
Expand All @@ -33,7 +35,7 @@ class Configuration: commonItems::parser {

std::string SaveGamePath;
std::string ImperatorPath;
std::string ImperatorModsPath;
std::string ImperatorDocsPath;
std::string CK3Path;
std::string CK3ModsPath;
std::string outputModName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Imperator::CharacterPortraitData::CharacterPortraitData(const std::string& dnaSt

auto accessoryGenes = genes->getAccessoryGenes().getGenes();

//LOG(LogLevel::Debug) << "ageSex: " << ageSexString;
//Log(LogLevel::Debug) << "ageSex: " << ageSexString;
const auto accessoryGenesIndex = genes->getAccessoryGenes().getIndex();
for (auto& [geneName, gene] : accessoryGenes) {
const auto geneIndex = gene.getIndex();
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/Source/Imperator/Genes/AccessoryGene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ const std::pair<const std::string, Imperator::AccessoryGeneTemplate>& Imperator:
if (geneTemplateItr.second.getIndex() == indexInDna)
return geneTemplateItr;
}
LOG(LogLevel::Warning) << "Could not find gene template by index from DNA";
Log(LogLevel::Warning) << "Could not find gene template by index from DNA";
return *geneTemplates.begin(); // fallback: return first element
}
Loading

0 comments on commit f1a847e

Please sign in to comment.