Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
eventsdb.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2019 Twilight
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
21
#include <QVector>
22
#include <QJsonArray>
23
#include <QQmlEngine>
24
#include <
pse-common/utility.h
>
25
26
#ifdef QT_DEBUG
27
#include <QtDebug>
28
#endif
29
30
#include "
./eventsdb.h
"
31
#include "
./entries/eventdbentry.h
"
32
#include "
./util/gamedata.h
"
33
#include "
./mapsdb.h
"
34
35
EventsDB*
EventsDB::inst
()
36
{
37
static
EventsDB* _inst =
new
EventsDB;
38
return
_inst;
39
}
40
41
const
QVector<EventDBEntry*>
EventsDB::getStore
()
const
42
{
43
return
store;
44
}
45
46
const
QHash<QString, EventDBEntry*>
EventsDB::getInd
()
const
47
{
48
return
ind;
49
}
50
51
int
EventsDB::getStoreSize
()
const
52
{
53
return
store.size();
54
}
55
56
EventDBEntry
*
EventsDB::getStoreAt
(
const
int
ind)
const
57
{
58
if
(ind < 0 || ind >= store.size())
59
return
nullptr
;
60
61
return
store.at(ind);
62
}
63
64
EventDBEntry
*
EventsDB::getIndAt
(
const
QString val)
const
65
{
66
return
ind.value(val,
nullptr
);
67
}
68
69
void
EventsDB::load
()
70
{
71
static
bool
once =
false
;
72
if
(once)
73
return
;
74
75
// Grab Events
76
auto
jsonData =
GameData::inst
()->
json
(
"events"
);
77
78
// Go through each event
79
for
(QJsonValue jsonEntry : jsonData.array())
80
{
81
// Create a new event
82
auto
entry =
new
EventDBEntry
(jsonEntry);
83
84
// Add to array
85
store.append(entry);
86
}
87
88
once =
true
;
89
}
90
91
void
EventsDB::index
()
92
{
93
static
bool
once =
false
;
94
if
(once)
95
return
;
96
97
for
(
auto
entry : store)
98
{
99
// Index name and index
100
ind.insert(entry->name, entry);
101
ind.insert(QString::number(entry->ind), entry);
102
}
103
104
once =
true
;
105
}
106
107
void
EventsDB::deepLink
()
108
{
109
static
bool
once =
false
;
110
if
(once)
111
return
;
112
113
for
(
auto
entry : store)
114
{
115
entry->deepLink();
116
}
117
118
once =
true
;
119
}
120
121
void
EventsDB::qmlProtect
(
const
QQmlEngine*
const
engine)
const
122
{
123
Utility::qmlProtectUtil
(
this
, engine);
124
for
(
auto
el : store)
125
el->qmlProtect(engine);
126
}
127
128
void
EventsDB::qmlRegister()
const
129
{
130
static
bool
once =
false
;
131
if
(once)
132
return
;
133
134
qmlRegisterUncreatableType<EventsDB>(
"PSE.DB.EventsDB"
, 1, 0,
"EventsDB"
,
"Can't instantiate in QML"
);
135
once =
true
;
136
}
137
138
EventsDB::EventsDB()
139
{
140
qmlRegister();
141
load
();
142
}
EventsDB::deepLink
void deepLink()
Resolve each event's cross-DB links.
Definition
eventsdb.cpp:107
EventsDB::qmlProtect
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition
eventsdb.cpp:121
EventsDB::getStoreSize
int getStoreSize() const
Event count.
Definition
eventsdb.cpp:51
EventsDB::getInd
const QHash< QString, EventDBEntry * > getInd() const
Name->entry index.
Definition
eventsdb.cpp:46
EventsDB::getIndAt
EventDBEntry * getIndAt(const QString val) const
Event by name key (for QML).
Definition
eventsdb.cpp:64
EventsDB::load
void load()
Load events from JSON.
Definition
eventsdb.cpp:69
EventsDB::getStoreAt
EventDBEntry * getStoreAt(const int ind) const
Event by store index (for QML).
Definition
eventsdb.cpp:56
EventsDB::index
void index()
Build the name->entry index.
Definition
eventsdb.cpp:91
EventsDB::getStore
const QVector< EventDBEntry * > getStore() const
All event definitions.
Definition
eventsdb.cpp:41
EventsDB::inst
static EventsDB * inst()
< Number of event definitions.
Definition
eventsdb.cpp:35
GameData::json
const QJsonDocument json(const QString filename) const
Parsed document for filename.
Definition
gamedata.cpp:45
GameData::inst
static GameData * inst()
The process-wide GameData singleton.
Definition
gamedata.cpp:71
Utility::qmlProtectUtil
static void qmlProtectUtil(const QObject *const obj, const QQmlEngine *const engine)
Pin obj to C++ ownership so the QML engine never garbage-collects it.
Definition
utility.cpp:63
eventdbentry.h
eventsdb.h
gamedata.h
mapsdb.h
EventDBEntry
One story-event definition: its name and where its flag lives in the save.
Definition
eventdbentry.h:42
utility.h
projects
db
src
pse-db
eventsdb.cpp
Generated by
1.17.0