Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
abstracthiddenitemdb.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
22
23#include <pse-common/utility.h>
24#include <QVector>
25#include <QJsonArray>
26
27#ifdef QT_DEBUG
28#include <QtDebug>
29#endif
30
32#include "./mapsdb.h"
33#include "./util/gamedata.h"
35
36const QVector<HiddenItemDBEntry*> AbstractHiddenItemDB::getStore() const
37{
38 return store;
39}
40
42{
43 return store.size();
44}
45
47{
48 if(ind >= store.size())
49 return nullptr;
50
51 return store.at(ind);
52}
53
55{
56 static bool once = false;
57 if(once)
58 return;
59
60 // Grab Event Pokemon Data
61 auto jsonData = GameData::inst()->json(loadFile);
62
63 // Go through each event Pokemon
64 for(QJsonValue jsonEntry : jsonData.array())
65 {
66 // Create a new event Pokemon entry
67 auto entry = new HiddenItemDBEntry(jsonEntry);
68
69 // Add to array
70 store.append(entry);
71 }
72
73 once = true;
74}
75
77{
78 static bool once = false;
79 if(once)
80 return;
81
82 for(auto entry : store)
83 {
84 entry->deepLink();
85 }
86
87 once = true;
88}
89
90void AbstractHiddenItemDB::qmlProtect(const QQmlEngine* const engine) const
91{
92 Utility::qmlProtectUtil(this, engine);
93
94 for(auto el : store)
95 el->qmlProtect(engine);
96}
97
AbstractHiddenItemDB(const QString loadFile)
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
int getStoreSize() const
Entry count.
const QString loadFile
JSON asset path (set by the subclass).
HiddenItemDBEntry * getStoreAt(const int ind) const
Entry by store index (for QML).
QVector< HiddenItemDBEntry * > store
The loaded entries.
void load()
Load entries from loadFile.
const QVector< HiddenItemDBEntry * > getStore() const
< Number of hidden pickups.
void deepLink()
Resolve each entry's cross-DB links.
const QJsonDocument json(const QString filename) const
Parsed document for filename.
Definition gamedata.cpp:45
static GameData * inst()
The process-wide GameData singleton.
Definition gamedata.cpp:71
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
One hidden pickup's location: its map and tile coordinates.