Add support for opening .inc scripts to the selected event script
This commit is contained in:
parent
3478846b60
commit
4aaae1a264
6 changed files with 67 additions and 20 deletions
|
@ -40,8 +40,8 @@ class ParseUtil
|
||||||
public:
|
public:
|
||||||
ParseUtil();
|
ParseUtil();
|
||||||
void set_root(QString);
|
void set_root(QString);
|
||||||
QString readTextFile(QString);
|
static QString readTextFile(QString);
|
||||||
void strip_comment(QString*);
|
static void strip_comment(QString*);
|
||||||
QList<QStringList>* parseAsm(QString);
|
QList<QStringList>* parseAsm(QString);
|
||||||
int evaluateDefine(QString, QMap<QString, int>*);
|
int evaluateDefine(QString, QMap<QString, int>*);
|
||||||
QStringList readCArray(QString text, QString label);
|
QStringList readCArray(QString text, QString label);
|
||||||
|
@ -54,6 +54,10 @@ public:
|
||||||
bool tryParseJsonFile(QJsonDocument *out, QString filepath);
|
bool tryParseJsonFile(QJsonDocument *out, QString filepath);
|
||||||
bool ensureFieldsExist(QJsonObject obj, QList<QString> fields);
|
bool ensureFieldsExist(QJsonObject obj, QList<QString> fields);
|
||||||
|
|
||||||
|
// Returns the 1-indexed line number for the definition of scriptLabel in the scripts file at filePath.
|
||||||
|
// Returns 0 if a definition for scriptLabel cannot be found.
|
||||||
|
static int getScriptLineNumber(const QString &scriptLabel, const QString &filePath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString root;
|
QString root;
|
||||||
QString text;
|
QString text;
|
||||||
|
|
|
@ -154,6 +154,7 @@ public:
|
||||||
void scaleMapView(int);
|
void scaleMapView(int);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void openMapScripts() const;
|
||||||
void maskNonVisibleConnectionTiles();
|
void maskNonVisibleConnectionTiles();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -183,6 +184,7 @@ private:
|
||||||
QString getMovementPermissionText(uint16_t collision, uint16_t elevation);
|
QString getMovementPermissionText(uint16_t collision, uint16_t elevation);
|
||||||
QString getMetatileDisplayMessage(uint16_t metatileId);
|
QString getMetatileDisplayMessage(uint16_t metatileId);
|
||||||
bool eventLimitReached(Map *, QString);
|
bool eventLimitReached(Map *, QString);
|
||||||
|
QString constructTextEditorCommand(QString commandTemplate, const QString &path) const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onMapStartPaint(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
|
void onMapStartPaint(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
|
||||||
|
|
|
@ -119,8 +119,6 @@ private slots:
|
||||||
|
|
||||||
void duplicate();
|
void duplicate();
|
||||||
|
|
||||||
void openInTextEditor();
|
|
||||||
|
|
||||||
void onLoadMapRequested(QString, QString);
|
void onLoadMapRequested(QString, QString);
|
||||||
void onMapChanged(Map *map);
|
void onMapChanged(Map *map);
|
||||||
void onMapNeedsRedrawing();
|
void onMapNeedsRedrawing();
|
||||||
|
@ -164,7 +162,6 @@ private slots:
|
||||||
void on_actionMap_Shift_triggered();
|
void on_actionMap_Shift_triggered();
|
||||||
|
|
||||||
void on_toolButton_deleteObject_clicked();
|
void on_toolButton_deleteObject_clicked();
|
||||||
void on_toolButton_Open_Scripts_clicked();
|
|
||||||
|
|
||||||
void addNewEvent(QString);
|
void addNewEvent(QString);
|
||||||
void updateSelectedObjects();
|
void updateSelectedObjects();
|
||||||
|
|
|
@ -420,3 +420,22 @@ bool ParseUtil::ensureFieldsExist(QJsonObject obj, QList<QString> fields) {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ParseUtil::getScriptLineNumber(const QString &scriptLabel, const QString &filePath) {
|
||||||
|
if (filePath.endsWith(".inc")) {
|
||||||
|
const QString text = readTextFile(filePath);
|
||||||
|
const QStringList lines = text.split('\n');
|
||||||
|
for (int lineNumber = 0; lineNumber < lines.count(); ++lineNumber) {
|
||||||
|
QString line = lines.at(lineNumber);
|
||||||
|
strip_comment(&line);
|
||||||
|
if (line.contains(':')) {
|
||||||
|
const QString parsedLabel = line.left(line.indexOf(':')).trimmed();
|
||||||
|
if (parsedLabel == scriptLabel)
|
||||||
|
return lineNumber + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (filePath.endsWith(".pory")) {
|
||||||
|
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "metatile.h"
|
#include "metatile.h"
|
||||||
#include "montabwidget.h"
|
#include "montabwidget.h"
|
||||||
#include "editcommands.h"
|
#include "editcommands.h"
|
||||||
|
#include "config.h"
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
@ -1999,6 +2000,44 @@ void Editor::deleteEvent(Event *event) {
|
||||||
//updateSelectedObjects();
|
//updateSelectedObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::openMapScripts() const {
|
||||||
|
const QString path = project->getMapScriptsFilePath(map->name);
|
||||||
|
const QString commandTemplate = porymapConfig.getTextEditorCommandTemplate();
|
||||||
|
if (commandTemplate.isEmpty()) {
|
||||||
|
// Open map scripts in the system's default editor.
|
||||||
|
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
||||||
|
} else {
|
||||||
|
const QString command = constructTextEditorCommand(commandTemplate, path);
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
// On Windows, a QProcess command must be wrapped in a cmd.exe command.
|
||||||
|
const QString program = QProcessEnvironment::systemEnvironment().value("COMSPEC");
|
||||||
|
QStringList arguments({ QString("/c"), command });
|
||||||
|
#else
|
||||||
|
QStringList arguments = QProcess::splitCommand(command);
|
||||||
|
const QString program = arguments.takeFirst();
|
||||||
|
#endif
|
||||||
|
static QProcess proc;
|
||||||
|
proc.setProgram(program);
|
||||||
|
proc.setArguments(arguments);
|
||||||
|
proc.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Editor::constructTextEditorCommand(QString commandTemplate, const QString &path) const {
|
||||||
|
if (commandTemplate.contains("%F")) {
|
||||||
|
if (commandTemplate.contains("%L")) {
|
||||||
|
const QString scriptLabel = selected_events->isEmpty() ?
|
||||||
|
QString() : selected_events->first()->event->get("script_label");
|
||||||
|
const int lineNum = ParseUtil::getScriptLineNumber(scriptLabel, path);
|
||||||
|
commandTemplate.replace("%L", QString::number(lineNum));
|
||||||
|
}
|
||||||
|
commandTemplate.replace("%F", path);
|
||||||
|
} else {
|
||||||
|
commandTemplate += path;
|
||||||
|
}
|
||||||
|
return commandTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
// It doesn't seem to be possible to prevent the mousePress event
|
// It doesn't seem to be possible to prevent the mousePress event
|
||||||
// from triggering both event's DraggablePixmapItem and the background mousePress.
|
// from triggering both event's DraggablePixmapItem and the background mousePress.
|
||||||
// Since the DraggablePixmapItem's event fires first, we can set a temp
|
// Since the DraggablePixmapItem's event fires first, we can set a temp
|
||||||
|
|
|
@ -154,6 +154,7 @@ void MainWindow::initEditor() {
|
||||||
connect(this->editor, SIGNAL(warpEventDoubleClicked(QString,QString)), this, SLOT(openWarpMap(QString,QString)));
|
connect(this->editor, SIGNAL(warpEventDoubleClicked(QString,QString)), this, SLOT(openWarpMap(QString,QString)));
|
||||||
connect(this->editor, SIGNAL(currentMetatilesSelectionChanged()), this, SLOT(currentMetatilesSelectionChanged()));
|
connect(this->editor, SIGNAL(currentMetatilesSelectionChanged()), this, SLOT(currentMetatilesSelectionChanged()));
|
||||||
connect(this->editor, SIGNAL(wildMonDataChanged()), this, SLOT(onWildMonDataChanged()));
|
connect(this->editor, SIGNAL(wildMonDataChanged()), this, SLOT(onWildMonDataChanged()));
|
||||||
|
connect(ui->toolButton_Open_Scripts, &QToolButton::clicked, this->editor, &Editor::openMapScripts);
|
||||||
|
|
||||||
this->loadUserSettings();
|
this->loadUserSettings();
|
||||||
|
|
||||||
|
@ -1293,16 +1294,6 @@ void MainWindow::duplicate() {
|
||||||
editor->duplicateSelectedEvents();
|
editor->duplicateSelectedEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open current map scripts in system default editor for .inc files
|
|
||||||
void MainWindow::openInTextEditor() {
|
|
||||||
bool usePoryscript = projectConfig.getUsePoryScript();
|
|
||||||
QString path = QDir::cleanPath("file://" + editor->project->root + QDir::separator() + "data/maps/" + editor->map->name + "/scripts");
|
|
||||||
|
|
||||||
// Try opening scripts file, if opening .pory failed try again with .inc
|
|
||||||
if (!QDesktopServices::openUrl(QUrl(path + editor->project->getScriptFileExtension(usePoryscript))) && usePoryscript)
|
|
||||||
QDesktopServices::openUrl(QUrl(path + editor->project->getScriptFileExtension(false)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_action_Save_triggered() {
|
void MainWindow::on_action_Save_triggered() {
|
||||||
editor->save();
|
editor->save();
|
||||||
updateMapList();
|
updateMapList();
|
||||||
|
@ -2093,11 +2084,6 @@ void MainWindow::on_toolButton_deleteObject_clicked() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_toolButton_Open_Scripts_clicked()
|
|
||||||
{
|
|
||||||
openInTextEditor();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_toolButton_Paint_clicked()
|
void MainWindow::on_toolButton_Paint_clicked()
|
||||||
{
|
{
|
||||||
if (ui->mainTabBar->currentIndex() == 0)
|
if (ui->mainTabBar->currentIndex() == 0)
|
||||||
|
|
Loading…
Reference in a new issue