Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
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
36{
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
51 if(type != "pokemon" &&
52 type != "tm")
53 return;
54
55 if(type == "pokemon") {
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") {
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
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
100
101void GameCornerDBEntry::qmlProtect(const QQmlEngine* const engine) const
102{
103 Utility::qmlProtectUtil(this, engine);
104}
105
110
112{
113 return level;
114}
115
117{
118 return price;
119}
120
122{
123 return type;
124}
125
127{
128 return name;
129}
static GameCornerDB * inst()
< Number of prize entries.
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
static PokemonDB * inst()
< Number of species.
Definition pokemon.cpp:183
PokemonDBEntry * getIndAt(const QString &key) const
Species by name key (for QML).
Definition pokemon.cpp:199
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
QString getType() const
void qmlRegister() const
Register with QML.
int price
Backing field (read via getPrice()).
PokemonDBEntry * toPokemon
Resolved Pokemon prize (deepLink).
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
QString getName() const
< Prize name.
void deepLink()
Resolve the Pokemon/item link.
int level
Backing field (read via getLevel()).
GameCornerDBEntry()
Empty entry (built by GameCornerDB).
PokemonDBEntry * getToPokemon() const
QString type
Backing field (read via getType()).
QString name
Backing field (read via getName()).
ItemDBEntry * getToItem() const
ItemDBEntry * toItem
Resolved item prize (deepLink).
One item's static data: name/flags, pricing, and where it's used.
Definition itemdbentry.h:46
One species' complete static data – the richest entry in the db layer.
Definition pokemon.h:98