Skip to content

Commit

Permalink
Convert more cpp files to WIP csharp files
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains committed Oct 1, 2024
1 parent d054d01 commit 2293dd5
Show file tree
Hide file tree
Showing 42 changed files with 893 additions and 1,039 deletions.
4 changes: 2 additions & 2 deletions CK3ToEU4/Source/CK3/Characters/Characters.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "Characters.h"
#include "../../Mappers/TraitScraper/TraitScraper.h"
#include "../Cultures/Cultures.cs"
#include "../Dynasties/House.h"
#include "../Dynasties/Houses.h"
#include "../Dynasties/House.cs"
#include "../Dynasties/Houses.cs"
#include "../Religions/Faiths.cs"
#include "../Titles/Title.h"
#include "../Titles/Titles.cs"
Expand Down
49 changes: 27 additions & 22 deletions CK3ToEU4/Source/CK3/CoatsOfArms/CoatsOfArms.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

using System;
using System.Collections.Generic;
using commonItems;
using commonItems.Colors;

namespace CK3ToEU4.CK3.CoatsOfArms;

class CoatsOfArms
Expand All @@ -7,53 +12,53 @@ public CoatsOfArms()
{
}

public CoatsOfArms(std::istream& theStream)
public CoatsOfArms(BufferedReader reader, ColorFactory colorFactory)
{
registerKeys();
parseStream(theStream);
clearRegisteredKeywords();
var parser = new Parser();
registerKeys(parser, colorFactory);
parser.ParseStream(reader);
}
public auto getCoats() const { return coats; }
public IReadOnlyDictionary<long, CoatOfArms> Coats => coats;
private Dictionary<long, CoatOfArms> coats;

public void linkParents(const Titles& titles)
public void linkParents(Titles.Titles titles)
{
auto counter = 0;
const auto& titleData = titles.getTitles();
for (const auto& coat: coats)
int counter = 0;
var titleData = titles.getTitles();
foreach (var coat in coats)
{
if (!coat.second->getParent())
if (coat.Value.Parent is null)
continue;
const auto& titleDataItr = titleData.find(coat.second->getParent()->first);
if (titleDataItr != titleData.end())
{
if (!titleDataItr->second->getCoA())
throw std::runtime_error("CoA " + std::to_string(coat.first) + " has parent " + coat.second->getParent()->first + " which has no coat defined!");
throw new Exception("CoA " + std::to_string(coat.first) + " has parent " + coat.second->getParent()->first + " which has no coat defined!");
if (!coats.count(titleDataItr->second->getCoA()->first))
throw std::runtime_error(
throw new Exception(
"CoA " + std::to_string(coat.first) + " has parent " + coat.second->getParent()->first + " which has invalid coat defined!");
coat.second->loadParent(std::make_pair(coat.second->getParent()->first, coats[titleDataItr->second->getCoA()->first]));
++counter;
}
else
{
throw std::runtime_error("CoA " + std::to_string(coat.first) + " has parent " + coat.second->getParent()->first + " which is undefined!");
throw new Exception("CoA " + std::to_string(coat.first) + " has parent " + coat.second->getParent()->first + " which is undefined!");
}
}
Log(LogLevel::Info) << "<> " << counter << " coats updated.";
Logger.Info("<> " + counter + " coats updated.");
}

:
private void registerKeys()
private void registerKeys(Parser parser, ColorFactory colorFactory)
{
registerRegex(R"(\d+)", [this](const std::string& coaID, std::istream& theStream) {
auto newCoA = std::make_shared<CoatOfArms>(theStream, std::stoll(coaID));
coats.insert(std::pair(newCoA->getID(), newCoA));
parser.RegisterRegex(CommonRegexes.Integer, (reader, coaID) => {
var newCoA = new CoatOfArms(reader, long.Parse(coaID), colorFactory);
coats[newCoA.Id] = newCoA;
});
registerKeyword("coat_of_arms_manager_database", [this](const std::string& unused, std::istream& theStream) {
coats = CoatsOfArms(theStream).getCoats();
parser.RegisterKeyword("coat_of_arms_manager_database", reader => {
coats = new (new CoatsOfArms(reader, colorFactory).Coats);
});
registerRegex(commonItems::catchallRegex, commonItems::ignoreItem);
parser.RegisterRegex(CommonRegexes.Catchall, ParserHelpers.IgnoreItem);
}

private std::map<long long, std::shared_ptr<CoatOfArms>> coats;
};
10 changes: 5 additions & 5 deletions CK3ToEU4/Source/CK3/CoatsOfArms/EmblemInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ public EmblemInstance(BufferedReader reader)
private void RegisterKeys(Parser parser)
{
parser.RegisterKeyword("rotation", reader => {
rotation = reader.GetDouble();
Rotation = reader.GetDouble();
});
parser.RegisterKeyword("depth", reader => {
depth = reader.GetDouble();
Depth = reader.GetDouble();
});
parser.RegisterKeyword("position", reader => {
position = commonItems::doubleList(theStream).getDoubles();
position = reader.GetDoubles();
});
parser.RegisterKeyword("scale", reader => {
scale = commonItems::doubleList(theStream).getDoubles();
scale = reader.GetDoubles();
});
parser.RegisterKeyword("offset", reader => {
offset = commonItems::doubleList(theStream).getDoubles();
offset = reader.GetDoubles();
});
parser.RegisterRegex(CommonRegexes.Catchall, ParserHelpers.IgnoreItem);
}
Expand Down
210 changes: 104 additions & 106 deletions CK3ToEU4/Source/CK3/Cultures/Culture.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System.Collections.Generic;
using commonItems;

namespace CK3ToEU4.CK3.Cultures
{
namespace CK3ToEU4.CK3.Cultures;

class Culture
{
public Culture() {}
public Culture(BufferedReader reader, long theID)
{
ID = theID;
Expand All @@ -15,146 +14,145 @@ public Culture(BufferedReader reader, long theID)
parser.ParseStream(reader);
}

public auto getID() const { return ID; }
public auto isEU4Ready() const { return eu4Ready; }
public auto isDynamic() const { return dynamic; }
public const auto& getLocalizedName() const { return localizedName; }
public const auto& getName() const { return name; }
public const auto& getNameLists() const { return nameLists; }
public const auto& getHeritage() const { return heritage; }
public const auto& getTemplate() const { return culture_template; }
public const auto& getEthos() const { return ethos; }
public const auto& getTraditions() const { return traditions; }
public long getID() { return ID; }
public bool isEU4Ready() { return eu4Ready; }
public bool isDynamic() { return dynamic; }
public const auto& getLocalizedName() { return localizedName; }
public const auto& getName() { return name; }
public const auto& getNameLists() { return nameLists; }
public const auto& getHeritage() { return heritage; }
public const auto& getTemplate() { return culture_template; }
public string getEthos() { return ethos; }
public const auto& getTraditions() { return traditions; }

public void setDynamic() { dynamic = true; }
public void concoctCultureName(LocalizationMapper localizationMapper,
CultureMapper cultureMapper,
Dictionary<string, int> cultureNamingCounter)
{
/* This function is responsible for determining what a culture is and where it's going. Base/vanilla cultures are known to us but
* hybrids and divergences most certainly are not. We can try to normalize some of them like Swiss (hybrid) or Austrian (divergence) into
* eu4 cultures (sidestepping cultural mapping altogether), and if that fails we can generate dynamic cultures and file them in culture
* groups according to their heritages. In this function we do the first half.
*/

// Is this a base ck3 culture?
if (culture_template)
{
name = *culture_template;
return;
}

// Does this culture have a name? If not that means the player was very funny. We'll do the same.
if (!localizedName)
{
name = "noname";
return;
}

/* We have a divergent culture. Hybrids and divergents are by definition eu4-ready cultures but:
* 1. we allow for overrides using "ck3 = culture" mappings
* 2. not all of them have eu4 definitions which we'll have to generate.
* If a culture is not in "eu4 = " target block then 2) applies and we need to know this.
*/

// Can we reverse map it via localization into some common base like "austrian"?
const auto& match = localizationMapper.reverseLookupCultureName(*localizedName);
if (match)
CultureMapper cultureMapper,
Dictionary<string, int> cultureNamingCounter)
{
auto strippedName = *match;
strippedName = strippedName.substr(0, strippedName.size() - 5);
if (cultureMapper.getTargetCultures().contains(strippedName))
/* This function is responsible for determining what a culture is and where it's going. Base/vanilla cultures are known to us but
* hybrids and divergences most certainly are not. We can try to normalize some of them like Swiss (hybrid) or Austrian (divergence) into
* eu4 cultures (sidestepping cultural mapping altogether), and if that fails we can generate dynamic cultures and file them in culture
* groups according to their heritages. In this function we do the first half.
*/

// Is this a base ck3 culture?
if (culture_template)
{
// this is a full-flegded eu4 culture with predefined definitions.
name = strippedName;
eu4Ready = true;
name = *culture_template;
return;
}

if (cultureMapper.getSourceCultures().contains(strippedName))
// Does this culture have a name? If not that means the player was very funny. We'll do the same.
if (!localizedName)
{
// this is a culture we've mapped to something else. Proceed normally as if it were vanilla ck3 culture.
name = strippedName;
name = "noname";
return;
}
}

// Now everything else, we need to Concoct the culture name, finally.
name = "dynamic-";
for (const auto& entry: nameLists)
{
// Enery name component must be mapped to some base eu4 culture, so that eu4tovic2 can decompose it.
const auto& cultureMatch = cultureMapper.cultureNonRegionalNonReligiousMatch(entry, "", 0, "");
if (cultureMatch)
/* We have a divergent culture. Hybrids and divergents are by definition eu4-ready cultures but:
* 1. we allow for overrides using "ck3 = culture" mappings
* 2. not all of them have eu4 definitions which we'll have to generate.
* If a culture is not in "eu4 = " target block then 2) applies and we need to know this.
*/

// Can we reverse map it via localization into some common base like "austrian"?
var match = localizationMapper.reverseLookupCultureName(*localizedName);
if (match)
{
name += *cultureMatch + "-";
var strippedName = match;
strippedName = strippedName.substr(0, strippedName.size() - 5);
if (cultureMapper.getTargetCultures().contains(strippedName))
{
// this is a full-flegded eu4 culture with predefined definitions.
name = strippedName;
eu4Ready = true;
return;
}

if (cultureMapper.getSourceCultures().contains(strippedName))
{
// this is a culture we've mapped to something else. Proceed normally as if it were vanilla ck3 culture.
name = strippedName;
return;
}
}
else

// Now everything else, we need to Concoct the culture name, finally.
name = "dynamic-";
foreach (var entry in nameLists)
{
Log(LogLevel::Warning) << "Mapping " << entry << " to an EU4 culture failed! Check mappings!";
name += entry + "-";
// Enery name component must be mapped to some base eu4 culture, so that eu4tovic2 can decompose it.
var cultureMatch = cultureMapper.cultureNonRegionalNonReligiousMatch(entry, "", 0, "");
if (cultureMatch)
{
name += *cultureMatch + "-";
}
else
{
Log(LogLevel::Warning) << "Mapping " << entry << " to an EU4 culture failed! Check mappings!";
name += entry + "-";
}
}
}
name += "culture";
name += "culture";

// did we see this culture before, elsewhere?
// did we see this culture before, elsewhere?

if (cultureNamingCounter.contains(name))
{
if (cultureNamingCounter.contains(name))
{

++cultureNamingCounter.at(name);
name += "-num" + std::to_string(cultureNamingCounter.at(name));
}
else
{
cultureNamingCounter.emplace(name, 1);
name += "-num1";
}
++cultureNamingCounter.at(name);
name += "-num" + std::to_string(cultureNamingCounter.at(name));
}
else
{
cultureNamingCounter.emplace(name, 1);
name += "-num1";
}

dynamic = true;
}
dynamic = true;
}



private void registerKeys()
private void registerKeys(Parser parser)
{
registerKeyword("culture_template", [this](std::istream& theStream) {
culture_template = commonItems::getString(theStream);
parser.RegisterKeyword("culture_template", reader => {
culture_template = reader.GetString();
});
registerKeyword("name", [this](std::istream& theStream) {
localizedName = commonItems::getString(theStream);
parser.RegisterKeyword("name", reader => {
localizedName = reader.GetString();
});
registerKeyword("heritage", [this](std::istream& theStream) {
heritage = commonItems::getString(theStream);
parser.RegisterKeyword("heritage", reader => {
heritage = reader.GetString();
});
registerKeyword("ethos", [this](std::istream& theStream) {
ethos = commonItems::singleString(theStream).getString();
parser.RegisterKeyword("ethos", reader => {
ethos = reader.GetString();
});
registerKeyword("traditions", [this](std::istream& theStream) {
traditions = commonItems::getStrings(theStream);
parser.RegisterKeyword("traditions", reader => {
traditions = reader.GetStrings();
});
registerKeyword("name_list", [this](std::istream& theStream) {
auto temp = commonItems::getString(theStream);
if (temp.size() > 10)
parser.RegisterKeyword("name_list", reader => {
var temp = reader.GetString();
if (temp.Length > 10)
{
temp = temp.substr(10, temp.size()); // drop "name_list_", leave "polish"
nameLists.insert(temp);
}
});
registerRegex(commonItems::catchallRegex, commonItems::ignoreItem);
parser.RegisterRegex(CommonRegexes.Catchall, ParserHelpers.IgnoreItem);
}

private long long ID = 0;
private long ID = 0;
private bool eu4Ready = false; // this culture has eu4 match and needs zero processing
private bool dynamic = false; // this culture is dynamic and will need generation of cultural data

private std::optional<std::string> culture_template; // this has data only for base ck3 cultures, like czech or german
private std::optional<std::string> localizedName; // this can be anything - user input or localized name in a particular language game is running.
private std::string heritage; // all cultures should have this.
private std::set<std::string> nameLists; // We use these to generate dynamic culture code names, in lack of a better solution.
private std::string ethos; // used to generate custom ideas for custom tags with a custom culture
private std::vector<std::string> traditions; // used to generate custom ideas for custom tags with a custom culture
private string? culture_template; // this has data only for base ck3 cultures, like czech or german
private string? localizedName; // this can be anything - user input or localized name in a particular language game is running.
private string heritage; // all cultures should have this.
private HashSet<string> nameLists; // We use these to generate dynamic culture code names, in lack of a better solution.
private string ethos; // used to generate custom ideas for custom tags with a custom culture
private std::vector<string> traditions; // used to generate custom ideas for custom tags with a custom culture

private std::string name; // calculated value from all of the above - can be either *eu4* culture, ck3 vanilla, or anything in between.
};
}
private string name; // calculated value from all of the above - can be either *eu4* culture, ck3 vanilla, or anything in between.
};
Loading

0 comments on commit 2293dd5

Please sign in to comment.