-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
ConverterVersion.cpp
84 lines (73 loc) · 2.45 KB
/
ConverterVersion.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "ConverterVersion.h"
#include "CommonRegexes.h"
#include "ParserHelpers.h"
#include <fstream>
void commonItems::ConverterVersion::loadVersion(const std::string& filename)
{
registerKeys();
parseFile(filename);
clearRegisteredKeywords();
}
void commonItems::ConverterVersion::loadVersion(std::istream& theStream)
{
registerKeys();
parseStream(theStream);
clearRegisteredKeywords();
}
void commonItems::ConverterVersion::registerKeys()
{
registerSetter("name", name);
registerSetter("version", version);
registerSetter("source", source);
registerSetter("target", target);
registerKeyword("minSource", [this](std::istream& theStream) {
minSource = GameVersion(getString(theStream));
});
registerKeyword("maxSource", [this](std::istream& theStream) {
maxSource = GameVersion(getString(theStream));
});
registerKeyword("minTarget", [this](std::istream& theStream) {
minTarget = GameVersion(getString(theStream));
});
registerKeyword("maxTarget", [this](std::istream& theStream) {
maxTarget = GameVersion(getString(theStream));
});
registerRegex(catchallRegex, ignoreItem);
}
std::string commonItems::ConverterVersion::getDescription() const
{
auto toReturn = "Compatible with " + source + " [v" + minSource.toShortString();
if (maxSource != minSource)
toReturn += "-v" + maxSource.toShortString();
toReturn += "] and " + target + " [v" + minTarget.toShortString();
if (maxTarget != minTarget)
toReturn += "-v" + maxTarget.toShortString();
toReturn += "]";
return toReturn;
}
std::ostream& commonItems::operator<<(std::ostream& output, const ConverterVersion& version)
{
output << "\n\n";
output << "************ -= The Paradox Game Converters Group =- *****************\n";
if (!version.version.empty() && !version.name.empty())
output << "* Converter version " << version.version << " \"" << version.name << "\"\n";
output << "* " << version.getDescription() << "\n";
output << "* Built on " << __TIMESTAMP__ << "\n";
std::string footerTitle = " + " + version.source + " To " + version.target + " + ";
if (footerTitle.length() >= 68)
{
footerTitle = "*" + footerTitle + "*\n";
}
else
{
auto target = static_cast<int>((70 - footerTitle.length()) / 2);
for (auto counter = 0; counter < target; counter++)
footerTitle = "*" + footerTitle;
target = static_cast<int>(70 - footerTitle.length());
for (auto counter = 0; counter < target; counter++)
footerTitle += "*";
footerTitle += "\n";
}
output << footerTitle;
return output;
}