-
Notifications
You must be signed in to change notification settings - Fork 2
/
game.h
149 lines (133 loc) · 6.18 KB
/
game.h
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
#ifndef GAME_H
# define GAME_H
# include <QObject>
# include "utils/storableobject.h"
# include "utils/uniquecharacterstorage.h"
# include "game/dataengine.h"
# include "game/leveltask.h"
# include "game/characterparty.h"
# include "game/timermanager.h"
# include "game/questmanager.h"
# include "game/worldmap/worldmap.h"
# include "game/worldmap/randomencountercontroller.h"
# include "game/diplomacy.hpp"
# include <QJSEngine>
# include "cmap/trait.h"
# include "cmap/race.h"
# include "game/timepasser.h"
class Game : public StorableObject
{
Q_OBJECT
Q_PROPERTY(QStringList consoleMessages MEMBER consoleMessages NOTIFY consoleUpdated)
Q_PROPERTY(LevelTask* level MEMBER currentLevel NOTIFY levelChanged)
Q_PROPERTY(WorldMap* worldmap MEMBER worldmap CONSTANT)
Q_PROPERTY(Character* player MEMBER player CONSTANT)
Q_PROPERTY(CharacterParty* playerParty MEMBER playerParty CONSTANT)
Q_PROPERTY(DataEngine* dataEngine MEMBER dataEngine CONSTANT)
Q_PROPERTY(WorldDiplomacy* diplomacy READ getDiplomacy CONSTANT)
Q_PROPERTY(TimeManager* timeManager MEMBER timeManager CONSTANT)
Q_PROPERTY(TaskRunner* tasks MEMBER taskManager CONSTANT)
Q_PROPERTY(QuestManager* quests MEMBER quests CONSTANT)
Q_PROPERTY(SoundManager* sounds READ getSoundManager CONSTANT)
Q_PROPERTY(RandomEncounterController* randomEncounters MEMBER randomEncounters CONSTANT)
Q_PROPERTY(UniqueCharacterStorage* uniqueCharacterStorage MEMBER uniqueCharacterStorage CONSTANT)
Q_PROPERTY(QString loadingScreenBackground MEMBER loadingScreenBackground NOTIFY loadingScreenBackgroundChanged)
Q_PROPERTY(bool saveLock MEMBER saveLock NOTIFY saveLockChanged)
Q_PROPERTY(bool fastPassTime READ isFastPassingTime NOTIFY fastPassingChanged)
Q_PROPERTY(bool isGameEditor MEMBER isGameEditor NOTIFY gameEditorEnabled)
static Game* instance;
public:
explicit Game(QObject *parent = nullptr);
~Game() override;
Q_INVOKABLE QStringList getCharacterTemplateList() const;
Q_INVOKABLE void prepareEditor();
void loadFromDataEngine(std::function<void()> callback);
Q_INVOKABLE void save();
void newPlayerParty(StatModel*);
Q_INVOKABLE void appendToConsole(const QString&);
Q_INVOKABLE void switchToLevel(const QString& name, const QString& targetZone = "", QJSValue callback = QJSValue());
Q_INVOKABLE void switchToCity(const QString& name, const QString& levelName = "", const QString& targetZone = "", QJSValue callback = QJSValue());
void exitLevel(bool silence = false);
static Game* get() { return instance; }
Q_INVOKABLE DataEngine* getDataEngine() const { return dataEngine; }
TimeManager* getTimeManager() const { return timeManager; }
WorldDiplomacy* getDiplomacy() const { return diplomacy; }
Q_INVOKABLE QuestManager* getQuestManager() const { return quests; }
WorldMap* getWorldmap() const { return worldmap; }
LevelTask* getLevel() const { return currentLevel; }
TaskRunner* getTaskManager() const { return taskManager; }
SoundManager* getSoundManager() const { return SoundManager::get(); }
QJSEngine& getScriptEngine() { return scriptEngine; }
QJSValue loadScript(const QString& path);
QJSValue scriptCall(QJSValue callable, const QJSValueList& args, const QString& scriptName);
QJSValue eval(const QString& command);
Q_INVOKABLE QJSValue getScriptObject() const { return script->getObject(); }
Q_INVOKABLE QString consoleEval(const QString& command);
void loadCmapTraits();
void loadCmapRaces();
Q_INVOKABLE CharacterParty* getPlayerParty() const { return playerParty; }
Q_INVOKABLE Character* getPlayer() const { return player; }
Q_INVOKABLE StatModel* getPlayerStatistics() const { return getPlayer()->getStatistics(); }
Q_INVOKABLE Character* getCharacter(const QString& characterSheet) const;
Q_INVOKABLE void advanceTime(unsigned int minutes);
Q_INVOKABLE void asyncAdvanceTime(unsigned int minutes);
Q_INVOKABLE void asyncAdvanceTime(unsigned int minutes, QJSValue callback);
Q_INVOKABLE void asyncAdvanceToHour(unsigned int hour, unsigned int minute = 0, QJSValue callback = QJSValue());
bool isFastPassingTime() const { return timePasser.isActive(); }
Q_INVOKABLE void setFactionAsEnemy(const QString &faction, const QString &enemyFaction, bool set);
signals:
void gameEditorEnabled();
void saveLockChanged();
void requestLoadingScreen();
void levelDestroy();
void levelChanged();
void consoleUpdated();
void gameOver();
void transitionRequired(const QString& video, int elapsingTime = 0);
void encounterTriggered(const QString& encounterTitle);
void encounterNotify(const QString& encounterName, const QVariantMap& parameter);
void loadError(const QString&);
void fastPassingChanged();
void requireScreenshot(QString);
void javascriptError(QString);
void loadingScreenBackgroundChanged();
public slots:
void onCityEntered(QString name);
void onCityEnteredAt(const QString& city, const QString& zone);
void changeZone(TileZone*);
void deleteLater();
void loadLevel(const QString& name, const QString& targetZone = "", QJSValue callback = QJSValue());
void loadLevel(const QString& name, const QString& targetZone, std::function<void()> callback);
void onDiplomacyUpdate(const QStringList& factions, bool enemy);
private slots:
void onLevelChanged();
void onGameOver();
private:
void initializeEvents();
void initializeScript();
void setupPlayerPartyIntoLevel(const QString& targetZone);
LevelTask* newLevelTask();
void destroyLevelTask();
bool isGameEditor = false;
bool saveLock = false;
bool exitingLevel = false;
DataEngine* dataEngine = nullptr;
TimeManager* timeManager;
WorldDiplomacy* diplomacy;
QuestManager* quests;
WorldMap* worldmap;
RandomEncounterController* randomEncounters;
UniqueCharacterStorage* uniqueCharacterStorage;
LevelTask* currentLevel = nullptr;
CharacterParty* playerParty = nullptr;
Character* player = nullptr;
QStringList consoleMessages;
QJSEngine scriptEngine;
ScriptController* script = nullptr;
TaskRunner* taskManager = nullptr;
TimePasser timePasser;
QString loadingScreenBackground;
QMap<QString, Trait> cmapTraits;
QMap<QString, Race> cmapRaces;
};
#endif // GAME_H