Skip to content

Commit 4e46726

Browse files
author
Ivo Elezović
authored
swap version to commons (#240)
* swap version to commons * fixes * typo
1 parent 9553722 commit 4e46726

File tree

15 files changed

+168
-133
lines changed

15 files changed

+168
-133
lines changed
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
# Version info
22

3-
descriptionLine = "Compatible with I:R 2.0 and CK3 1.4"
3+
source = "Imperator"
4+
minSource = "2.0"
5+
maxSource = "2.0"
6+
target = "CK3"
7+
minTarget = "1.4"
8+
maxTarget = "1.4"

ImperatorToCK3/Source/CK3/CK3World.h

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,58 @@
33

44

55

6-
#include "Mappers/LocalizationMapper/LocalizationMapper.h"
7-
#include "Mappers/TagTitleMapper/TagTitleMapper.h"
6+
#include "Character/CK3Character.h"
7+
#include "ConverterVersion.h"
8+
#include "Dynasties/Dynasty.h"
9+
#include "Mappers/CoaMapper/CoaMapper.h"
810
#include "Mappers/CultureMapper/CultureMapper.h"
911
#include "Mappers/DeathReasonMapper/DeathReasonMapper.h"
10-
#include "Mappers/ReligionMapper/ReligionMapper.h"
11-
#include "Mappers/ProvinceMapper/ProvinceMapper.h"
12-
#include "Mappers/CoaMapper/CoaMapper.h"
13-
#include "Mappers/TraitMapper/TraitMapper.h"
14-
#include "Mappers/NicknameMapper/NicknameMapper.h"
1512
#include "Mappers/GovernmentMapper/GovernmentMapper.h"
13+
#include "Mappers/LocalizationMapper/LocalizationMapper.h"
14+
#include "Mappers/NicknameMapper/NicknameMapper.h"
15+
#include "Mappers/ProvinceMapper/ProvinceMapper.h"
1616
#include "Mappers/RegionMapper/CK3RegionMapper.h"
1717
#include "Mappers/RegionMapper/ImperatorRegionMapper.h"
18+
#include "Mappers/ReligionMapper/ReligionMapper.h"
1819
#include "Mappers/SuccessionLawMapper/SuccessionLawMapper.h"
19-
#include "Character/CK3Character.h"
20-
#include "Dynasties/Dynasty.h"
20+
#include "Mappers/TagTitleMapper/TagTitleMapper.h"
21+
#include "Mappers/TraitMapper/TraitMapper.h"
2122
#include "Province/CK3Province.h"
2223
#include "Titles/LandedTitles.h"
2324
#include "Titles/TitlesHistory.h"
2425

2526

26-
2727
class Configuration;
2828

2929
namespace Imperator {
3030
class World;
3131
}
3232

33-
namespace commonItems {
34-
struct ConverterVersion;
35-
}
36-
3733
namespace CK3 {
3834

3935
class World {
40-
public:
36+
public:
4137
World(const Imperator::World& impWorld, const Configuration& theConfiguration, const commonItems::ConverterVersion& converterVersion);
4238

4339
[[nodiscard]] const auto& getCharacters() const { return characters; }
4440
[[nodiscard]] const auto& getDynasties() const { return dynasties; }
4541
[[nodiscard]] const auto& getTitles() const { return landedTitles.getTitles(); }
4642
[[nodiscard]] const auto& getProvinces() const { return provinces; }
4743

48-
private:
44+
private:
4945
void importImperatorCharacters(const Imperator::World& impWorld, bool ConvertBirthAndDeathDates, date endDate);
50-
void importImperatorCharacter(const std::pair<unsigned long long, std::shared_ptr<Imperator::Character>>& character, bool ConvertBirthAndDeathDates, date endDate);
46+
void importImperatorCharacter(const std::pair<unsigned long long, std::shared_ptr<Imperator::Character>>& character,
47+
bool ConvertBirthAndDeathDates,
48+
date endDate);
5149
void linkSpouses();
5250
void linkMothersAndFathers();
5351

5452
void importImperatorFamilies(const Imperator::World& impWorld);
55-
53+
5654
void importImperatorCountries(const std::map<unsigned long long, std::shared_ptr<Imperator::Country>>& imperatorCountries);
57-
void importImperatorCountry(const std::pair<unsigned long long, std::shared_ptr<Imperator::Country>>& country,
55+
void importImperatorCountry(const std::pair<unsigned long long, std::shared_ptr<Imperator::Country>>& country,
5856
const std::map<unsigned long long, std::shared_ptr<Imperator::Country>>& imperatorCountries);
59-
57+
6058
void importVanillaProvinces(const std::string& ck3Path);
6159
void importImperatorProvinces(const Imperator::World& impWorld);
6260

@@ -66,7 +64,8 @@ class World {
6664

6765
void purgeLandlessVanillaCharacters();
6866

69-
[[nodiscard]] std::optional<std::pair<unsigned long long, std::shared_ptr<Imperator::Province>>> determineProvinceSource(const std::vector<unsigned long long>& impProvinceNumbers,
67+
[[nodiscard]] std::optional<std::pair<unsigned long long, std::shared_ptr<Imperator::Province>>> determineProvinceSource(
68+
const std::vector<unsigned long long>& impProvinceNumbers,
7069
const Imperator::World& impWorld) const;
7170

7271

@@ -91,11 +90,11 @@ class World {
9190
TitlesHistory titlesHistory;
9291

9392

94-
std::set<std::string> countyHoldersCache; // used by removeInvalidLandlessTitles
93+
std::set<std::string> countyHoldersCache; // used by removeInvalidLandlessTitles
9594
};
9695

97-
}
96+
} // namespace CK3
9897

9998

10099

101-
#endif // CK3_WORLD_H
100+
#endif // CK3_WORLD_H
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#include "outVersion.h"
2+
#include <fstream>
23
#include "ConverterVersion.h"
34
#include "Log.h"
4-
#include <fstream>
55

66

77

88
void logConverterVersion(const commonItems::ConverterVersion& versionParser) {
99
// read commit id
1010
std::string commitID;
11-
std::ifstream commitIdFile{ "../commit_id.txt" };
11+
std::ifstream commitIdFile{"../commit_id.txt"};
1212
commitIdFile >> commitID;
1313
commitIdFile.close();
1414

1515
Log(LogLevel::Info) << "************ -= The Paradox Converters Team =- ********************";
1616
Log(LogLevel::Info) << "* Converter build based on commit " << commitID;
17-
Log(LogLevel::Info) << "* " << versionParser.descriptionLine;
17+
Log(LogLevel::Info) << "* " << versionParser.getDescription();
1818
Log(LogLevel::Info) << "* Built on " << __TIMESTAMP__;
1919
Log(LogLevel::Info) << "*********** + Imperator: Rome To Crusader Kings III + *************\n";
2020
}

ImperatorToCK3/Source/CK3Outputter/outVersion.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
#ifndef OUT_VERSION_H
22
#define OUT_VERSION_H
3+
#include "ConverterVersion.h"
34

45

5-
6-
namespace commonItems {
7-
struct ConverterVersion;
8-
} // namespace commonItems
9-
106
void logConverterVersion(const commonItems::ConverterVersion& versionParser);
117

128

ImperatorToCK3/Source/Configuration/Configuration.cpp

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
#include "Configuration.h"
22
#include "Color.h"
33
#include "CommonFunctions.h"
4+
#include "CommonRegexes.h"
45
#include "Log.h"
56
#include "OSCompatibilityLayer.h"
67
#include "ParserHelpers.h"
7-
#include "CommonRegexes.h"
88

99

1010

1111
auto laFabricaDeColor = commonItems::Color::Factory{};
1212

1313

14-
Configuration::Configuration() {
14+
Configuration::Configuration(const commonItems::ConverterVersion& converterVersion) {
1515
LOG(LogLevel::Info) << "Reading configuration file";
1616
registerKeys();
1717
parseFile("configuration.txt");
1818
clearRegisteredKeywords();
1919
setOutputName();
2020
verifyImperatorPath();
21+
verifyImperatorVersion(converterVersion);
2122
verifyCK3Path();
23+
verifyCK3Version(converterVersion);
2224
}
2325

2426

@@ -35,18 +37,10 @@ void Configuration::registerKeys() {
3537
SaveGamePath = commonItems::getString(theStream);
3638
Log(LogLevel::Info) << "Save Game set to: " << SaveGamePath;
3739
});
38-
registerKeyword("ImperatorDirectory", [this](std::istream& theStream) {
39-
ImperatorPath = commonItems::getString(theStream);
40-
});
41-
registerKeyword("ImperatorModsDirectory", [this](std::istream& theStream) {
42-
ImperatorModsPath = commonItems::getString(theStream);
43-
});
44-
registerKeyword("CK3directory", [this](std::istream& theStream) {
45-
CK3Path = commonItems::getString(theStream);
46-
});
47-
registerKeyword("CK3ModsDirectory", [this](std::istream& theStream) {
48-
CK3ModsPath = commonItems::getString(theStream);
49-
});
40+
registerKeyword("ImperatorDirectory", [this](std::istream& theStream) { ImperatorPath = commonItems::getString(theStream); });
41+
registerKeyword("ImperatorModsDirectory", [this](std::istream& theStream) { ImperatorModsPath = commonItems::getString(theStream); });
42+
registerKeyword("CK3directory", [this](std::istream& theStream) { CK3Path = commonItems::getString(theStream); });
43+
registerKeyword("CK3ModsDirectory", [this](std::istream& theStream) { CK3ModsPath = commonItems::getString(theStream); });
5044
registerKeyword("output_name", [this](std::istream& theStream) {
5145
outputModName = commonItems::getString(theStream);
5246
Log(LogLevel::Info) << "Output name set to: " << outputModName;
@@ -56,8 +50,7 @@ void Configuration::registerKeys() {
5650
try {
5751
imperatorDeJure = static_cast<IMPERATOR_DE_JURE>(stoi(deJureString));
5852
Log(LogLevel::Info) << "ImperatorDeJure set to: " << deJureString;
59-
}
60-
catch (const std::exception& e) {
53+
} catch (const std::exception& e) {
6154
Log(LogLevel::Error) << "Undefined error, ImperatorDeJure value was: " << deJureString << "; Error message: " << e.what();
6255
}
6356
});
@@ -91,9 +84,8 @@ void Configuration::verifyCK3Path() const {
9184
}
9285

9386

94-
void Configuration::setOutputName()
95-
{
96-
if (outputModName.empty()) {
87+
void Configuration::setOutputName() {
88+
if (outputModName.empty()) {
9789
outputModName = trimPath(SaveGamePath);
9890
}
9991
outputModName = trimExtension(outputModName);
@@ -102,4 +94,46 @@ void Configuration::setOutputName()
10294

10395
outputModName = commonItems::normalizeUTF8Path(outputModName);
10496
LOG(LogLevel::Info) << "Using output name " << outputModName;
105-
}
97+
}
98+
99+
void Configuration::verifyImperatorVersion(const commonItems::ConverterVersion& converterVersion) const {
100+
const auto ImpVersion = GameVersion::extractVersionFromLauncher(ImperatorPath + "/launcher/launcher-settings.json");
101+
if (!ImpVersion) {
102+
Log(LogLevel::Error) << "Imperator version could not be determined, proceeding blind!";
103+
return;
104+
}
105+
106+
Log(LogLevel::Info) << "Imperator version: " << ImpVersion->toShortString();
107+
108+
if (converterVersion.getMinSource() > *ImpVersion) {
109+
Log(LogLevel::Error) << "Imperator version is v" << ImpVersion->toShortString() << ", converter requires minimum v"
110+
<< converterVersion.getMinSource().toShortString() << "!";
111+
throw std::runtime_error("Converter vs Imperator installation mismatch!");
112+
}
113+
if (!converterVersion.getMaxSource().isLargerishThan(*ImpVersion)) {
114+
Log(LogLevel::Error) << "Imperator version is v" << ImpVersion->toShortString() << ", converter requires maximum v"
115+
<< converterVersion.getMaxSource().toShortString() << "!";
116+
throw std::runtime_error("Converter vs Imperator installation mismatch!");
117+
}
118+
}
119+
120+
void Configuration::verifyCK3Version(const commonItems::ConverterVersion& converterVersion) const {
121+
const auto CK3Version = GameVersion::extractVersionFromLauncher(CK3Path + "/launcher/launcher-settings.json");
122+
if (!CK3Version) {
123+
Log(LogLevel::Error) << "CK3 version could not be determined, proceeding blind!";
124+
return;
125+
}
126+
127+
Log(LogLevel::Info) << "CK3 version: " << CK3Version->toShortString();
128+
129+
if (converterVersion.getMinTarget() > *CK3Version) {
130+
Log(LogLevel::Error) << "CK3 version is v" << CK3Version->toShortString() << ", converter requires minimum v"
131+
<< converterVersion.getMinTarget().toShortString() << "!";
132+
throw std::runtime_error("Converter vs CK3 installation mismatch!");
133+
}
134+
if (!converterVersion.getMaxTarget().isLargerishThan(*CK3Version)) {
135+
Log(LogLevel::Error) << "CK3 version is v" << CK3Version->toShortString() << ", converter requires maximum v"
136+
<< converterVersion.getMaxTarget().toShortString() << "!";
137+
throw std::runtime_error("Converter vs CK3 installation mismatch!");
138+
}
139+
}

ImperatorToCK3/Source/Configuration/Configuration.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44

55

6+
#include "ConverterVersion.h"
67
#include "Parser.h"
78

89

9-
1010
class Configuration: commonItems::parser {
1111
public:
12-
Configuration();
12+
Configuration(const commonItems::ConverterVersion& converterVersion);
1313
explicit Configuration(std::istream& theStream);
1414

1515
enum class IMPERATOR_DE_JURE { REGIONS = 1, COUNTRIES = 2, NO = 3 };
@@ -28,6 +28,8 @@ class Configuration: commonItems::parser {
2828
void setOutputName();
2929
void verifyImperatorPath() const;
3030
void verifyCK3Path() const;
31+
void verifyImperatorVersion(const commonItems::ConverterVersion& converterVersion) const;
32+
void verifyCK3Version(const commonItems::ConverterVersion& converterVersion) const;
3133

3234
std::string SaveGamePath;
3335
std::string ImperatorPath;
@@ -42,4 +44,4 @@ class Configuration: commonItems::parser {
4244

4345

4446

45-
#endif // CONFIGURATION_H
47+
#endif // CONFIGURATION_H

0 commit comments

Comments
 (0)