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

@ -1167,6 +1167,12 @@ The following functions are related to settings.
:returns string: ``"pokeruby"``, ``"pokefirered"``, or ``"pokeemerald"``
.. js:function:: map.getPorymapVersion()
Gets the current version of Porymap (``MAJOR.MINOR.PATCH``).
:returns {major, minor, patch}: the version object
.. js:function:: map.getCustomScripts()
Gets the list of paths to custom scripts.

View file

@ -16,7 +16,7 @@
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<widget class="QLabel" name="label_Title">
<property name="font">
<font>
<family>Segoe UI</family>
@ -39,7 +39,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<widget class="QLabel" name="label_Version">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -61,7 +61,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="label_Description">
<property name="font">
<font>
<family>Segoe UI</family>
@ -76,7 +76,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<widget class="QLabel" name="label_Manual">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Official Documentation: &lt;a href=&quot;https://huderlem.github.io/porymap/&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;https://huderlem.github.io/porymap/&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>

View file

@ -177,6 +177,7 @@ public:
Q_INVOKABLE int getNumTilesInMetatile();
Q_INVOKABLE int getNumMetatileLayers();
Q_INVOKABLE QString getBaseGameVersion();
Q_INVOKABLE QJSValue getPorymapVersion();
Q_INVOKABLE QList<QString> getCustomScripts();
Q_INVOKABLE int getMainTab();
Q_INVOKABLE void setMainTab(int index);

View file

@ -29,6 +29,7 @@ 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 QJSEngine *getEngine();

View file

@ -1,6 +1,8 @@
#ifndef ABOUTPORYMAP_H
#define ABOUTPORYMAP_H
#include <QString>
#include <QRegularExpression>
#include <QMainWindow>
namespace Ui {
@ -12,6 +14,7 @@ class AboutPorymap : public QMainWindow
public:
explicit AboutPorymap(QWidget *parent = nullptr);
~AboutPorymap();
QList<int> getVersionNumbers();
private:
Ui::AboutPorymap *ui;
};

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()});
}