mirror of
https://github.com/huderlem/porymap.git
synced 2026-09-29 03:16:51 -05:00
Merge pull request #456 from GriffinRichards/api-scale
Add scale to API's createImage, add getPorymapVersion
This commit is contained in:
@@ -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)
|
||||
@@ -480,14 +481,14 @@ void MainWindow::addImage(int x, int y, QString filepath, int layer, bool useCac
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
}
|
||||
|
||||
void MainWindow::createImage(int x, int y, QString filepath, int width, int height, unsigned offset, bool xflip, bool yflip, int paletteId, bool setTransparency, int layer, bool useCache) {
|
||||
void MainWindow::createImage(int x, int y, QString filepath, int width, int height, unsigned offset, qreal hScale, qreal vScale, int paletteId, bool setTransparency, int layer, bool useCache) {
|
||||
if (!this->ui || !this->ui->graphicsView_Map || !this->editor || !this->editor->map || !this->editor->map->layout
|
||||
|| !this->editor->map->layout->tileset_primary || !this->editor->map->layout->tileset_secondary)
|
||||
return;
|
||||
QList<QRgb> palette;
|
||||
if (paletteId != -1)
|
||||
palette = Tileset::getPalette(paletteId, this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary);
|
||||
if (this->ui->graphicsView_Map->getOverlay(layer)->addImage(x, y, filepath, useCache, width, height, offset, xflip, yflip, palette, setTransparency))
|
||||
if (this->ui->graphicsView_Map->getOverlay(layer)->addImage(x, y, filepath, useCache, width, height, offset, hScale, vScale, palette, setTransparency))
|
||||
this->ui->graphicsView_Map->scene()->update();
|
||||
}
|
||||
|
||||
@@ -1195,6 +1196,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();
|
||||
}
|
||||
|
||||
@@ -274,6 +274,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) {
|
||||
Tile tile = Tile();
|
||||
|
||||
|
||||
@@ -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()});
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ void Overlay::addRect(int x, int y, int width, int height, QString color, bool f
|
||||
this->items.append(new OverlayRect(x, y, width, height, QColor(color), filled));
|
||||
}
|
||||
|
||||
bool Overlay::addImage(int x, int y, QString filepath, bool useCache, int width, int height, unsigned offset, bool xflip, bool yflip, QList<QRgb> palette, bool setTransparency) {
|
||||
bool Overlay::addImage(int x, int y, QString filepath, bool useCache, int width, int height, unsigned offset, qreal hScale, qreal vScale, QList<QRgb> palette, bool setTransparency) {
|
||||
QImage image = useCache ? Scripting::getImage(filepath) : QImage(filepath);
|
||||
if (image.isNull()) {
|
||||
logError(QString("Failed to load image '%1'").arg(filepath));
|
||||
@@ -126,8 +126,8 @@ bool Overlay::addImage(int x, int y, QString filepath, bool useCache, int width,
|
||||
if (width != fullWidth || height != fullHeight)
|
||||
image = image.copy(offset % fullWidth, offset / fullWidth, width, height);
|
||||
|
||||
if (xflip || yflip)
|
||||
image = image.transformed(QTransform().scale(xflip ? -1 : 1, yflip ? -1 : 1));
|
||||
if (hScale != 1 || vScale != 1)
|
||||
image = image.transformed(QTransform().scale(hScale, vScale));
|
||||
|
||||
for (int i = 0; i < palette.size(); i++)
|
||||
image.setColor(i, palette.at(i));
|
||||
|
||||
Reference in New Issue
Block a user