Skip to content

Commit

Permalink
Country loc fix, submodules update (#182)
Browse files Browse the repository at this point in the history
* Ported a test fix from a different branch

* Bump librakaly to 0.8.3

* Update submodules

* Imperator::Country: adjective, locBase

* CountryNameFactory

* CountryName tweak

* Moved two function implementations to cpp file

* Fixed tests project

* Basic CountryName tests

* Removed some debug logging

* Imperator::CountryName::getNameLocBlock()

* Imperator::CountryName::getNameLocBlock()
  • Loading branch information
IhateTrains authored Apr 7, 2021
1 parent 9961979 commit d1c205e
Show file tree
Hide file tree
Showing 24 changed files with 370 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
uses: anothrNick/github-tag-action@master
env:
GITHUB_TOKEN: ${{ secrets.API_TOKEN_GITHUB }}
DEFAULT_BUMP: patch
DEFAULT_BUMP: none
2 changes: 1 addition & 1 deletion Fronter
Submodule Fronter updated 1 files
+1 −1 commonItems
2 changes: 2 additions & 0 deletions ImperatorToCK3/ImperatorToCK3.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
<ClCompile Include="Source\Imperator\Countries\CountryCurrencies.cpp" />
<ClCompile Include="Source\Imperator\Countries\CountryFactory.cpp" />
<ClCompile Include="Source\Imperator\Countries\CountryName.cpp" />
<ClCompile Include="Source\Imperator\Countries\CountryNameFactory.cpp" />
<ClCompile Include="Source\Imperator\Families\Families.cpp" />
<ClCompile Include="Source\Imperator\Families\Family.cpp" />
<ClCompile Include="Source\Imperator\Families\FamilyFactory.cpp" />
Expand Down Expand Up @@ -363,6 +364,7 @@
<ClInclude Include="Source\Imperator\Countries\CountryCurrencies.h" />
<ClInclude Include="Source\Imperator\Countries\CountryFactory.h" />
<ClInclude Include="Source\Imperator\Countries\CountryName.h" />
<ClInclude Include="Source\Imperator\Countries\CountryNameFactory.h" />
<ClInclude Include="Source\Imperator\Families\Families.h" />
<ClInclude Include="Source\Imperator\Families\Family.h" />
<ClInclude Include="Source\Imperator\Families\FamilyFactory.h" />
Expand Down
12 changes: 9 additions & 3 deletions ImperatorToCK3/ImperatorToCK3.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@
<ClInclude Include="..\commonItems\ConverterVersion.h">
<Filter>commonItems</Filter>
</ClInclude>
<ClInclude Include="Source\Imperator\Countries\CountryNameFactory.h">
<Filter>Imperator\Countries</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Source\main.cpp" />
Expand Down Expand Up @@ -470,9 +473,6 @@
<ClCompile Include="Source\Imperator\Countries\CountryCurrencies.cpp">
<Filter>Imperator\Countries</Filter>
</ClCompile>
<ClCompile Include="Source\Imperator\Countries\CountryName.cpp">
<Filter>Imperator\Countries</Filter>
</ClCompile>
<ClCompile Include="..\cpp-base64\base64.cpp">
<Filter>base64</Filter>
</ClCompile>
Expand Down Expand Up @@ -674,6 +674,12 @@
<ClCompile Include="..\commonItems\ConverterVersion.cpp">
<Filter>commonItems</Filter>
</ClCompile>
<ClCompile Include="Source\Imperator\Countries\CountryNameFactory.cpp">
<Filter>Imperator\Countries</Filter>
</ClCompile>
<ClCompile Include="Source\Imperator\Countries\CountryName.cpp">
<Filter>Imperator\Countries</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="Resources\rakaly.dll">
Expand Down
Binary file modified ImperatorToCK3/Resources/librakaly.so
Binary file not shown.
Binary file modified ImperatorToCK3/Resources/rakaly.dll
Binary file not shown.
Binary file modified ImperatorToCK3/Resources/rakaly.dll.lib
Binary file not shown.
13 changes: 7 additions & 6 deletions ImperatorToCK3/Source/CK3/CK3World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CK3::World::World(const Imperator::World& impWorld, const Configuration& theConf
// Load vanilla titles history
titlesHistory = TitlesHistory(theConfiguration);

importImperatorCountries(impWorld);
importImperatorCountries(impWorld.getCountries());

// Now we can deal with provinces since we know to whom to assign them. We first import vanilla province data.
// Some of it will be overwritten, but not all.
Expand Down Expand Up @@ -81,22 +81,23 @@ void CK3::World::importImperatorCharacter(const std::pair<unsigned long long, st
}


void CK3::World::importImperatorCountries(const Imperator::World& impWorld) {
void CK3::World::importImperatorCountries(const std::map<unsigned long long, std::shared_ptr<Imperator::Country>>& imperatorCountries) {
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 : impWorld.getCountries()) {
importImperatorCountry(title);
for (const auto& title : imperatorCountries) {
importImperatorCountry(title, imperatorCountries);
}
LOG(LogLevel::Info) << ">> " << getTitles().size() << " total countries recognized.";
}


void CK3::World::importImperatorCountry(const std::pair<unsigned long long, std::shared_ptr<Imperator::Country>>& country) {
void CK3::World::importImperatorCountry(const std::pair<unsigned long long, std::shared_ptr<Imperator::Country>>& country,
const std::map<unsigned long long, std::shared_ptr<Imperator::Country>>& imperatorCountries) {
// Create a new title
auto newTitle = std::make_shared<Title>();
newTitle->initializeFromTag(country.second, localizationMapper, landedTitles, provinceMapper, coaMapper, tagTitleMapper, governmentMapper, successionLawMapper);
newTitle->initializeFromTag(country.second, imperatorCountries, localizationMapper, landedTitles, provinceMapper, coaMapper, tagTitleMapper, governmentMapper, successionLawMapper);

const auto& name = newTitle->getName();
if (auto titleItr = getTitles().find(name); titleItr!=getTitles().end()) {
Expand Down
5 changes: 3 additions & 2 deletions ImperatorToCK3/Source/CK3/CK3World.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ class World {

void importImperatorFamilies(const Imperator::World& impWorld);

void importImperatorCountries(const Imperator::World& impWorld);
void importImperatorCountry(const std::pair<unsigned long long, std::shared_ptr<Imperator::Country>>& country);
void importImperatorCountries(const std::map<unsigned long long, std::shared_ptr<Imperator::Country>>& imperatorCountries);
void importImperatorCountry(const std::pair<unsigned long long, std::shared_ptr<Imperator::Country>>& country,
const std::map<unsigned long long, std::shared_ptr<Imperator::Country>>& imperatorCountries);

void importVanillaProvinces(const std::string& ck3Path);
void importImperatorProvinces(const Imperator::World& impWorld);
Expand Down
35 changes: 15 additions & 20 deletions ImperatorToCK3/Source/CK3/Titles/Title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "LandedTitles.h"
#include "TitlesHistory.h"
#include "Imperator/Countries/Country.h"
#include "Imperator/Countries/CountryName.h"
#include "Mappers/ProvinceMapper/ProvinceMapper.h"
#include "Mappers/CoaMapper/CoaMapper.h"
#include "Mappers/TagTitleMapper/TagTitleMapper.h"
Expand Down Expand Up @@ -74,6 +75,7 @@ void CK3::Title::registerKeys() {


void CK3::Title::initializeFromTag(std::shared_ptr<Imperator::Country> theCountry,
const std::map<unsigned long long, std::shared_ptr<Imperator::Country>>& imperatorCountries,
mappers::LocalizationMapper& localizationMapper,
LandedTitles& landedTitles,
mappers::ProvinceMapper& provinceMapper,
Expand All @@ -99,7 +101,7 @@ void CK3::Title::initializeFromTag(std::shared_ptr<Imperator::Country> theCountr
validatedName = localizationMapper.getLocBlockForKey("get_mry_name_fallback");
// normal case
else
validatedName = localizationMapper.getLocBlockForKey(imperatorCountry->getName());
validatedName = imperatorCountry->getCountryName().getNameLocBlock(localizationMapper, imperatorCountries);

std::optional<std::string> title;
if (validatedName)
Expand Down Expand Up @@ -150,22 +152,22 @@ void CK3::Title::initializeFromTag(std::shared_ptr<Imperator::Country> theCountr

auto nameSet = false;
if (validatedName) {
localizations.insert(std::pair(titleName, *validatedName));
localizations.emplace(titleName, *validatedName);
nameSet = true;
}
if (!nameSet) {
auto impTagLoc = localizationMapper.getLocBlockForKey(imperatorCountry->getTag());
if (impTagLoc) {
localizations.insert(std::pair(titleName, *impTagLoc));
localizations.emplace(titleName, *impTagLoc);
nameSet = true;
}
}
// giving up.
// giving up
if (!nameSet)
Log(LogLevel::Warning) << titleName << " help with localization! " << imperatorCountry->getName() << "?";
Log(LogLevel::Warning) << titleName << " needs help with localization! " << imperatorCountry->getName() << "?";

// --------------- Adjective Locs
trySetAdjectiveLoc(localizationMapper);
trySetAdjectiveLoc(localizationMapper, imperatorCountries);
}


Expand All @@ -189,7 +191,7 @@ void CK3::Title::updateFromTitle(const std::shared_ptr<Title>& otherTitle) {
}


void CK3::Title::trySetAdjectiveLoc(mappers::LocalizationMapper& localizationMapper) {
void CK3::Title::trySetAdjectiveLoc(mappers::LocalizationMapper& localizationMapper, const std::map<unsigned long long, std::shared_ptr<Imperator::Country>>& imperatorCountries) {
auto adjSet = false;

if (imperatorCountry->getTag() == "PRY" || imperatorCountry->getTag() == "SEL" || imperatorCountry->getTag() == "MRY") { // these tags use customizable loc for adj
Expand All @@ -207,29 +209,22 @@ void CK3::Title::trySetAdjectiveLoc(mappers::LocalizationMapper& localizationMap
}
}
if (!adjSet) {
auto adjLocalizationMatch = localizationMapper.getLocBlockForKey(imperatorCountry->getName() + "_ADJ");
if (adjLocalizationMatch) {
localizations.emplace(titleName + "_adj", *adjLocalizationMatch);
adjSet = true;
}
}
if (!adjSet && !imperatorCountry->getName().empty()) { // if loc for <title name>_adj key doesn't exist, use title name (which is apparently what Imperator does
auto adjLocalizationMatch = localizationMapper.getLocBlockForKey(imperatorCountry->getName());
if (adjLocalizationMatch) {
localizations.emplace(titleName + "_adj", *adjLocalizationMatch);
const auto adjOpt = imperatorCountry->getCountryName().getAdjectiveLocBlock(localizationMapper, imperatorCountries);
if (adjOpt) {
localizations.emplace(titleName + "_adj", *adjOpt);
adjSet = true;
}
}
if (!adjSet) { // same as above, but with tag instead of name as fallback
if (!adjSet) { // final fallback
auto adjLocalizationMatch = localizationMapper.getLocBlockForKey(imperatorCountry->getTag());
if (adjLocalizationMatch) {
localizations.emplace(titleName + "_adj", *adjLocalizationMatch);
adjSet = true;
}
}
// giving up.
// giving up
if (!adjSet)
Log(LogLevel::Warning) << titleName << " help with localization for adjective! " << imperatorCountry->getName() << "_adj?";
Log(LogLevel::Warning) << titleName << " needs help with localization for adjective! " << imperatorCountry->getName() << "_adj?";
}


Expand Down
12 changes: 7 additions & 5 deletions ImperatorToCK3/Source/CK3/Titles/Title.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


#include "Mappers/LocalizationMapper/LocalizationMapper.h"
#include "Imperator/Countries/CountryName.h"
#include "Parser.h"
#include "Color.h"
#include <memory>
Expand Down Expand Up @@ -38,9 +39,10 @@ class Title: commonItems::parser, public std::enable_shared_from_this<Title>
Title() = default;
explicit Title(const std::string& name) { titleName = name; }
void initializeFromTag(
std::shared_ptr<Imperator::Country> theCountry,
mappers::LocalizationMapper& localizationMapper,
LandedTitles& landedTitles,
std::shared_ptr<Imperator::Country> theCountry,
const std::map<unsigned long long, std::shared_ptr<Imperator::Country>>& imperatorCountries,
mappers::LocalizationMapper& localizationMapper,
LandedTitles& landedTitles,
mappers::ProvinceMapper& provinceMapper,
mappers::CoaMapper& coaMapper,
mappers::TagTitleMapper& tagTitleMapper,
Expand All @@ -50,7 +52,8 @@ class Title: commonItems::parser, public std::enable_shared_from_this<Title>
void updateFromTitle(const std::shared_ptr<Title>& otherTitle);
void loadTitles(std::istream& theStream);

void setLocalizations(const mappers::LocBlock& newBlock) { localizations[titleName] = newBlock; } // Setting the name
void setLocalizations(const mappers::LocBlock& newBlock) { localizations[titleName] = newBlock; } // Setting the localized name
void trySetAdjectiveLoc(mappers::LocalizationMapper& localizationMapper, const std::map<unsigned long long, std::shared_ptr<Imperator::Country>>& imperatorCountries);
void addCountyProvince(const unsigned long long provinceId) { countyProvinces.emplace(provinceId); }
void addHistory(const LandedTitles& landedTitles, TitlesHistory& titlesHistory);

Expand Down Expand Up @@ -99,7 +102,6 @@ class Title: commonItems::parser, public std::enable_shared_from_this<Title>
static void addFoundTitle(const std::shared_ptr<Title>& newTitle, std::map<std::string, std::shared_ptr<Title>>& foundTitles);

void registerKeys();
void trySetAdjectiveLoc(mappers::LocalizationMapper& localizationMapper);

std::string titleName; // e.g. d_latium
std::set<std::string> successionLaws;
Expand Down
22 changes: 11 additions & 11 deletions ImperatorToCK3/Source/Helpers/rakaly.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern "C" {
*
* Must pass in a valid pointer to a `MeltedBuffer`
*/
int rakaly_melt_error_code(const MeltedBuffer *res);
int rakaly_melt_error_code(const struct MeltedBuffer *res);

/**
* Destroys a `MeltedBuffer` once you are done with it.
Expand All @@ -33,7 +33,7 @@ int rakaly_melt_error_code(const MeltedBuffer *res);
*
* Must pass in a valid pointer to a `MeltedBuffer`
*/
void rakaly_free_melt(MeltedBuffer *res);
void rakaly_free_melt(struct MeltedBuffer *res);

/**
* Returns the length of the melted data in bytes.
Expand All @@ -42,7 +42,7 @@ void rakaly_free_melt(MeltedBuffer *res);
*
* Must pass in a valid pointer to a `MeltedBuffer`
*/
size_t rakaly_melt_data_length(const MeltedBuffer *res);
size_t rakaly_melt_data_length(const struct MeltedBuffer *res);

/**
* Writes the melted data into a provided buffer that is a given length.
Expand All @@ -58,7 +58,7 @@ size_t rakaly_melt_data_length(const MeltedBuffer *res);
* - Must pass in a valid pointer to a `MeltedBuffer`
* - Given buffer must be at least the given length in size
*/
size_t rakaly_melt_write_data(const MeltedBuffer *res, char *buffer, size_t length);
size_t rakaly_melt_write_data(const struct MeltedBuffer *res, char *buffer, size_t length);

/**
* Melts binary encoded ironman data into normal plaintext data that can be understood by EU4
Expand All @@ -81,7 +81,7 @@ size_t rakaly_melt_write_data(const MeltedBuffer *res, char *buffer, size_t leng
* - Else the object value (or array value) will be string of "__unknown_x0$z" where z is the
* hexadecimal representation of the unknown token.
*/
MeltedBuffer *rakaly_eu4_melt(const char *data_ptr, size_t data_len);
struct MeltedBuffer *rakaly_eu4_melt(const char *data_ptr, size_t data_len);

/**
* Melts binary encoded CK3 data into normal plaintext data. The melted buffer will contain utf-8 encoded
Expand All @@ -104,8 +104,8 @@ MeltedBuffer *rakaly_eu4_melt(const char *data_ptr, size_t data_len);
* - Else the object value (or array value) will be string of "__unknown_x0$z" where z is the
* hexadecimal representation of the unknown token.
*/
MeltedBuffer *rakaly_ck3_melt(const char *data_ptr,
size_t data_len);
struct MeltedBuffer *rakaly_ck3_melt(const char *data_ptr,
size_t data_len);

/**
* Melts binary encoded Imperator data into normal plaintext data. The melted buffer will contain utf-8 encoded
Expand All @@ -127,8 +127,8 @@ MeltedBuffer *rakaly_ck3_melt(const char *data_ptr,
* - Else the object value (or array value) will be string of "__unknown_x0$z" where z is the
* hexadecimal representation of the unknown token.
*/
MeltedBuffer *rakaly_imperator_melt(const char *data_ptr,
size_t data_len);
struct MeltedBuffer *rakaly_imperator_melt(const char *data_ptr,
size_t data_len);

/**
* Melts binary encoded HOI4 data into normal plaintext data. The melted buffer will contain utf-8 encoded
Expand All @@ -148,8 +148,8 @@ MeltedBuffer *rakaly_imperator_melt(const char *data_ptr,
* - Else the object value (or array value) will be string of "__unknown_x0$z" where z is the
* hexadecimal representation of the unknown token.
*/
MeltedBuffer *rakaly_hoi4_melt(const char *data_ptr,
size_t data_len);
struct MeltedBuffer *rakaly_hoi4_melt(const char *data_ptr,
size_t data_len);

#ifdef __cplusplus
} // extern "C"
Expand Down
6 changes: 4 additions & 2 deletions ImperatorToCK3/Source/Imperator/Countries/Country.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@



#include "CountryName.h"
#include "Parser.h"
#include "Color.h"
#include <set>
Expand Down Expand Up @@ -41,7 +42,8 @@ class Country {
[[nodiscard]] auto getID() const { return ID; }
[[nodiscard]] auto getMonarch() const { return monarch; }
[[nodiscard]] const std::string& getTag() const { return tag; }
[[nodiscard]] const auto& getName() const { return name; }
[[nodiscard]] const auto& getName() const { return countryName.getName(); }
[[nodiscard]] const auto& getCountryName() const { return countryName; }
[[nodiscard]] const auto& getFlag() const { return flag; }
[[nodiscard]] const auto& getCountryType() const { return countryType; }
[[nodiscard]] const auto& getCapital() const { return capital; }
Expand All @@ -65,7 +67,7 @@ class Country {
uint64_t ID = 0;
std::optional<unsigned long long> monarch; // >=0 are valid
std::string tag;
std::string name;
CountryName countryName;
std::string flag;
countryTypeEnum countryType = countryTypeEnum::real;
std::optional<unsigned long long> capital;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Imperator::Country::Factory::Factory() {
country->tag = commonItems::getString(theStream);
});
registerKeyword("country_name", [this](std::istream& theStream) {
country->name = CountryName(theStream).getName();
country->countryName = std::move(*countryNameFactory.getCountryName(theStream));
});
registerKeyword("flag", [this](std::istream& theStream){
country->flag = commonItems::getString(theStream);
Expand Down
10 changes: 6 additions & 4 deletions ImperatorToCK3/Source/Imperator/Countries/CountryFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@



#include "ConvenientParser.h"
#include "Country.h"
#include "CountryNameFactory.h"
#include "Parser.h"
#include <memory>



namespace Imperator {

class Country::Factory: commonItems::convenientParser
class Country::Factory: commonItems::parser
{
public:
public:
explicit Factory();
std::unique_ptr<Country> getCountry(std::istream& theStream, unsigned long long countryID);

private:
private:
std::unique_ptr<Country> country;
CountryName::Factory countryNameFactory;
};

} // namespace Imperator
Expand Down
Loading

0 comments on commit d1c205e

Please sign in to comment.