-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
189 lines (165 loc) · 7.2 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QIcon>
#include "globals.h"
#include "i18n.h"
#include "credits.h"
#include "game/animationlibrary.h"
#include "game/inventoryitemlibrary.h"
#include "tilemap/tilemap.h"
#include "tilemap/tilelayer.h"
#include "tilemap/tilezone.h"
#include "tilemap/tile.h"
#include "game.h"
#include "game/dices.hpp"
#include "game/dynamicobject.h"
#include "game/objects/inventoryitem.h"
#include "game/objects/doorway.h"
#include "game/objects/elevator.h"
#include "game/objects/objectfactory.h"
#include "game/leveltask.h"
#include "game/characterdialog.h"
#include "game/lootingcontroller.h"
#include "gamemanager.h"
#include "musicmanager.h"
#include "game/soundmanager.h"
#include "game/characters/buff.h"
#include "game/characters/actionqueue.h"
#include "game/mousecursor.h"
#include "game/gamepadcontroller.h"
#include "game/savepreview.h"
#include "game/diplomacy.hpp"
#include "cmap/statmodel.h"
#include "editor/scripteditorcontroller.h"
#include "editor/characterdialogeditor.h"
#include "editor/leveleditorcontroller.h"
#include "editor/gameobjecttemplates.h"
#include <QResource>
QJSEngine* qmlJsEngine = nullptr;
void registerQmlTilemap() {
qmlRegisterType<TileMap> ("Tiles", 1,0, "TileMap");
qmlRegisterType<TileLayer>("Tiles", 1,0, "TileLayer");
qmlRegisterType<Tile> ("Tiles", 1,0, "Tile");
qmlRegisterType<TileZone> ("Tiles", 1,0, "TileZone");
}
int main(int argc, char *argv[])
{
auto fileProtocol = FILE_PROTOCOL;
auto rootPath = FILE_PROTOCOL + ROOT_PATH;
auto scriptPath = FILE_PROTOCOL + SCRIPTS_PATH;
auto assetPath = FILE_PROTOCOL + ASSETS_PATH;
QCoreApplication::setOrganizationName("Ile Noire Dev");
QCoreApplication::setOrganizationDomain("ile-noire.fr");
QCoreApplication::setApplicationName("Fallout Equestria RPG");
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
Dices::Initialize();
#ifdef GAME_EDITOR
QResource::registerResource("editor.rcc");
#endif
AnimationLibrary animationLibrary;
animationLibrary.initialize();
InventoryItemLibrary itemLibrary;
itemLibrary.initialize();
ScriptEditorController scriptEditorController;
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
MouseCursor* cursor = new MouseCursor(&app);
GamepadController* gamepad = new GamepadController(&app);
app.setWindowIcon(QIcon(":/assets/icon.ico"));
cursor->updatePointerType();
qmlRegisterType<I18n>("I18n", 1,0, "I18n");
qmlRegisterType<Game>("Game", 1,0, "Controller");
qmlRegisterType<SavePreview>("Game", 1,0, "SavePreview");
qmlRegisterType<StatModel>("Game", 1,0, "StatModel");
qmlRegisterType<Sprite>("Game", 1,0, "Sprite");
qmlRegisterType<DynamicObject>("Game", 1,0, "DynamicObject");
qmlRegisterType<Character>("Game", 1,0, "Character");
qmlRegisterType<StorageObject>("Game", 1,0, "StorageObject");
qmlRegisterType<Doorway>("Game", 1,0, "Doorway");
qmlRegisterType<Elevator>("Game", 1,0, "Elevator");
qmlRegisterType<InventoryItem>("Game", 1,0, "InventoryItem");
qmlRegisterType<Inventory>("Game", 1,0, "Inventory");
qmlRegisterType<CharacterDialog>("Game", 1,0, "CharacterDialog");
qmlRegisterType<LootingController>("Game", 1,0, "LootingController");
qmlRegisterType<GameManager>("Game", 1,0, "GameManager");
qmlRegisterType<MusicManager>("Game", 1,0, "MusicManager");
qmlRegisterType<SoundManager>("Game", 1,0, "SoundManager");
qmlRegisterType<QuestManager>("Game", 1,0, "QuestManager");
qmlRegisterType<Quest>("Game", 1,0, "Quest");
qmlRegisterType<WorldMap>("Game", 1,0, "WorldMap");
qmlRegisterType<WorldMapCity>("Game", 1,0, "WorldMapCity");
qmlRegisterType<WorldMapZone>("Game", 1,0, "WorldMapZone");
qmlRegisterType<Inventory>("Game", 1,0, "Inventory");
qmlRegisterType<TextBubble>("Game", 1,0, "TextBubble");
qmlRegisterType<Buff>("Game", 1,0, "Buff");
qmlRegisterType<TutorialComponent>("Game", 1,0, "TutorialComponent");
qmlRegisterType<ActionQueue>("Game", 1,0, "ActionQueue");
qmlRegisterType<InteractionTargetList>("Game", 1,0, "InteractionTargetList");
qmlRegisterType<LevelGrid>("Game", 1,0, "LevelGrid");
qmlRegisterType<ObjectGroup>("Game", 1,0, "ObjectGroup");
qmlRegisterType<Credits>("Game", 1,0, "Credits");
qmlRegisterType<CreditPerson>("Game", 1,0, "Person");
qRegisterMetaType<Character*>("Character*");
qRegisterMetaType<Character*>("const Character*");
qRegisterMetaType<CharacterDiplomacy*>("const CharacterDiplomacy*");
qRegisterMetaType<DynamicObject*>("const DynamicObject*");
qRegisterMetaType<TileZone*>("const TileZone*");
qRegisterMetaType<ObjectFactory*>("ObjectFactory*");
qRegisterMetaType<ObjectGroup*>("const ObjectGroup*");
qRegisterMetaType<GridComponent*>("GridComponent*");
qRegisterMetaType<WorldDiplomacy*>("WorldDiplomacy*");
qRegisterMetaType<TileZone*>("const TileZone*");
registerQmlTilemap();
// GAME EDITOR
qmlRegisterType<QmlSpriteAnimation>("Game", 1,0, "SpriteAnimation");
qmlRegisterType<CharacterDialogEditor>("Game", 1,0, "CharacterDialogEditor");
qmlRegisterType<LevelEditorController>("Game", 1,0, "LevelEditorController");
qmlRegisterType<GameObjectTemplates>("Game", 1,0, "GameObjectTemplates");
GameObjectTemplates* got = new GameObjectTemplates(&app);
got->initialize();
engine.rootContext()->setContextProperty("gameObjectTemplates", got);
// END GAME EDITOR
MusicManager* musicManager = new MusicManager(&app);
SoundManager* soundManager = new SoundManager(&app);
GameManager* gameManager = new GameManager();
I18n* i18n = new I18n(&app);
qmlJsEngine = &engine;
engine.rootContext()->setContextProperty("i18n", i18n);
engine.rootContext()->setContextProperty("gameManager", gameManager);
engine.rootContext()->setContextProperty("musicManager", musicManager);
engine.rootContext()->setContextProperty("soundManager", soundManager);
engine.rootContext()->setContextProperty("animationLibrary", &animationLibrary);
engine.rootContext()->setContextProperty("itemLibrary", &itemLibrary);
engine.rootContext()->setContextProperty("fileProtocol", fileProtocol);
engine.rootContext()->setContextProperty("rootPath", rootPath);
engine.rootContext()->setContextProperty("scriptPath", scriptPath);
engine.rootContext()->setContextProperty("assetPath", assetPath);
engine.rootContext()->setContextProperty("scriptController", &scriptEditorController);
engine.rootContext()->setContextProperty("gamepad", gamepad);
engine.rootContext()->setContextProperty("mouseCursor", cursor);
#ifdef GAME_EDITOR
engine.rootContext()->setContextProperty("developmentEdition", true);
#else
engine.rootContext()->setContextProperty("developmentEdition", false);
#endif
QObject::connect(i18n, &I18n::currentLocaleChanged, &app, [&engine, i18n]()
{
engine.rootContext()->setContextProperty("i18n", i18n);
});
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url, cursor, gamepad](QObject *obj, const QUrl &objUrl)
{
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
else
{
gamepad->initialize();
cursor->setWindow(obj);
}
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}