-
Notifications
You must be signed in to change notification settings - Fork 44
/
main.cpp
123 lines (99 loc) · 3.09 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* main.cpp
Copyright (c) 2015 by Michael Zahniser
Endless Sky is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later version.
Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
*/
#include "MainWindow.h"
#include "Map.h"
#include "SpriteSet.h"
#include <QApplication>
#include <QFileInfo>
#include <QFileOpenEvent>
#include <QString>
#include <iostream>
using namespace std;
class EventFilter: public QObject {
public:
EventFilter(MainWindow &window) : QObject(), window(window) {};
~EventFilter() {};
bool eventFilter(QObject *obj, QEvent *event)
{
if(event->type() == QEvent::FileOpen)
{
window.DoOpen(dynamic_cast<QFileOpenEvent *>(event)->file());
return true;
}
return obj->eventFilter(obj, event);
}
MainWindow &window;
};
void PrintHelp();
void PrintVersion();
int main(int argc, char *argv[])
{
QString path;
for(int i = 1; i < argc; ++i)
{
QString arg = argv[i];
if(arg == "-v" || arg == "--version")
{
PrintVersion();
return 0;
}
else if(arg[0] != '-')
path = arg;
else
{
PrintHelp();
return 0;
}
}
if(path.isEmpty())
{
#if defined __APPLE__
path = "/Applications/Endless Sky.app/Contents/Resources/data/map.txt";
#elif defined _WIN32
path = "C:/Program Files/Endless Sky/data/map.txt";
#else
path = "/usr/share/games/endless-sky/data/map.txt";
#endif
if(!path.isEmpty() && !QFileInfo(path).exists())
path.clear();
}
#if defined _WIN32
path.replace('\\', '/');
#endif
QApplication app(argc, argv);
Map mapData;
if(!path.isEmpty())
mapData.Load(path);
MainWindow window(mapData);
app.installEventFilter(new EventFilter(window));
return app.exec();
}
void PrintHelp()
{
cerr << endl;
cerr << "Command line options:" << endl;
cerr << " -h, --help: print this help message." << endl;
cerr << " -v, --version: print version information." << endl;
cerr << " <path to map.txt>: load the given map file." << endl;
cerr << " Sprites are then loaded from ../images/ relative to the map file." << endl;
cerr << endl;
cerr << "Report bugs to: [email protected]" << endl;
cerr << "Home page: <https://endless-sky.github.io>" << endl;
cerr << endl;
}
void PrintVersion()
{
cerr << endl;
cerr << "Endless Sky Editor v. 0.7.10" << endl;
cerr << "License GPLv3+: GNU GPL version 3 or later: <https://gnu.org/licenses/gpl.html>" << endl;
cerr << "This is free software: you are free to change and redistribute it." << endl;
cerr << "There is NO WARRANTY, to the extent permitted by law." << endl;
cerr << endl;
}