-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·54 lines (43 loc) · 1.31 KB
/
main.cpp
File metadata and controls
executable file
·54 lines (43 loc) · 1.31 KB
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
/**
* Written by James Butcher
* 2018/04/12
*/
#include "dialog.h"
#include "game.h"
#include "utils.h"
#include "gamebuilder.h"
#include <QApplication>
#include <QFile>
#include <QString>
#include <QJsonObject>
#include <QJsonDocument>
#include <iostream>
QJsonObject loadConfig() {
// load json from config file
QFile conf_file(config_path);
conf_file.open(QIODevice::ReadOnly | QIODevice::Text);
QString content = conf_file.readAll();
conf_file.close();
QJsonObject config = QJsonDocument::fromJson(content.toUtf8()).object();
return config;
}
int main(int argc, char *argv[])
{
QJsonObject conf = loadConfig();
// create our game based on our config
GameDirector director(&conf);
director.setBuilder(new StageOneBuilder());
// // set it to be the stage two builder.. when do we choose the factory??
if (conf.contains("stage2") && conf.value("stage2").toBool())
director.setBuilder(new StageTwoBuilder());
else
director.setBuilder(new StageOneBuilder());
// set and transfer ownership of this builder to the director
Game* game = director.createGame();
// display our dialog that contains our game and run
QApplication a(argc, argv);
Dialog w(game, nullptr);
w.show();
qWarning("help!");
return a.exec();
}