Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
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
42{
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
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
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
81const QVector<MapDBEntry*> EventDBEntry::getToMaps() const
82{
83 return toMaps;
84}
85
87{
88 return toMaps.size();
89}
90
92{
93 if(ind >= toMaps.size())
94 return nullptr;
95
96 return toMaps.at(ind);
97}
98
99void EventDBEntry::qmlProtect(const QQmlEngine* const engine) const
100{
101 Utility::qmlProtectUtil(this, engine);
102}
103
104const QVector<QString> EventDBEntry::getMaps() const
105{
106 return maps;
107}
108
110{
111 return maps.size();
112}
113
114const QString EventDBEntry::getMapAt(int ind) const
115{
116 if(ind >= maps.size())
117 return nullptr;
118
119 return maps.at(ind);
120}
121
123{
124 return bit;
125}
126
128{
129 return byte;
130}
131
133{
134 return ind;
135}
136
137const QString EventDBEntry::getName() const
138{
139 return name;
140}
141
static MapsDB * inst()
< Number of maps.
Definition mapsdb.cpp:35
MapDBEntry * getIndAt(const QString val) const
Map by name key (for QML).
Definition mapsdb.cpp:155
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()
Empty entry (built by EventsDB).
const QString getName() const
< Event name.
const QString getMapAt(int ind) const
Associated map name ind (for QML).
int getBit() const
int getToMapsSize() const
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
void qmlRegister() const
Register with QML.
int getMapsSize() const
const QVector< QString > getMaps() const
Associated map names.
QVector< MapDBEntry * > toMaps
QVector< QString > maps
void deepLink()
Resolve the associated maps.
int getInd() const
const QVector< MapDBEntry * > getToMaps() const
Resolved associated maps.
int getByte() const
const MapDBEntry * getToMapAt(int ind) const
Resolved map ind (for QML).
One map's complete static definition – the root of the MapDBEntry family.
Definition mapdbentry.h:56