Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
gamecornerdbentry.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 <QDebug>
23
#include <QQmlEngine>
24
#include <
pse-common/utility.h
>
25
26
#include "
../pokemon.h
"
27
#include "
../itemsdb.h
"
28
#include "
./itemdbentry.h
"
29
#include "
../gamecornerdb.h
"
30
#include "
gamecornerdbentry.h
"
31
32
GameCornerDBEntry::GameCornerDBEntry
() {
33
qmlRegister
();
34
}
35
GameCornerDBEntry::GameCornerDBEntry
(
const
QJsonValue& data)
36
{
37
qmlRegister
();
38
39
name
= data[
"name"
].toString();
40
type
= data[
"type"
].toString();
41
42
if
(
type
!=
"pokemon"
)
43
price
= data[
"price"
].toDouble();
44
45
if
(
type
==
"money"
) {
46
GameCornerDB::inst
()->buyPrice =
price
;
47
}
48
}
49
50
void
GameCornerDBEntry::deepLink
() {
51
if
(
type
!=
"pokemon"
&&
52
type
!=
"tm"
)
53
return
;
54
55
if
(
type
==
"pokemon"
) {
56
toPokemon
=
PokemonDB::inst
()->
getIndAt
(
name
);
57
58
#ifdef QT_DEBUG
59
if
(
toPokemon
==
nullptr
)
60
qCritical() <<
"Game Corner: "
<<
name
<<
", could not be deep linked."
;
61
#endif
62
63
if
(
toPokemon
==
nullptr
)
64
return
;
65
66
// Cross-Deep Link
67
toPokemon
->toGameCorner.append(
this
);
68
}
69
else
if
(
type
==
"tm"
) {
70
toItem
=
ItemsDB::inst
()->
getIndAt
(
name
);
71
72
#ifdef QT_DEBUG
73
if
(
toItem
==
nullptr
)
74
qCritical() <<
"Game Corner: "
<<
name
<<
", could not be deep linked."
;
75
#endif
76
77
if
(
toItem
==
nullptr
)
78
return
;
79
80
// Cross-Deep Link
81
toItem
->toGameCorner =
this
;
82
}
83
}
84
85
void
GameCornerDBEntry::qmlRegister
()
const
86
{
87
static
bool
once =
false
;
88
if
(once)
89
return
;
90
91
qmlRegisterUncreatableType<GameCornerDBEntry>(
92
"PSE.DB.GameCornerDBEntry"
, 1, 0,
"GameCornerDBEntry"
,
"Can't instantiate in QML"
);
93
once =
true
;
94
}
95
96
ItemDBEntry
*
GameCornerDBEntry::getToItem
()
const
97
{
98
return
toItem
;
99
}
100
101
void
GameCornerDBEntry::qmlProtect
(
const
QQmlEngine*
const
engine)
const
102
{
103
Utility::qmlProtectUtil
(
this
, engine);
104
}
105
106
PokemonDBEntry
*
GameCornerDBEntry::getToPokemon
()
const
107
{
108
return
toPokemon
;
109
}
110
111
int
GameCornerDBEntry::getLevel
()
const
112
{
113
return
level
;
114
}
115
116
int
GameCornerDBEntry::getPrice
()
const
117
{
118
return
price
;
119
}
120
121
QString
GameCornerDBEntry::getType
()
const
122
{
123
return
type
;
124
}
125
126
QString
GameCornerDBEntry::getName
()
const
127
{
128
return
name
;
129
}
GameCornerDB::inst
static GameCornerDB * inst()
< Number of prize entries.
Definition
gamecornerdb.cpp:108
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
PokemonDB::inst
static PokemonDB * inst()
< Number of species.
Definition
pokemon.cpp:183
PokemonDB::getIndAt
PokemonDBEntry * getIndAt(const QString &key) const
Species by name key (for QML).
Definition
pokemon.cpp:199
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
gamecornerdb.h
gamecornerdbentry.h
itemdbentry.h
itemsdb.h
pokemon.h
GameCornerDBEntry::getType
QString getType() const
Definition
gamecornerdbentry.cpp:121
GameCornerDBEntry::qmlRegister
void qmlRegister() const
Register with QML.
Definition
gamecornerdbentry.cpp:85
GameCornerDBEntry::price
int price
Backing field (read via getPrice()).
Definition
gamecornerdbentry.h:65
GameCornerDBEntry::toPokemon
PokemonDBEntry * toPokemon
Resolved Pokemon prize (deepLink).
Definition
gamecornerdbentry.h:67
GameCornerDBEntry::qmlProtect
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition
gamecornerdbentry.cpp:101
GameCornerDBEntry::getLevel
int getLevel() const
Definition
gamecornerdbentry.cpp:111
GameCornerDBEntry::getName
QString getName() const
< Prize name.
Definition
gamecornerdbentry.cpp:126
GameCornerDBEntry::deepLink
void deepLink()
Resolve the Pokemon/item link.
Definition
gamecornerdbentry.cpp:50
GameCornerDBEntry::level
int level
Backing field (read via getLevel()).
Definition
gamecornerdbentry.h:66
GameCornerDBEntry::GameCornerDBEntry
GameCornerDBEntry()
Empty entry (built by GameCornerDB).
Definition
gamecornerdbentry.cpp:32
GameCornerDBEntry::getPrice
int getPrice() const
Definition
gamecornerdbentry.cpp:116
GameCornerDBEntry::getToPokemon
PokemonDBEntry * getToPokemon() const
Definition
gamecornerdbentry.cpp:106
GameCornerDBEntry::type
QString type
Backing field (read via getType()).
Definition
gamecornerdbentry.h:64
GameCornerDBEntry::name
QString name
Backing field (read via getName()).
Definition
gamecornerdbentry.h:63
GameCornerDBEntry::getToItem
ItemDBEntry * getToItem() const
Definition
gamecornerdbentry.cpp:96
GameCornerDBEntry::toItem
ItemDBEntry * toItem
Resolved item prize (deepLink).
Definition
gamecornerdbentry.h:68
ItemDBEntry
One item's static data: name/flags, pricing, and where it's used.
Definition
itemdbentry.h:46
PokemonDBEntry
One species' complete static data – the richest entry in the db layer.
Definition
pokemon.h:98
utility.h
projects
db
src
pse-db
entries
gamecornerdbentry.cpp
Generated by
1.17.0