38 name = data[
"name"].toString();
39 ind =
static_cast<var8>(data[
"ind"].toDouble());
40 readable = data[
"readable"].toString();
42 if (data[
"glitch"].isBool())
glitch = data[
"glitch"].toBool();
43 if (data[
"type"].isString())
type = data[
"type"].toString();
44 if (data[
"power"].isDouble())
power =
static_cast<var8>(data[
"power"].toDouble());
45 if (data[
"accuracy"].isDouble())
accuracy =
static_cast<var8>(data[
"accuracy"].toDouble());
46 if (data[
"pp"].isDouble())
pp =
static_cast<var8>(data[
"pp"].toDouble());
47 if (data[
"tm"].isDouble())
tm =
static_cast<var8>(data[
"tm"].toDouble());
48 if (data[
"hm"].isDouble())
hm =
static_cast<var8>(data[
"hm"].toDouble());
63 qCritical() <<
"Move type:" <<
type <<
"could not be deep linked.";
65 qCritical() <<
"Move:" <<
name <<
"TM/HM item could not be deep linked.";
69 toType->toMoves.append(
this);
74 static MovesDB* _inst =
new MovesDB;
84 if (idx < 0 || idx >= store.size())
return nullptr;
90 return ind.value(key,
nullptr);
95 static bool once =
false;
98 for (QJsonValue entry : jsonData.array())
105 static bool once =
false;
107 for (
auto* entry : store) {
108 ind.insert(entry->name, entry);
109 ind.insert(QString::number(entry->ind), entry);
110 ind.insert(entry->readable, entry);
111 if (entry->tm) ind.insert(
"tm" + QString::number(*entry->tm), entry);
112 if (entry->hm) ind.insert(
"hm" + QString::number(*entry->hm), entry);
119 static bool once =
false;
121 for (
auto* entry : store)
131void MovesDB::qmlRegister()
const
133 static bool once =
false;
135 qmlRegisterUncreatableType<MovesDB>(
"PSE.DB.MovesDB", 1, 0,
"MovesDB",
"Can't instantiate in QML");
const QJsonDocument json(const QString filename) const
Parsed document for filename.
static GameData * inst()
The process-wide GameData singleton.
ItemDBEntry * getIndAt(const QString val) const
Item by name key (for QML).
static ItemsDB * inst()
< Number of items.
void load()
Load moves from JSON.
void deepLink()
Resolve every move's cross-DB links.
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
int getStoreSize() const
Move count.
const QHash< QString, MoveDBEntry * > getInd() const
Name->entry index.
void index()
Build the name->entry index.
MoveDBEntry * getStoreAt(int idx) const
Move by store index (for QML).
const QVector< MoveDBEntry * > getStore() const
All moves, in load order.
MoveDBEntry * getIndAt(const QString &key) const
Move by name key (for QML).
static MovesDB * inst()
< Number of moves.
TypeDBEntry * getIndAt(const QString &key) const
Type by name key (for QML).
static TypesDB * inst()
< Number of types.
static void qmlProtectUtil(const QObject *const obj, const QQmlEngine *const engine)
Pin obj to C++ ownership so the QML engine never garbage-collects it.
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
One move's static data (type, power, accuracy, PP, TM/HM), with links.
std::optional< var8 > hm
HM number teaching this move, if any.
QString type
Type name (resolved to toType).
ItemDBEntry * toItem
Resolved TM/HM item entry (deepLink).
std::optional< var8 > pp
Base PP, if any.
std::optional< var8 > accuracy
Accuracy, if any.
void deepLink()
Resolve cross-DB links (type, item) after load.
TypeDBEntry * toType
Resolved type entry (deepLink).
std::optional< var8 > power
Base power, if any.
QString readable
Human-readable display name.
std::optional< var8 > tm
TM number teaching this move, if any.
QString name
Internal move name (key).
bool glitch
Whether this is a glitch move.
MoveDBEntry()
Empty entry.