34 static bool once =
false;
42 for(QJsonValue jsonEntry : jsonData.array())
56 static bool once =
false;
60 for(
auto entry : store)
63 ind.insert(entry->name, entry);
64 ind.insert(
"ind"+QString::number(entry->ind), entry);
74 el->qmlProtect(engine);
77void FontsDB::qmlRegister()
const
79 static bool once =
false;
83 qmlRegisterUncreatableType<FontsDB>(
"PSE.DB.FontsDB", 1, 0,
"FontsDB",
"Can't instantiate in QML");
100 return QScopedPointer<FontSearch, QScopedPointerDeleteLater>(
122 while (str.length() != 0) {
131 for (
int i = 0; i < store.length(); i++) {
136 if (!str.startsWith(transPair->
name))
143 str = str.mid(transPair->
name.length());
146 code.append(transPair->
ind);
147 lastCode = transPair->
ind;
159 if (code.length() >= maxLen || lastCode == 0x50)
179 for (
int i = 0; i < codes.length(); i++) {
188 if(ind.value(
"ind"+QString::number(code),
nullptr) ==
nullptr)
192 eng += ind.value(
"ind"+QString::number(code))->name;
205const QString
FontsDB::expandStr(
const QString msg,
const int maxLen,
const QString rival,
const QString player)
const
212 for(
int i = 0; i < charCodes.length(); i++) {
214 int code = charCodes[i];
220 charCodes = charCodes.mid(0, i);
227 else if(code == 75) {
228 charCodes = charCodes.mid(0, i);
235 else if(code == 76) {
236 charCodes = charCodes.mid(i+1, -1);
242 else if(code == 80) {
243 charCodes = charCodes.mid(0, i);
250 else if(code == 81) {
251 charCodes = charCodes.mid(0, i);
258 else if(code == 85) {
259 charCodes = charCodes.mid(0, i);
265 else if(code == 87) {
266 charCodes = charCodes.mid(i+1, -1);
271 else if(code == 88) {
272 charCodes = charCodes.mid(0, i);
280 for(
int i = 0; i < charCodes.length(); i++) {
283 int code = charCodes[i];
288 splice(charCodes,
"<pk><mn>", i);
291 else if (code == 0x52) {
292 splice(charCodes, player, i);
295 else if (code == 0x53) {
296 splice(charCodes, rival, i);
299 else if (code == 0x54) {
300 splice(charCodes,
"POK<e>", i);
303 else if (code == 0x56) {
304 splice(charCodes,
"<...><...>", i);
307 else if (code == 0x59) {
308 splice(charCodes,
"CHARIZARD", i);
311 else if (code == 0x5A) {
312 splice(charCodes,
"Enemy BLASTOISE", i);
315 else if (code == 0x5B) {
316 splice(charCodes,
"PC", i);
319 else if (code == 0x5C) {
320 splice(charCodes,
"TM", i);
323 else if (code == 0x5D) {
324 splice(charCodes,
"TRAINER", i);
327 else if (code == 0x5E) {
328 splice(charCodes,
"ROCKET", i);
333 else if(code == 78) {
336 charCodes = charCodes.mid(0, i);
343 else if(code == 79) {
346 charCodes = charCodes.mid(0, i);
354 else if(code == 95) {
355 splice(charCodes,
".", i);
361 ret = ret.replace(
"<next>",
"\n");
362 ret = ret.replace(
"<line>",
"\n");
369 static FontsDB* _inst =
new FontsDB();
390 if(ind < 0 || ind >= store.size())
393 return store.at(ind);
398 return ind.value(val,
nullptr);
406 if(ind >= store.size() ||
410 return store.at(ind);
434 expandStr(val, 255,
"1234567",
"1234567"), 255,
false).size();
437void FontsDB::splice(QVector<int>& out,
const QString in,
const int position)
const
444 out.remove(position);
445 for(
int i = 0; i < codes.size(); i++)
446 out.insert(position + i, codes.at(i));
A chainable filter ("finder") over the font glyphs.
const QHash< QString, FontDBEntry * > getInd() const
Name->glyph index.
FontDBEntry * getIndAt(const QString val) const
Glyph by name key (for QML).
static FontsDB * inst()
< Number of font glyphs.
FontSearch * searchRaw() const
Raw finder for QML (caller must delete; see note).
FontDBEntry * getStoreAt(const int ind) const
Glyph by store index (for QML).
void load()
Load glyphs from JSON.
const QVector< int > convertToCode(QString str, int maxLen=11, const bool autoEnd=true) const
String -> font codes (see note; expensive).
void index()
Build the name->glyph index.
int countSizeOfExpanded(const QString val) const
Rendered length after expandStr (expensive).
FontDBEntry * fontAt(int ind) const
Alias for getStoreAt (1-based-friendly UI accessor).
int countSizeOf(const QString val) const
Rendered length of val (expensive).
int getStoreSize() const
Glyph count.
const QString convertFromCode(const QVector< int > codes, const int maxLen=11) const
Font codes -> string (fast).
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
int fontCount() const
Alias for getStoreSize.
const QString expandStr(const QString msg, const int maxLen, const QString rival, const QString player) const
Expand English text to in-game form (substitutes rival/player).
const FontDBEntry * getStoreByVal(int ind) const
Glyph by its font-code value.
const QVector< FontDBEntry * > getStore() const
All glyphs.
QScopedPointer< FontSearch, QScopedPointerDeleteLater > search() const
C++-owned finder (smart pointer).
const QJsonDocument json(const QString filename) const
Parsed document for filename.
static GameData * inst()
The process-wide GameData singleton.
static void qmlProtectUtil(const QObject *const obj, const QQmlEngine *const engine)
Pin obj to C++ ownership so the QML engine never garbage-collects it.
One in-game font character: its code, output text, and classification flags.