Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
trainers.h
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#pragma once
17
18#include <QObject>
19#include <QJsonValue>
20#include <QVector>
21#include <QString>
22#include <QHash>
23
24#include <pse-common/types.h>
25#include "./db_autoport.h"
26
28class QQmlEngine;
29
40 TrainerDBEntry(QJsonValue& data);
41
42 QString name;
43 var8 ind = 0;
44 bool unused = false;
45 bool opp = false;
46
47 QVector<MapDBEntrySpriteTrainer*> tpMapSpriteTrainers;
48};
49
57class DB_AUTOPORT TrainersDB : public QObject
58{
59 Q_OBJECT
60 Q_PROPERTY(int getStoreSize READ getStoreSize CONSTANT)
61
62public:
63 static TrainersDB* inst();
64
65 [[nodiscard]] const QVector<TrainerDBEntry*> getStore() const;
66 [[nodiscard]] const QHash<QString, TrainerDBEntry*> getInd() const;
67 [[nodiscard]] int getStoreSize() const;
68
69 Q_INVOKABLE TrainerDBEntry* getStoreAt(int idx) const;
70 Q_INVOKABLE TrainerDBEntry* getIndAt(const QString& key) const;
71
72public slots:
73 void load();
74 void index();
75 void qmlProtect(const QQmlEngine* const engine) const;
76
77private slots:
78 void qmlRegister() const;
79
80private:
81 TrainersDB();
82
83 QVector<TrainerDBEntry*> store;
84 QHash<QString, TrainerDBEntry*> ind;
85};
TrainerDBEntry * getIndAt(const QString &key) const
Trainer by name key (for QML).
Definition trainers.cpp:54
const QVector< TrainerDBEntry * > getStore() const
All trainer classes.
Definition trainers.cpp:44
void index()
Build the name->entry index.
Definition trainers.cpp:69
static TrainersDB * inst()
< Number of trainer classes.
Definition trainers.cpp:38
TrainerDBEntry * getStoreAt(int idx) const
Trainer by store index (for QML).
Definition trainers.cpp:48
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition trainers.cpp:80
const QHash< QString, TrainerDBEntry * > getInd() const
Name->entry index.
Definition trainers.cpp:45
void load()
Load trainers from JSON.
Definition trainers.cpp:59
int getStoreSize() const
Trainer-class count.
Definition trainers.cpp:46
Project-wide fixed-width integer aliases (var8, var16, ...).
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition types.h:124
Import/export macro for the db library, plus the central list of DB entry pointer types declared opaq...
#define DB_AUTOPORT
Expands to the correct dllexport/dllimport decoration for this library.
Definition db_autoport.h:37
A map sprite that is a battleable trainer (type TRAINER).
One trainer-class definition (its name/index and flags).
Definition trainers.h:38
TrainerDBEntry()
Empty entry.
Definition trainers.cpp:29
QString name
Trainer-class name (key).
Definition trainers.h:42
bool unused
Whether this slot is unused.
Definition trainers.h:44
QVector< MapDBEntrySpriteTrainer * > tpMapSpriteTrainers
On-map trainers of this class (back-ref).
Definition trainers.h:47
var8 ind
Trainer-class index.
Definition trainers.h:43
bool opp
Whether it's an opponent class.
Definition trainers.h:45