-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert many cpp files to WIP csharp files
- Loading branch information
1 parent
8bf9287
commit d054d01
Showing
72 changed files
with
993 additions
and
2,573 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
...Source/CK3World/Characters/Characters.cpp → ...oEU4/Source/CK3/Characters/Characters.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
2 changes: 1 addition & 1 deletion
2
...4/Source/CK3World/Dynasties/Dynasties.cpp → CK3ToEU4/Source/CK3/Dynasties/Dynasties.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.