Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
gamecornerdb.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 <QJsonArray>
23
#include <QQmlEngine>
24
#include <
pse-common/utility.h
>
25
26
#ifdef QT_DEBUG
27
#include <QtDebug>
28
#endif
29
30
#include "
./gamecornerdb.h
"
31
#include "
./util/gamedata.h
"
32
#include "
./pokemon.h
"
33
#include "
./itemsdb.h
"
34
#include "
./entries/gamecornerdbentry.h
"
35
36
void
GameCornerDB::load
()
37
{
38
static
bool
once =
false
;
39
if
(once)
40
return
;
41
42
// Grab Item Data
43
auto
jsonData =
GameData::inst
()->
json
(
"gameCorner"
);
44
45
// Go through each item
46
for
(QJsonValue jsonEntry : jsonData.array())
47
{
48
if
(jsonEntry[
"options"
].isArray()) {
49
for
(QJsonValue option : jsonEntry[
"options"
].toArray()) {
50
51
// Create a new item entry
52
auto
entry =
new
GameCornerDBEntry
(jsonEntry);
53
entry->level = option[
"level"
].toDouble();
54
entry->price = option[
"price"
].toDouble();
55
56
// Add to array
57
store.append(entry);
58
}
59
}
60
else
{
61
auto
entry =
new
GameCornerDBEntry
(jsonEntry);
62
63
// Add to array
64
store.append(entry);
65
}
66
}
67
68
once =
true
;
69
}
70
71
void
GameCornerDB::deepLink
()
72
{
73
static
bool
once =
false
;
74
if
(once)
75
return
;
76
77
for
(
auto
entry : store)
78
{
79
entry->deepLink();
80
}
81
82
once =
true
;
83
}
84
85
void
GameCornerDB::qmlProtect
(
const
QQmlEngine*
const
engine)
const
86
{
87
Utility::qmlProtectUtil
(
this
, engine);
88
for
(
auto
el : store)
89
el->qmlProtect(engine);
90
}
91
92
void
GameCornerDB::qmlRegister()
const
93
{
94
static
bool
once =
false
;
95
if
(once)
96
return
;
97
98
qmlRegisterUncreatableType<GameCornerDB>(
99
"PSE.DB.GameCornerDB"
, 1, 0,
"GameCornerDB"
,
"Can't instantiate in QML"
);
100
once =
true
;
101
}
102
103
GameCornerDB::GameCornerDB()
104
{
105
qmlRegister();
106
}
107
108
GameCornerDB*
GameCornerDB::inst
()
109
{
110
static
GameCornerDB* _inst =
new
GameCornerDB;
111
return
_inst;
112
}
113
114
const
QVector<GameCornerDBEntry*>
GameCornerDB::getStore
()
const
115
{
116
return
store;
117
}
118
119
int
GameCornerDB::getStoreSize
()
const
120
{
121
return
store.size();
122
}
123
124
GameCornerDBEntry
*
GameCornerDB::getStoreAt
(
const
int
ind)
const
125
{
126
if
(ind < 0 || ind >= store.size())
127
return
nullptr
;
128
129
return
store.at(ind);
130
}
131
132
int
GameCornerDB::getBuyPrice
()
const
133
{
134
return
buyPrice;
135
}
136
137
int
GameCornerDB::getSellPrice
()
const
138
{
139
// Follow the global Poke-World sell-back mechanic: half the buy price back.
140
return
buyPrice / 2;
141
}
142
GameCornerDB::deepLink
void deepLink()
Resolve each prize's item/Pokemon links.
Definition
gamecornerdb.cpp:71
GameCornerDB::qmlProtect
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition
gamecornerdb.cpp:85
GameCornerDB::getStoreAt
GameCornerDBEntry * getStoreAt(const int ind) const
Prize by store index (for QML).
Definition
gamecornerdb.cpp:124
GameCornerDB::getStoreSize
int getStoreSize() const
Prize count.
Definition
gamecornerdb.cpp:119
GameCornerDB::GameCornerDBEntry
friend class GameCornerDBEntry
Lets entries populate the store/price during load.
Definition
gamecornerdb.h:74
GameCornerDB::getStore
const QVector< GameCornerDBEntry * > getStore() const
All prize entries.
Definition
gamecornerdb.cpp:114
GameCornerDB::load
void load()
Load prizes from JSON.
Definition
gamecornerdb.cpp:36
GameCornerDB::getBuyPrice
int getBuyPrice() const
The buy rate (backs getBuyPrice).
Definition
gamecornerdb.cpp:132
GameCornerDB::inst
static GameCornerDB * inst()
< Number of prize entries.
Definition
gamecornerdb.cpp:108
GameCornerDB::getSellPrice
int getSellPrice() const
The sell rate (half the buy rate).
Definition
gamecornerdb.cpp:137
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
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
gamedata.h
itemsdb.h
pokemon.h
utility.h
projects
db
src
pse-db
gamecornerdb.cpp
Generated by
1.17.0