-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.cpp
101 lines (91 loc) · 2.64 KB
/
main.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <stdio.h>
#include <stdlib.h>
#include "draw.h"
#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <unistd.h>
#include "include/config.h"
#include "include/abstractrule.h"
#include "include/boardgraph.h"
#include "include/textrenderer.h"
using namespace std;
const int CLI_ARG_ERROR_CODE = 1;
const int CONFIG_PARSE_ERROR_CODE = 2;
// Command line arguments
// -c [Config file path]
// -l [float hex side length]
// -r [float chit radius]
// -m [float margin size]
// -R
// -f [output file name]
// -h
int main(int argc, char **argv)
{
srand(time(NULL));
Catan::Generate::Config config;
fstream fin;
string contents;
float length = 400.0f;
float radius = 100.0f;
float margin = 5.0f;
bool random = false;
string filename = "board.png";
// Handle command line arguments
int c;
while ((c = getopt(argc, argv, "c:l:r:m:f:Rh")) != -1)
{
switch (c)
{
case 'c':
fin = fstream(optarg);
contents = string((istreambuf_iterator<char>(fin)), istreambuf_iterator<char>());
try
{
config = Catan::Generate::Config(contents.c_str());
}
catch (...)
{
return CONFIG_PARSE_ERROR_CODE;
}
break;
case 'l':
length = stof(optarg);
break;
case 'r':
radius = stof(optarg);
break;
case 'm':
margin = stof(optarg);
break;
case 'R':
random = true;
break;
case 'f':
filename = optarg;
break;
case 'h':
cout << "Commands for catangen:" << endl;
cout << "-c [Config file path] (required)" << endl;
cout << "-l [float hex side length in pixels] (optional)" << endl;
cout << "-r [float chit radius length in pixels] (optional)" << endl;
cout << "-m [float margin size in pixels] (optional)" << endl;
cout << "-R (optional) Random chit and tile orientations" << endl;
cout << "-f [output file name]" << endl;
cout << "-h (optional) Display help" << endl;
return 0;
}
}
if (!config.initialized)
return CLI_ARG_ERROR_CODE;
Catan::Generate::BoardGraph graph = Catan::Generate::BoardGraph(&config);
graph.RandomizeWithRules();
Catan::Draw::RenderAsText(graph);
if (Catan::Draw::Initialize())
{
Catan::Draw::Render(graph, length, radius, margin, random, filename.c_str());
Catan::Draw::Uninitialize();
}
return 0;
}