Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
creditsdb.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 <QJsonDocument>
23
#include <QJsonArray>
24
#include <QJsonObject>
25
#include <QJsonValueRef>
26
#include <
pse-common/utility.h
>
27
28
#include "
./creditsdb.h
"
29
#include "
./entries/creditdbentry.h
"
30
#include "
./util/gamedata.h
"
31
#include "
./db.h
"
32
33
CreditsDB*
CreditsDB::inst
()
34
{
35
static
CreditsDB* _inst =
new
CreditsDB;
36
return
_inst;
37
}
38
39
const
QVector<CreditDBEntry*>
CreditsDB::getStore
()
const
40
{
41
return
store;
42
}
43
44
int
CreditsDB::getStoreSize
()
const
45
{
46
return
store.size();
47
}
48
49
CreditDBEntry
*
CreditsDB::getStoreAt
(
const
int
ind)
const
50
{
51
// Bounds guard. The old check was inverted (`store.size() >= ind`), which
52
// returned nullptr for every valid small index (e.g. 0) and fell through to
53
// store.at(ind) for out-of-range indices -> a crash. Correct form below.
54
if
(ind < 0 || ind >= store.size())
55
return
nullptr
;
56
57
return
store.at(ind);
58
}
59
60
void
CreditsDB::load
()
61
{
62
static
bool
loaded =
false
;
63
64
if
(loaded)
65
return
;
66
67
// Grab Event Pokemon Data
68
auto
jsonData =
GameData::inst
()->
json
(
"credits"
);
69
auto
obj = jsonData.object();
70
71
// Create a entry
72
CreditDBEntry::process
(obj);
73
74
// Seal off further loading
75
loaded =
true
;
76
}
77
78
void
CreditsDB::qmlProtect
(
const
QQmlEngine*
const
engine)
const
79
{
80
Utility::qmlProtectUtil
(
this
, engine);
81
82
for
(
auto
el : store)
83
el->qmlProtect(engine);
84
}
85
86
void
CreditsDB::qmlRegister()
const
87
{
88
static
bool
registered =
false
;
89
if
(registered)
90
return
;
91
92
qmlRegisterUncreatableType<CreditsDB>(
"PSE.DB.CreditsDB"
, 1, 0,
"CreditsDB"
,
"Can't instantiate in QML"
);
93
registered =
true
;
94
}
95
96
CreditsDB::CreditsDB() {
97
// Do NOT call load() here — load() causes side effects before the singleton is ready.
98
}
CreditsDB::getStore
const QVector< CreditDBEntry * > getStore() const
The full entry vector.
Definition
creditsdb.cpp:39
CreditsDB::getStoreSize
int getStoreSize() const
Entry count (backs getStoreSize).
Definition
creditsdb.cpp:44
CreditsDB::load
void load()
Load entries from the JSON assets.
Definition
creditsdb.cpp:60
CreditsDB::inst
static CreditsDB * inst()
< Number of credit entries.
Definition
creditsdb.cpp:33
CreditsDB::CreditDBEntry
friend struct CreditDBEntry
Lets entries populate the store during load.
Definition
creditsdb.h:80
CreditsDB::qmlProtect
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership (anti-GC).
Definition
creditsdb.cpp:78
CreditsDB::getStoreAt
CreditDBEntry * getStoreAt(const int ind) const
Entry at ind (for QML).
Definition
creditsdb.cpp:49
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
creditdbentry.h
creditsdb.h
db.h
gamedata.h
CreditDBEntry::process
static void process(QJsonObject &data)
Parse JSON and append entries to CreditsDB's store.
Definition
creditdbentry.cpp:88
utility.h
projects
db
src
pse-db
creditsdb.cpp
Generated by
1.17.0