diff --git a/forms/aboutporymap.ui b/forms/aboutporymap.ui
index cfe22bf5..f823396c 100644
--- a/forms/aboutporymap.ui
+++ b/forms/aboutporymap.ui
@@ -52,9 +52,6 @@
12
-
- Version 5.3.0 - January 15th, 2024
-
Qt::AlignCenter
diff --git a/include/scripting.h b/include/scripting.h
index 7fd2a170..fb96e7ae 100644
--- a/include/scripting.h
+++ b/include/scripting.h
@@ -52,7 +52,6 @@ public:
static QJSValue fromBlock(Block block);
static QJSValue fromTile(Tile tile);
static Tile toTile(QJSValue obj);
- static QJSValue version(QList versionNums);
static QJSValue dimensions(int width, int height);
static QJSValue position(int x, int y);
static const QImage * getImage(const QString &filepath, bool useCache);
diff --git a/include/ui/aboutporymap.h b/include/ui/aboutporymap.h
index cc6cb6e8..28b06249 100644
--- a/include/ui/aboutporymap.h
+++ b/include/ui/aboutporymap.h
@@ -14,7 +14,6 @@ class AboutPorymap : public QMainWindow
public:
explicit AboutPorymap(QWidget *parent = nullptr);
~AboutPorymap();
- QList getVersionNumbers();
private:
Ui::AboutPorymap *ui;
};
diff --git a/porymap.pro b/porymap.pro
index 90072830..f5cb0452 100644
--- a/porymap.pro
+++ b/porymap.pro
@@ -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 \
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 6e2ca509..f98b3a30 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -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;
}
});
diff --git a/src/scriptapi/scripting.cpp b/src/scriptapi/scripting.cpp
index 626f820b..aa547724 100644
--- a/src/scriptapi/scripting.cpp
+++ b/src/scriptapi/scripting.cpp
@@ -1,7 +1,6 @@
#include "scripting.h"
#include "log.h"
#include "config.h"
-#include "aboutporymap.h"
QMap 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 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();
diff --git a/src/ui/aboutporymap.cpp b/src/ui/aboutporymap.cpp
index ce0a1fe4..96f20ee8 100644
--- a/src/ui/aboutporymap.cpp
+++ b/src/ui/aboutporymap.cpp
@@ -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 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({0, 0, 0});
- }
- return QList({match.captured(1).toInt(), match.captured(2).toInt(), match.captured(3).toInt()});
-}