Skip to content

Commit

Permalink
Convert many 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 8bf9287 commit d054d01
Show file tree
Hide file tree
Showing 72 changed files with 993 additions and 2,573 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "Characters.h"
#include "../../Mappers/TraitScraper/TraitScraper.h"
#include "../Cultures/Cultures.h"
#include "../Cultures/Cultures.cs"
#include "../Dynasties/House.h"
#include "../Dynasties/Houses.h"
#include "../Religions/Faiths.h"
#include "../Religions/Faiths.cs"
#include "../Titles/Title.h"
#include "../Titles/Titles.h"
#include "../Titles/Titles.cs"
#include "Character.h"
#include "CharacterDomain.h"
#include "CommonRegexes.h"
Expand Down
File renamed without changes.
59 changes: 59 additions & 0 deletions CK3ToEU4/Source/CK3/CoatsOfArms/CoatsOfArms.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

namespace CK3ToEU4.CK3.CoatsOfArms;

class CoatsOfArms
{
public CoatsOfArms()
{
}

public CoatsOfArms(std::istream& theStream)
{
registerKeys();
parseStream(theStream);
clearRegisteredKeywords();
}
public auto getCoats() const { return coats; }

public void linkParents(const Titles& titles)
{
auto counter = 0;
const auto& titleData = titles.getTitles();
for (const auto& coat: coats)
{
if (!coat.second->getParent())
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!");
if (!coats.count(titleDataItr->second->getCoA()->first))
throw std::runtime_error(
"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!");
}
}
Log(LogLevel::Info) << "<> " << counter << " coats updated.";
}

:
private void registerKeys()
{
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));
});
registerKeyword("coat_of_arms_manager_database", [this](const std::string& unused, std::istream& theStream) {
coats = CoatsOfArms(theStream).getCoats();
});
registerRegex(commonItems::catchallRegex, commonItems::ignoreItem);
}

private std::map<long long, std::shared_ptr<CoatOfArms>> coats;
};
16 changes: 8 additions & 8 deletions CK3ToEU4/Source/CK3/CoatsOfArms/EmblemInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ public EmblemInstance(BufferedReader reader)

private void RegisterKeys(Parser parser)
{
registerKeyword("rotation", [this](const std::string& unused, std::istream& theStream) {
rotation = commonItems::singleDouble(theStream).getDouble();
parser.RegisterKeyword("rotation", reader => {
rotation = reader.GetDouble();
});
registerKeyword("depth", [this](const std::string& unused, std::istream& theStream) {
depth = commonItems::singleDouble(theStream).getDouble();
parser.RegisterKeyword("depth", reader => {
depth = reader.GetDouble();
});
registerKeyword("position", [this](const std::string& unused, std::istream& theStream) {
parser.RegisterKeyword("position", reader => {
position = commonItems::doubleList(theStream).getDoubles();
});
registerKeyword("scale", [this](const std::string& unused, std::istream& theStream) {
parser.RegisterKeyword("scale", reader => {
scale = commonItems::doubleList(theStream).getDoubles();
});
registerKeyword("offset", [this](const std::string& unused, std::istream& theStream) {
parser.RegisterKeyword("offset", reader => {
offset = commonItems::doubleList(theStream).getDoubles();
});
registerRegex(commonItems::catchallRegex, commonItems::ignoreItem);
parser.RegisterRegex(CommonRegexes.Catchall, ParserHelpers.IgnoreItem);
}

public void DefaultPosition()
Expand Down
160 changes: 160 additions & 0 deletions CK3ToEU4/Source/CK3/Cultures/Culture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
using System.Collections.Generic;
using commonItems;

namespace CK3ToEU4.CK3.Cultures
{
class Culture
{
public Culture() {}
public Culture(BufferedReader reader, long theID)
{
ID = theID;

var parser = new Parser();
registerKeys(parser);
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 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)
{
auto 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;
}
}

// 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)
{
name += *cultureMatch + "-";
}
else
{
Log(LogLevel::Warning) << "Mapping " << entry << " to an EU4 culture failed! Check mappings!";
name += entry + "-";
}
}
name += "culture";

// did we see this culture before, elsewhere?

if (cultureNamingCounter.contains(name))
{

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

dynamic = true;
}



private void registerKeys()
{
registerKeyword("culture_template", [this](std::istream& theStream) {
culture_template = commonItems::getString(theStream);
});
registerKeyword("name", [this](std::istream& theStream) {
localizedName = commonItems::getString(theStream);
});
registerKeyword("heritage", [this](std::istream& theStream) {
heritage = commonItems::getString(theStream);
});
registerKeyword("ethos", [this](std::istream& theStream) {
ethos = commonItems::singleString(theStream).getString();
});
registerKeyword("traditions", [this](std::istream& theStream) {
traditions = commonItems::getStrings(theStream);
});
registerKeyword("name_list", [this](std::istream& theStream) {
auto temp = commonItems::getString(theStream);
if (temp.size() > 10)
{
temp = temp.substr(10, temp.size()); // drop "name_list_", leave "polish"
nameLists.insert(temp);
}
});
registerRegex(commonItems::catchallRegex, commonItems::ignoreItem);
}

private long 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 std::string name; // calculated value from all of the above - can be either *eu4* culture, ck3 vanilla, or anything in between.
};
}
43 changes: 43 additions & 0 deletions CK3ToEU4/Source/CK3/Cultures/Cultures.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using CK3;

namespace CK3ToEU4.CK3.Cultures;

class Cultures: commonItems::parser
{
public Cultures() {}
public Cultures(std::istream& theStream)
{
registerKeys();
parseStream(theStream);
clearRegisteredKeywords();
}

public const auto& getCultures() const { return cultures; }
public void concoctCultures(const mappers::LocalizationMapper& localizationMapper, const mappers::CultureMapper& cultureMapper)
{
for (const auto& culture: cultures | std::views::values)
{
culture->concoctCultureName(localizationMapper, cultureMapper, cultureNamingCounter);
}
}



private void registerKeys()
{
registerRegex(R"(\d+)", [this](const std::string& cultureID, std::istream& theStream) {
auto newCulture = std::make_shared<Culture>(theStream, std::stoll(cultureID));
cultures.insert(std::pair(newCulture->getID(), newCulture));
});
registerKeyword("cultures", [this](std::istream& theStream) {
const auto scraper = Cultures(theStream);
cultures = scraper.getCultures();
});
registerRegex(commonItems::catchallRegex, commonItems::ignoreItem);
}



private std::map<long long, std::shared_ptr<Culture>> cultures;
private std::map<std::string, int> cultureNamingCounter;
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Dynasties.h"
#include "../CoatsOfArms/CoatsOfArms.h"
#include "../CoatsOfArms/CoatsOfArms.cs"
#include "CommonRegexes.h"
#include "Dynasty.h"
#include "Log.h"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
58 changes: 58 additions & 0 deletions CK3ToEU4/Source/CK3/Flags/Flags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef CK3_FLAGS_H
#define CK3_FLAGS_H
#include <set>

#include "Parser.h"

namespace CK3
{
class Flags: commonItems::parser
{
public:
Flags() = default;
explicit Flags(std::istream& theStream)
{
registerKeys();
parseStream(theStream);
clearRegisteredKeywords();

if (itemType == "flag" && !incomingFlag.empty())
flags.insert(incomingFlag);
}

[[nodiscard]] const auto& getFlags() const { return flags; }

private:
void registerKeys()
{
registerKeyword("list", [this](const std::string& unused, std::istream& theStream) {
for (const auto& blob: commonItems::blobList(theStream).getBlobs())
{
auto blobStream = std::stringstream(blob);
const auto scraper = Flags(blobStream);
const auto& foundFlags = scraper.getFlags();
flags.insert(foundFlags.begin(), foundFlags.end());
}
});
registerKeyword("item", [this](const std::string& unused, std::istream& theStream) {
const auto scraper = Flags(theStream);
const auto& foundFlags = scraper.getFlags();
flags.insert(foundFlags.begin(), foundFlags.end());
});
registerKeyword("flag", [this](const std::string& unused, std::istream& theStream) {
incomingFlag = commonItems::singleString(theStream).getString();
});
registerKeyword("type", [this](const std::string& unused, std::istream& theStream) {
itemType = commonItems::singleString(theStream).getString();
});
registerRegex(commonItems::catchallRegex, commonItems::ignoreItem);
}


std::string itemType;
std::string incomingFlag;
std::set<std::string> flags;
};
} // namespace CK3

#endif // CK3_FLAGS_H
Loading

0 comments on commit d054d01

Please sign in to comment.