Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
eventdbentry.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2020 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
22
#include <QVector>
23
#include <QJsonArray>
24
#include <QQmlEngine>
25
#include <
pse-common/utility.h
>
26
27
#ifdef QT_DEBUG
28
#include <QtDebug>
29
#endif
30
31
#include "
../eventsdb.h
"
32
#include "
../util/gamedata.h
"
33
#include "
../mapsdb.h
"
34
#include "
mapdbentry.h
"
35
36
#include "
eventdbentry.h
"
37
38
EventDBEntry::EventDBEntry
() {
39
qmlRegister
();
40
}
41
EventDBEntry::EventDBEntry
(QJsonValue& data)
42
{
43
qmlRegister
();
44
// Set simple properties
45
name
= data[
"name"
].toString();
46
ind
= data[
"ind"
].toDouble();
47
byte
= data[
"byte"
].toDouble();
48
bit
= data[
"bit"
].toDouble();
49
50
for
(
auto
eventMap : data[
"maps"
].toArray())
51
maps
.append(eventMap.toString());
52
}
53
54
void
EventDBEntry::deepLink
()
55
{
56
for
(
const
auto
& map :
maps
)
57
{
58
auto
tmp =
MapsDB::inst
()->
getIndAt
(map);
59
toMaps
.append(tmp);
60
61
#ifdef QT_DEBUG
62
if
(tmp ==
nullptr
)
63
qCritical() <<
"Events: "
<<
name
<<
", could not be deep linked to map "
<< map ;
64
#endif
65
66
if
(tmp !=
nullptr
)
67
tmp->toEvents.append(
this
);
68
}
69
}
70
71
void
EventDBEntry::qmlRegister
()
const
72
{
73
static
bool
once =
false
;
74
if
(once)
75
return
;
76
77
qmlRegisterUncreatableType<EventDBEntry>(
"PSE.DB.EventDBEntry"
, 1, 0,
"EventDBEntry"
,
"Can't instantiate in QML"
);
78
once =
true
;
79
}
80
81
const
QVector<MapDBEntry*>
EventDBEntry::getToMaps
()
const
82
{
83
return
toMaps
;
84
}
85
86
int
EventDBEntry::getToMapsSize
()
const
87
{
88
return
toMaps
.size();
89
}
90
91
const
MapDBEntry
*
EventDBEntry::getToMapAt
(
int
ind
)
const
92
{
93
if
(
ind
>=
toMaps
.size())
94
return
nullptr
;
95
96
return
toMaps
.at(
ind
);
97
}
98
99
void
EventDBEntry::qmlProtect
(
const
QQmlEngine*
const
engine)
const
100
{
101
Utility::qmlProtectUtil
(
this
, engine);
102
}
103
104
const
QVector<QString>
EventDBEntry::getMaps
()
const
105
{
106
return
maps
;
107
}
108
109
int
EventDBEntry::getMapsSize
()
const
110
{
111
return
maps
.size();
112
}
113
114
const
QString
EventDBEntry::getMapAt
(
int
ind
)
const
115
{
116
if
(
ind
>=
maps
.size())
117
return
nullptr
;
118
119
return
maps
.at(
ind
);
120
}
121
122
int
EventDBEntry::getBit
()
const
123
{
124
return
bit
;
125
}
126
127
int
EventDBEntry::getByte
()
const
128
{
129
return
byte
;
130
}
131
132
int
EventDBEntry::getInd
()
const
133
{
134
return
ind
;
135
}
136
137
const
QString
EventDBEntry::getName
()
const
138
{
139
return
name
;
140
}
141
MapsDB::inst
static MapsDB * inst()
< Number of maps.
Definition
mapsdb.cpp:35
MapsDB::getIndAt
MapDBEntry * getIndAt(const QString val) const
Map by name key (for QML).
Definition
mapsdb.cpp:155
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
mapdbentry.h
mapsdb.h
EventDBEntry::EventDBEntry
EventDBEntry()
Empty entry (built by EventsDB).
Definition
eventdbentry.cpp:38
EventDBEntry::getName
const QString getName() const
< Event name.
Definition
eventdbentry.cpp:137
EventDBEntry::byte
int byte
Definition
eventdbentry.h:77
EventDBEntry::name
QString name
Definition
eventdbentry.h:75
EventDBEntry::getMapAt
const QString getMapAt(int ind) const
Associated map name ind (for QML).
Definition
eventdbentry.cpp:114
EventDBEntry::bit
int bit
Definition
eventdbentry.h:78
EventDBEntry::getBit
int getBit() const
Definition
eventdbentry.cpp:122
EventDBEntry::getToMapsSize
int getToMapsSize() const
Definition
eventdbentry.cpp:86
EventDBEntry::qmlProtect
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition
eventdbentry.cpp:99
EventDBEntry::qmlRegister
void qmlRegister() const
Register with QML.
Definition
eventdbentry.cpp:71
EventDBEntry::getMapsSize
int getMapsSize() const
Definition
eventdbentry.cpp:109
EventDBEntry::getMaps
const QVector< QString > getMaps() const
Associated map names.
Definition
eventdbentry.cpp:104
EventDBEntry::toMaps
QVector< MapDBEntry * > toMaps
Definition
eventdbentry.h:80
EventDBEntry::maps
QVector< QString > maps
Definition
eventdbentry.h:79
EventDBEntry::deepLink
void deepLink()
Resolve the associated maps.
Definition
eventdbentry.cpp:54
EventDBEntry::ind
int ind
Definition
eventdbentry.h:76
EventDBEntry::getInd
int getInd() const
Definition
eventdbentry.cpp:132
EventDBEntry::getToMaps
const QVector< MapDBEntry * > getToMaps() const
Resolved associated maps.
Definition
eventdbentry.cpp:81
EventDBEntry::getByte
int getByte() const
Definition
eventdbentry.cpp:127
EventDBEntry::getToMapAt
const MapDBEntry * getToMapAt(int ind) const
Resolved map ind (for QML).
Definition
eventdbentry.cpp:91
MapDBEntry
One map's complete static definition – the root of the MapDBEntry family.
Definition
mapdbentry.h:56
utility.h
projects
db
src
pse-db
entries
eventdbentry.cpp
Generated by
1.17.0