mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-21 20:27:45 +00:00
Remove GameParser class
This commit is contained in:
parent
f1b2241a24
commit
bdcbcd9fc1
2 changed files with 0 additions and 127 deletions
|
@ -1,38 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QImage>
|
|
||||||
#include <leptonica/allheaders.h>
|
|
||||||
#include <tesseract/baseapi.h>
|
|
||||||
|
|
||||||
enum class ScreenState { Splash, LobbyError, WorldFull, ConnectingToDataCenter, EnteredTitleScreen, InLoginQueue };
|
|
||||||
|
|
||||||
struct GameParseResult {
|
|
||||||
ScreenState state;
|
|
||||||
|
|
||||||
int playersInQueue = -1;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool operator==(const GameParseResult a, const GameParseResult b)
|
|
||||||
{
|
|
||||||
return a.state == b.state && a.playersInQueue == b.playersInQueue;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator!=(const GameParseResult a, const GameParseResult b)
|
|
||||||
{
|
|
||||||
return !(a == b);
|
|
||||||
}
|
|
||||||
|
|
||||||
class GameParser
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GameParser();
|
|
||||||
~GameParser();
|
|
||||||
|
|
||||||
GameParseResult parseImage(QImage image);
|
|
||||||
|
|
||||||
private:
|
|
||||||
tesseract::TessBaseAPI *api;
|
|
||||||
};
|
|
|
@ -1,89 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
#include "gameparser.h"
|
|
||||||
|
|
||||||
#include <QBuffer>
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QRegularExpression>
|
|
||||||
|
|
||||||
GameParser::GameParser()
|
|
||||||
{
|
|
||||||
api = new tesseract::TessBaseAPI();
|
|
||||||
|
|
||||||
if (api->Init(nullptr, "eng")) {
|
|
||||||
qDebug() << "Could not initialize tesseract!";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
api->SetPageSegMode(tesseract::PageSegMode::PSM_SINGLE_BLOCK);
|
|
||||||
}
|
|
||||||
|
|
||||||
GameParser::~GameParser()
|
|
||||||
{
|
|
||||||
api->End();
|
|
||||||
delete api;
|
|
||||||
}
|
|
||||||
|
|
||||||
GameParseResult GameParser::parseImage(QImage img)
|
|
||||||
{
|
|
||||||
QBuffer buf;
|
|
||||||
img = img.convertToFormat(QImage::Format_Grayscale8);
|
|
||||||
img.save(&buf, "PNG", 100);
|
|
||||||
|
|
||||||
Pix *image = pixReadMem((const l_uint8 *)buf.data().data(), buf.size());
|
|
||||||
api->SetImage(image);
|
|
||||||
api->SetSourceResolution(300);
|
|
||||||
|
|
||||||
const QString text = api->GetUTF8Text();
|
|
||||||
|
|
||||||
// TODO: clean up these names
|
|
||||||
const bool hasWorldFullText = text.contains("This World is currently full.") || text.contains("Players in queue");
|
|
||||||
const bool hasLobbyErrorText = text.contains("The lobby server connection has encountered an error.");
|
|
||||||
const bool hasCONFIGURATIONText = text.contains("CONFIGURATION") || text.contains("ONLINE");
|
|
||||||
const bool hasConnectingToData = text.contains("Connecting to data center");
|
|
||||||
const bool worldTotallyFull = text.contains("3001");
|
|
||||||
|
|
||||||
if (hasLobbyErrorText) {
|
|
||||||
qDebug() << "LOBBY ERROR";
|
|
||||||
|
|
||||||
return {ScreenState::LobbyError, -1};
|
|
||||||
} else {
|
|
||||||
if (worldTotallyFull) {
|
|
||||||
qDebug() << "TOTALLY FULL WORLD (CLOSED BY SQENIX)";
|
|
||||||
|
|
||||||
return {ScreenState::WorldFull, -1};
|
|
||||||
} else {
|
|
||||||
if (hasConnectingToData) {
|
|
||||||
qDebug() << "CONNECTING TO DATA CENTER";
|
|
||||||
|
|
||||||
return {ScreenState::ConnectingToDataCenter, -1};
|
|
||||||
} else {
|
|
||||||
if (hasWorldFullText) {
|
|
||||||
qDebug() << "FULL WORLD";
|
|
||||||
|
|
||||||
// attempt to extract number of players in queue
|
|
||||||
QRegularExpression exp("(?:Players in queue: )([\\d|,]*)");
|
|
||||||
|
|
||||||
auto match = exp.match(text);
|
|
||||||
if (match.isValid()) {
|
|
||||||
return {ScreenState::InLoginQueue, match.captured(1).remove(',').toInt()};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {ScreenState::InLoginQueue, -1};
|
|
||||||
} else {
|
|
||||||
if (hasCONFIGURATIONText) {
|
|
||||||
qDebug() << "TITLE SCREEN";
|
|
||||||
return {ScreenState::EnteredTitleScreen, -1};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: figure out how to properly clear tesseract data
|
|
||||||
api->Clear();
|
|
||||||
api->ClearAdaptiveClassifier();
|
|
||||||
|
|
||||||
return {ScreenState::Splash, -1};
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue