Add getPorymapVersion

This commit is contained in:
GriffinR
2022-08-31 13:38:07 -04:00
parent af2f1b6f7d
commit 268cc9b30b
8 changed files with 42 additions and 4 deletions

View File

@@ -4,6 +4,7 @@
#include "editcommands.h"
#include "config.h"
#include "imageproviders.h"
#include "aboutporymap.h"
QJSValue MainWindow::getBlock(int x, int y) {
if (!this->editor || !this->editor->map)
@@ -1051,6 +1052,13 @@ QString MainWindow::getBaseGameVersion() {
return projectConfig.getBaseGameVersionString();
}
QJSValue MainWindow::getPorymapVersion() {
AboutPorymap *window = new AboutPorymap(this);
QJSValue version = Scripting::version(window->getVersionNumbers());
delete window;
return version;
}
QList<QString> MainWindow::getCustomScripts() {
return projectConfig.getCustomScripts();
}

View File

@@ -238,6 +238,14 @@ 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) {
if (!obj.hasProperty("tileId")
|| !obj.hasProperty("xflip")

View File

@@ -12,3 +12,14 @@ 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 "#.#.#"
QRegularExpression regex("Version (\\d+)\\.(\\d+)\\.(\\d+)");
QRegularExpressionMatch match = regex.match(ui->label_Version->text());
if (!match.hasMatch())
return QList<int>({0, 0, 0});
return QList<int>({match.captured(1).toInt(), match.captured(2).toInt(), match.captured(3).toInt()});
}