Move version info to porymap.pro

This commit is contained in:
GriffinR 2024-01-21 00:14:40 -05:00
parent 09c2ed6b30
commit 97b485284e
7 changed files with 27 additions and 37 deletions

View file

@ -52,9 +52,6 @@
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Version 5.3.0 - January 15th, 2024</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>

View file

@ -52,7 +52,6 @@ public:
static QJSValue fromBlock(Block block);
static QJSValue fromTile(Tile tile);
static Tile toTile(QJSValue obj);
static QJSValue version(QList<int> versionNums);
static QJSValue dimensions(int width, int height);
static QJSValue position(int x, int y);
static const QImage * getImage(const QString &filepath, bool useCache);

View file

@ -14,7 +14,6 @@ class AboutPorymap : public QMainWindow
public:
explicit AboutPorymap(QWidget *parent = nullptr);
~AboutPorymap();
QList<int> getVersionNumbers();
private:
Ui::AboutPorymap *ui;
};

View file

@ -14,6 +14,14 @@ RC_ICONS = resources/icons/porymap-icon-2.ico
ICON = resources/icons/porymap.icns
QMAKE_CXXFLAGS += -std=c++17 -Wall
QMAKE_TARGET_BUNDLE_PREFIX = com.pret
VERSION_MAJOR = 5
VERSION_MINOR = 3
VERSION_PATCH = 0
VERSION = $${VERSION_MAJOR}.$${VERSION_MINOR}.$${VERSION_PATCH}
DEFINES += PORYMAP_VERSION_MAJOR=$$VERSION_MAJOR \
PORYMAP_VERSION_MINOR=$$VERSION_MINOR \
PORYMAP_VERSION_PATCH=$$VERSION_PATCH \
PORYMAP_VERSION=\\\"$$VERSION\\\"
SOURCES += src/core/block.cpp \
src/core/bitpacker.cpp \

View file

@ -53,6 +53,7 @@ MainWindow::MainWindow(QWidget *parent) :
{
QCoreApplication::setOrganizationName("pret");
QCoreApplication::setApplicationName("porymap");
QCoreApplication::setApplicationVersion(PORYMAP_VERSION);
QApplication::setApplicationDisplayName("porymap");
QApplication::setWindowIcon(QIcon(":/icons/porymap-icon-2.ico"));
ui->setupUi(this);
@ -301,7 +302,17 @@ void MainWindow::checkForUpdates(bool requestedByUser) {
const QString changelog = release.value("body").toString();
if (changelog.isEmpty()) break;
// TODO: Compare version to host version, then show appropriate dialog
bool newVersionAvailable;
if (major != PORYMAP_VERSION_MAJOR) {
newVersionAvailable = major > PORYMAP_VERSION_MAJOR;
} else if (minor != PORYMAP_VERSION_MINOR) {
newVersionAvailable = minor > PORYMAP_VERSION_MINOR;
} else {
newVersionAvailable = patch > PORYMAP_VERSION_PATCH;
}
logInfo(QString("Host version is %1").arg(newVersionAvailable ? "old" : "up to date"));
// TODO: Show appropriate dialog
break;
}
});

View file

@ -1,7 +1,6 @@
#include "scripting.h"
#include "log.h"
#include "config.h"
#include "aboutporymap.h"
QMap<CallbackType, QString> callbackFunctions = {
{OnProjectOpened, "onProjectOpened"},
@ -77,15 +76,12 @@ void Scripting::populateGlobalObject(MainWindow *mainWindow) {
QJSValue constants = instance->engine->newObject();
// Invisibly create an "About" window to read Porymap version
AboutPorymap *about = new AboutPorymap(mainWindow);
if (about) {
QJSValue version = Scripting::version(about->getVersionNumbers());
constants.setProperty("version", version);
delete about;
} else {
logError("Failed to read Porymap version for API");
}
// Get version numbers
QJSValue version = instance->engine->newObject();
version.setProperty("major", PORYMAP_VERSION_MAJOR);
version.setProperty("minor", PORYMAP_VERSION_MINOR);
version.setProperty("patch", PORYMAP_VERSION_PATCH);
constants.setProperty("version", version);
// Get basic tileset information
int numTilesPrimary = Project::getNumTilesPrimary();
@ -343,14 +339,6 @@ QJSValue Scripting::position(int x, int y) {
return obj;
}
QJSValue Scripting::version(QList<int> versionNums) {
QJSValue obj = instance->engine->newObject();
obj.setProperty("major", versionNums.at(0));
obj.setProperty("minor", versionNums.at(1));
obj.setProperty("patch", versionNums.at(2));
return obj;
}
Tile Scripting::toTile(QJSValue obj) {
Tile tile = Tile();

View file

@ -8,6 +8,7 @@ AboutPorymap::AboutPorymap(QWidget *parent) :
{
ui->setupUi(this);
this->ui->label_Version->setText(QString("Version %1 - %2").arg(PORYMAP_VERSION).arg(QStringLiteral(__DATE__)));
this->ui->textBrowser->setSource(QUrl("qrc:/CHANGELOG.md"));
}
@ -15,16 +16,3 @@ AboutPorymap::~AboutPorymap()
{
delete ui;
}
// Returns the Porymap version number as a list of ints with the order {major, minor, patch}
QList<int> AboutPorymap::getVersionNumbers()
{
// Get the version string "#.#.#"
static const QRegularExpression regex("Version (\\d+)\\.(\\d+)\\.(\\d+)");
QRegularExpressionMatch match = regex.match(ui->label_Version->text());
if (!match.hasMatch()) {
logError("Failed to locate Porymap version text");
return QList<int>({0, 0, 0});
}
return QList<int>({match.captured(1).toInt(), match.captured(2).toInt(), match.captured(3).toInt()});
}