Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
scripts.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#include <optional>
24
25#include <pse-common/types.h>
26#include "./db_autoport.h"
27
28struct MapDBEntry;
29class QQmlEngine;
30
42 ScriptDBEntry(QJsonValue& data);
43 void deepLink();
44
45 QString name;
46 var8 ind = 0;
47 var8 size = 0;
48
49 QVector<QString> maps;
50 std::optional<var8> skip;
51
52 QVector<MapDBEntry*> toMaps;
53};
54
62class DB_AUTOPORT ScriptsDB : public QObject
63{
64 Q_OBJECT
65 Q_PROPERTY(int getStoreSize READ getStoreSize CONSTANT)
66
67public:
68 static ScriptsDB* inst();
69
70 [[nodiscard]] const QVector<ScriptDBEntry*> getStore() const;
71 [[nodiscard]] const QHash<QString, ScriptDBEntry*> getInd() const;
72 [[nodiscard]] int getStoreSize() const;
73
74 Q_INVOKABLE ScriptDBEntry* getStoreAt(int idx) const;
75 Q_INVOKABLE ScriptDBEntry* getIndAt(const QString& key) const;
76
77public slots:
78 void load();
79 void index();
80 void deepLink();
81 void qmlProtect(const QQmlEngine* const engine) const;
82
83private slots:
84 void qmlRegister() const;
85
86private:
87 ScriptsDB();
88
89 QVector<ScriptDBEntry*> store;
90 QHash<QString, ScriptDBEntry*> ind;
91};
int getStoreSize() const
Script count.
Definition scripts.cpp:75
void deepLink()
Resolve each script's map links.
Definition scripts.cpp:109
const QHash< QString, ScriptDBEntry * > getInd() const
Name->entry index.
Definition scripts.cpp:74
void load()
Load scripts from JSON.
Definition scripts.cpp:88
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition scripts.cpp:118
static ScriptsDB * inst()
< Number of scripts.
Definition scripts.cpp:67
ScriptDBEntry * getIndAt(const QString &key) const
Script by name key (for QML).
Definition scripts.cpp:83
const QVector< ScriptDBEntry * > getStore() const
All scripts.
Definition scripts.cpp:73
void index()
Build the name->entry index.
Definition scripts.cpp:98
ScriptDBEntry * getStoreAt(int idx) const
Script by store index (for QML).
Definition scripts.cpp:77
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
One map's complete static definition – the root of the MapDBEntry family.
Definition mapdbentry.h:56
One map-script definition: its id/size and which maps use it.
Definition scripts.h:40
var8 size
Script size.
Definition scripts.h:47
QVector< MapDBEntry * > toMaps
Resolved map entries (deepLink).
Definition scripts.h:52
void deepLink()
Resolve the maps names to entries.
Definition scripts.cpp:53
std::optional< var8 > skip
Optional skip value.
Definition scripts.h:50
var8 ind
Script index.
Definition scripts.h:46
QVector< QString > maps
Map names using this script.
Definition scripts.h:49
ScriptDBEntry()
Empty entry.
Definition scripts.cpp:35
QString name
Script name (key).
Definition scripts.h:45