-
Notifications
You must be signed in to change notification settings - Fork 0
/
ygo-calc.cpp
75 lines (68 loc) · 1.73 KB
/
ygo-calc.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
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <filesystem>
#include <yaml-cpp/yaml.h>
#include "deck.h"
#include "context.h"
#include "simulator.h"
using namespace std;
namespace fs = std::filesystem;
using namespace YGO;
string interactiveInputFile()
{
cout << "please input config path (*.yml): " << flush;
string path;
cin >> path;
return path;
}
void checkPath(const string& path)
{
const fs::path fpath{ path };
if (!fs::exists(fpath))
{
cout << "file doesn't exist: " << fs::absolute(fpath) << endl;
panic("");
}
const fs::file_status status = fs::status(fpath);
if (status.type() != fs::file_type::regular)
{
cout << fpath << " is not a valid file" << endl;
panic("");
}
}
int main(int argc, char **argv)
{
UTF8CodePage use_utf8;
if (argc > 2)
{
panic("Usage: ./ygo-calc.exe <deck.yml>");
}
string path = argc == 1 ? interactiveInputFile() : argv[1];
checkPath(path);
YAML::Node root = YAML::LoadFile(path);
Deck deck(root["deck"]);
cout << deck;
Context context;
for (auto& card : deck.cards())
{
context.addCardNameCondition(card);
}
YAML::Node conditions = root["deck"]["alias"];
if (conditions.IsDefined())
{
for (auto it = conditions.begin(); it != conditions.end(); ++it)
{
auto conditionName = it->first.as<t_string>();
auto condition = it->second.as<t_string>();
context.addCondition(conditionName, Utils::parse(context, condition));
}
}
//context.print(cout);
//cout << endl;
Simulator simulator(root["simulate"]);
simulator.run(deck, context);
system("pause");
return 0;
}