Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
tileset.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
#include "
./tileset.h
"
27
#include "
./util/gamedata.h
"
28
29
TilesetDBEntry::TilesetDBEntry
() {}
30
TilesetDBEntry::TilesetDBEntry
(QJsonValue& data)
31
{
32
name
= data[
"name"
].toString();
33
type
= data[
"type"
].toString();
34
nameAlias
= data[
"nameAlias"
].toString();
35
typeAlias
= data[
"typeAlias"
].toString();
36
37
ind
=
static_cast<
var8
>
(data[
"ind"
].toDouble());
38
grass
=
static_cast<
var8
>
(data[
"grass"
].toDouble());
39
bank
=
static_cast<
var8
>
(data[
"bank"
].toDouble());
40
blockPtr
=
static_cast<
var16
>
(data[
"blockPtr"
].toDouble());
41
gfxPtr
=
static_cast<
var16
>
(data[
"gfxPtr"
].toDouble());
42
collPtr
=
static_cast<
var16
>
(data[
"collPtr"
].toDouble());
43
44
QJsonValue talkArr = data[
"talk"
].toArray();
45
for
(
var8
i = 0; i <
talkCount
; ++i)
46
talk
[i] =
static_cast<
var8
>
(talkArr[i].toDouble());
47
}
48
49
TilesetType
TilesetDBEntry::typeAsEnum
()
const
50
{
51
if
(
type
==
"Outdoor"
)
return
TilesetType::OUTDOOR
;
52
if
(
type
==
"Cave"
)
return
TilesetType::CAVE
;
53
return
TilesetType::INDOOR
;
54
}
55
56
TilesetDB*
TilesetDB::inst
()
57
{
58
static
TilesetDB* _inst =
new
TilesetDB;
59
return
_inst;
60
}
61
62
const
QVector<TilesetDBEntry*>
TilesetDB::getStore
()
const
{
return
store; }
63
const
QHash<QString, TilesetDBEntry*>
TilesetDB::getInd
()
const
{
return
ind; }
64
int
TilesetDB::getStoreSize
()
const
{
return
store.size(); }
65
66
TilesetDBEntry
*
TilesetDB::getStoreAt
(
int
idx)
const
67
{
68
if
(idx < 0 || idx >= store.size())
return
nullptr
;
69
return
store.at(idx);
70
}
71
72
TilesetDBEntry
*
TilesetDB::getIndAt
(
const
QString& key)
const
73
{
74
return
ind.value(key,
nullptr
);
75
}
76
77
void
TilesetDB::load
()
78
{
79
static
bool
once =
false
;
80
if
(once)
return
;
81
auto
jsonData =
GameData::inst
()->
json
(
"tileset"
);
82
for
(QJsonValue entry : jsonData.array())
83
store.append(
new
TilesetDBEntry
(entry));
84
once =
true
;
85
}
86
87
void
TilesetDB::index
()
88
{
89
static
bool
once =
false
;
90
if
(once)
return
;
91
for
(
auto
* entry : store) {
92
ind.insert(entry->name, entry);
93
ind.insert(entry->nameAlias, entry);
94
}
95
once =
true
;
96
}
97
98
void
TilesetDB::qmlProtect
(
const
QQmlEngine*
const
engine)
const
99
{
100
Utility::qmlProtectUtil
(
this
, engine);
101
}
102
103
void
TilesetDB::qmlRegister()
const
104
{
105
static
bool
once =
false
;
106
if
(once)
return
;
107
qmlRegisterUncreatableType<TilesetDB>(
"PSE.DB.TilesetDB"
, 1, 0,
"TilesetDB"
,
"Can't instantiate in QML"
);
108
once =
true
;
109
}
110
111
TilesetDB::TilesetDB()
112
{
113
qmlRegister();
114
}
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
TilesetDB::getStoreAt
TilesetDBEntry * getStoreAt(int idx) const
Tileset by store index (for QML).
Definition
tileset.cpp:66
TilesetDB::qmlProtect
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition
tileset.cpp:98
TilesetDB::getInd
const QHash< QString, TilesetDBEntry * > getInd() const
Name->entry index.
Definition
tileset.cpp:63
TilesetDB::getStore
const QVector< TilesetDBEntry * > getStore() const
All tilesets.
Definition
tileset.cpp:62
TilesetDB::load
void load()
Load tilesets from JSON.
Definition
tileset.cpp:77
TilesetDB::getIndAt
TilesetDBEntry * getIndAt(const QString &key) const
Tileset by name key (for QML).
Definition
tileset.cpp:72
TilesetDB::inst
static TilesetDB * inst()
< Number of tilesets.
Definition
tileset.cpp:56
TilesetDB::getStoreSize
int getStoreSize() const
Tileset count.
Definition
tileset.cpp:64
TilesetDB::index
void index()
Build the name->entry index.
Definition
tileset.cpp:87
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
var16
var16e var16
Everyday 16-bit alias. Exact width to avoid the "fastest" widening bug.
Definition
types.h:125
gamedata.h
TilesetDBEntry
One tileset definition: its type, graphics/block/collision pointers, etc.
Definition
tileset.h:45
TilesetDBEntry::collPtr
var16 collPtr
Collision pointer.
Definition
tileset.h:62
TilesetDBEntry::nameAlias
QString nameAlias
Friendly name.
Definition
tileset.h:51
TilesetDBEntry::typeAlias
QString typeAlias
Friendly type label.
Definition
tileset.h:52
TilesetDBEntry::typeAsEnum
TilesetType typeAsEnum() const
type parsed to the TilesetType enum.
Definition
tileset.cpp:49
TilesetDBEntry::type
QString type
Behaviour type as a string.
Definition
tileset.h:50
TilesetDBEntry::talk
var8 talk[3]
Talk-over tile ids.
Definition
tileset.h:57
TilesetDBEntry::TilesetDBEntry
TilesetDBEntry()
Empty entry.
Definition
tileset.cpp:29
TilesetDBEntry::blockPtr
var16 blockPtr
Blocks pointer.
Definition
tileset.h:60
TilesetDBEntry::bank
var8 bank
Bank holding GFX + blocks.
Definition
tileset.h:59
TilesetDBEntry::grass
var8 grass
Grass tile id.
Definition
tileset.h:58
TilesetDBEntry::ind
var8 ind
Tileset index.
Definition
tileset.h:56
TilesetDBEntry::gfxPtr
var16 gfxPtr
Graphics pointer.
Definition
tileset.h:61
TilesetDBEntry::name
QString name
Internal tileset name (key).
Definition
tileset.h:49
tileset.h
talkCount
constexpr var8 talkCount
Number of "talk-over" tile slots per tileset.
Definition
tileset.h:33
TilesetType
TilesetType
The three tileset behaviour categories.
Definition
tileset.h:31
TilesetType::INDOOR
@ INDOOR
Definition
tileset.h:31
TilesetType::CAVE
@ CAVE
Definition
tileset.h:31
TilesetType::OUTDOOR
@ OUTDOOR
Definition
tileset.h:31
utility.h
projects
db
src
pse-db
tileset.cpp
Generated by
1.17.0