Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
eventpokemondb.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
22#include <QJsonDocument>
23#include <QJsonArray>
24#include <QJsonValueRef>
25#include <QQmlEngine>
26#include <pse-common/utility.h>
27
28#ifdef QT_DEBUG
29#include <QtDebug>
30#endif
31
32#include "./eventpokemondb.h"
34#include "./util/gamedata.h"
35#include "./pokemon.h"
36
37EventPokemonDB* EventPokemonDB::inst()
38{
39 static EventPokemonDB* _inst = new EventPokemonDB;
40 return _inst;
41}
42
43const QVector<EventPokemonDBEntry*> EventPokemonDB::getStore() const
44{
45 return store;
46}
47
49{
50 return store.size();
51}
52
54{
55 if(ind < 0 || ind >= store.size())
56 return nullptr;
57
58 return store.at(ind);
59}
60
62{
63 static bool once = false;
64 if(once)
65 return;
66
67 // Grab Event Pokemon Data
68 auto jsonData = GameData::inst()->json("eventPokemon");
69
70 // Go through each event Pokemon
71 for(QJsonValue jsonEntry : jsonData.array())
72 {
73 // Create a new event Pokemon entry
74 auto entry = new EventPokemonDBEntry(jsonEntry);
75
76 // Add to array
77 store.append(entry);
78 }
79
80 once = true;
81}
82
84{
85 static bool once = false;
86 if(once)
87 return;
88
89 for(auto entry : store)
90 {
91 entry->deepLink();
92 }
93
94 once = true;
95}
96
97void EventPokemonDB::qmlProtect(const QQmlEngine* const engine) const
98{
99 Utility::qmlProtectUtil(this, engine);
100 for(auto el : store)
101 el->qmlProtect(engine);
102}
103
104void EventPokemonDB::qmlRegister() const
105{
106 static bool once = false;
107 if(once)
108 return;
109
110 qmlRegisterUncreatableType<EventPokemonDB>("PSE.DB.EventPokemonDB", 1, 0, "EventPokemonDB", "Can't instantiate in QML");
111 once = true;
112}
113
114EventPokemonDB::EventPokemonDB()
115{
116 qmlRegister();
117 load();
118}
void deepLink()
Resolve each entry's species/move links.
int getStoreSize() const
Event-Pokemon count.
void load()
Load event Pokemon from JSON.
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
static EventPokemonDB * inst()
< Number of event Pokemon.
const QVector< EventPokemonDBEntry * > getStore() const
All event Pokemon.
EventPokemonDBEntry * getStoreAt(const int ind) const
Event Pokemon by store index (for QML).
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 real-world event-distribution Pokemon preset.