Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
tmHm.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 <QJsonArray>
23#include <QQmlEngine>
24#include <pse-common/utility.h>
25
26#ifdef QT_DEBUG
27#include <QtDebug>
28#endif
29
30#include "./tmHm.h"
31#include "./util/gamedata.h"
32#include "./itemsdb.h"
33#include "./moves.h"
34
35TmHmsDB* TmHmsDB::inst()
36{
37 static TmHmsDB* _inst = new TmHmsDB;
38 return _inst;
39}
40
41const QVector<QString> TmHmsDB::getStore() const { return store; }
42int TmHmsDB::getStoreSize() const { return store.size(); }
43const QVector<ItemDBEntry*>& TmHmsDB::getTmHmItems() const { return toTmHmItem; }
44const QVector<MoveDBEntry*>& TmHmsDB::getTmHmMoves() const { return toTmHmMove; }
45
47{
48 static bool once = false;
49 if (once) return;
50 auto jsonData = GameData::inst()->json("tmHm");
51 for (QJsonValue entry : jsonData.array())
52 store.append(entry.toString());
53 once = true;
54}
55
57{
58 static bool once = false;
59 if (once) return;
60 for (var8 i = 0; i < static_cast<var8>(store.size()); ++i) {
61 const auto& entry = store.at(i);
62 var8 tmNum = i + 1;
63 auto* item = ItemsDB::inst()->getIndAt("tm" + QString::number(tmNum));
64 auto* move = MovesDB::inst()->getIndAt("tm" + QString::number(tmNum));
65 toTmHmItem.append(item);
66 toTmHmMove.append(move);
67#ifdef QT_DEBUG
68 if (!item) qCritical() << "TM/HM item:" << entry << "could not be deep linked.";
69 if (!move) qCritical() << "TM/HM move:" << entry << "could not be deep linked.";
70#endif
71 }
72 once = true;
73}
74
75void TmHmsDB::qmlProtect(const QQmlEngine* const engine) const
76{
77 Utility::qmlProtectUtil(this, engine);
78}
79
80void TmHmsDB::qmlRegister() const
81{
82 static bool once = false;
83 if (once) return;
84 qmlRegisterUncreatableType<TmHmsDB>("PSE.DB.TmHmsDB", 1, 0, "TmHmsDB", "Can't instantiate in QML");
85 once = true;
86}
87
88TmHmsDB::TmHmsDB()
89{
90 qmlRegister();
91}
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
ItemDBEntry * getIndAt(const QString val) const
Item by name key (for QML).
Definition itemsdb.cpp:66
static ItemsDB * inst()
< Number of items.
Definition itemsdb.cpp:37
MoveDBEntry * getIndAt(const QString &key) const
Move by name key (for QML).
Definition moves.cpp:88
static MovesDB * inst()
< Number of moves.
Definition moves.cpp:72
const QVector< ItemDBEntry * > & getTmHmItems() const
The item for each TM/HM (parallel to store).
Definition tmHm.cpp:43
const QVector< QString > getStore() const
Move names in TM/HM order.
Definition tmHm.cpp:41
void load()
Load the TM/HM list from JSON.
Definition tmHm.cpp:46
static TmHmsDB * inst()
< Number of TMs+HMs.
Definition tmHm.cpp:35
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition tmHm.cpp:75
void deepLink()
Resolve the parallel item/move vectors.
Definition tmHm.cpp:56
int getStoreSize() const
TM+HM count.
Definition tmHm.cpp:42
const QVector< MoveDBEntry * > & getTmHmMoves() const
The move for each TM/HM (parallel to store).
Definition tmHm.cpp:44
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
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition types.h:124