Skip to content

Commit

Permalink
Scripting: Added tiled.projectFilePath
Browse files Browse the repository at this point in the history
There is still no scripting API for the project, but at least now you
can get the path of the current project.

Related to issue #2902.
  • Loading branch information
bjorn committed Nov 11, 2022
1 parent 33dc41e commit 462986c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Fixed new layer names to be always unique (by Logan Higinbotham, #3452)
* Scripting: Added Object.setColorProperty and Object.setFloatProperty (#3423)
* Scripting: Added tiled.projectFilePath
* Scripting: Allow assigning null to Tile.objectGroup (by Logan Higinbotham, #3495)
* Scripting: Allow changing the items in a combo box added to a dialog
* Scripting: Fixed painting issues after changing TileLayer size (#3481)
Expand Down
8 changes: 8 additions & 0 deletions docs/scripting-doc/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3335,6 +3335,14 @@ declare namespace tiled {
*/
export const extensionsPath: string;

/**
* The file path of the currently loaded project, or empty if no project is
* currently loaded.
*
* @since 1.9.3
*/
export const projectFilePath: string;

/**
* A list of arguments passed to a script that is evaluated from the
* command-line.
Expand Down
6 changes: 6 additions & 0 deletions src/tiled/scriptmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "logginginterface.h"
#include "mainwindow.h"
#include "mapeditor.h"
#include "projectmanager.h"
#include "scriptedaction.h"
#include "scriptedfileformat.h"
#include "scriptedtool.h"
Expand Down Expand Up @@ -116,6 +117,11 @@ QString ScriptModule::applicationDirPath() const
return QCoreApplication::applicationDirPath();
}

QString ScriptModule::projectFilePath() const
{
return ProjectManager::instance()->project().fileName();
}

QStringList ScriptModule::scriptArguments() const
{
return mScriptArguments;
Expand Down
2 changes: 2 additions & 0 deletions src/tiled/scriptmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ScriptModule : public QObject
Q_PROPERTY(QString arch READ arch)
Q_PROPERTY(QString extensionsPath READ extensionsPath)
Q_PROPERTY(QString applicationDirPath READ applicationDirPath)
Q_PROPERTY(QString projectFilePath READ projectFilePath)
Q_PROPERTY(QStringList scriptArguments READ scriptArguments)

Q_PROPERTY(QStringList actions READ actions)
Expand All @@ -81,6 +82,7 @@ class ScriptModule : public QObject
QString arch() const;
QString extensionsPath() const;
QString applicationDirPath() const;
QString projectFilePath() const;

QStringList scriptArguments() const;
void setScriptArguments(const QStringList &arguments);
Expand Down

0 comments on commit 462986c

Please sign in to comment.