Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
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
35
TmHmsDB*
TmHmsDB::inst
()
36
{
37
static
TmHmsDB* _inst =
new
TmHmsDB;
38
return
_inst;
39
}
40
41
const
QVector<QString>
TmHmsDB::getStore
()
const
{
return
store; }
42
int
TmHmsDB::getStoreSize
()
const
{
return
store.size(); }
43
const
QVector<ItemDBEntry*>&
TmHmsDB::getTmHmItems
()
const
{
return
toTmHmItem; }
44
const
QVector<MoveDBEntry*>&
TmHmsDB::getTmHmMoves
()
const
{
return
toTmHmMove; }
45
46
void
TmHmsDB::load
()
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
56
void
TmHmsDB::deepLink
()
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
75
void
TmHmsDB::qmlProtect
(
const
QQmlEngine*
const
engine)
const
76
{
77
Utility::qmlProtectUtil
(
this
, engine);
78
}
79
80
void
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
88
TmHmsDB::TmHmsDB()
89
{
90
qmlRegister();
91
}
GameData::json
const QJsonDocument json(const QString filename) const
Parsed document for filename.
Definition
gamedata.cpp:45
GameData::inst
static GameData * inst()
The process-wide GameData singleton.
Definition
gamedata.cpp:71
ItemsDB::getIndAt
ItemDBEntry * getIndAt(const QString val) const
Item by name key (for QML).
Definition
itemsdb.cpp:66
ItemsDB::inst
static ItemsDB * inst()
< Number of items.
Definition
itemsdb.cpp:37
MovesDB::getIndAt
MoveDBEntry * getIndAt(const QString &key) const
Move by name key (for QML).
Definition
moves.cpp:88
MovesDB::inst
static MovesDB * inst()
< Number of moves.
Definition
moves.cpp:72
TmHmsDB::getTmHmItems
const QVector< ItemDBEntry * > & getTmHmItems() const
The item for each TM/HM (parallel to store).
Definition
tmHm.cpp:43
TmHmsDB::getStore
const QVector< QString > getStore() const
Move names in TM/HM order.
Definition
tmHm.cpp:41
TmHmsDB::load
void load()
Load the TM/HM list from JSON.
Definition
tmHm.cpp:46
TmHmsDB::inst
static TmHmsDB * inst()
< Number of TMs+HMs.
Definition
tmHm.cpp:35
TmHmsDB::qmlProtect
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition
tmHm.cpp:75
TmHmsDB::deepLink
void deepLink()
Resolve the parallel item/move vectors.
Definition
tmHm.cpp:56
TmHmsDB::getStoreSize
int getStoreSize() const
TM+HM count.
Definition
tmHm.cpp:42
TmHmsDB::getTmHmMoves
const QVector< MoveDBEntry * > & getTmHmMoves() const
The move for each TM/HM (parallel to store).
Definition
tmHm.cpp:44
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
var8
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition
types.h:124
gamedata.h
itemsdb.h
moves.h
tmHm.h
utility.h
projects
db
src
pse-db
tmHm.cpp
Generated by
1.17.0