Skip to content

Commit

Permalink
Added --project command-line parameter for use when exporting
Browse files Browse the repository at this point in the history
This allows the --export-map and --export-tileset parameters to use file
formats defined by extensions in the project, and also enables handling
of custom types.

Closes #3797
  • Loading branch information
bjorn committed Jan 12, 2024
1 parent a4386c5 commit 018dd3a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
### Unreleased

* Added --project command-line parameter for use when exporting (#3797)
* JSON format: Fixed tile order when loading a tileset using the old format
* tmxrasterizer: Added --hide-object and --show-object arguments (by Lars Luz, #3819)
* tmxviewer: Added support for viewing JSON maps (#3866)
* tmxrasterizer: Added --frames and --frame-duration arguments to export animated maps as multiple images (#3868)
* tmxviewer: Added support for viewing JSON maps (#3866)
* Windows: Fixed the support for WebP images (updated to Qt 6.5.3, #3661)
* Fixed mouse handling issue when zooming while painting (#3863)
* Fixed possible crash after a scripted tool disappears while active
Expand Down
3 changes: 2 additions & 1 deletion src/tiled/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "command.h"
#include "object.h"
#include "tiled.h"
#include "tilededitor_global.h"

#include <QDateTime>
#include <QStringList>
Expand All @@ -32,7 +33,7 @@

namespace Tiled {

class Project : public Object
class TILED_EDITOR_EXPORT Project : public Object
{
public:
Project();
Expand Down
2 changes: 1 addition & 1 deletion src/tiled/projectmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ProjectModel;
*
* No dependencies.
*/
class ProjectManager : public QObject
class TILED_EDITOR_EXPORT ProjectManager : public QObject
{
Q_OBJECT

Expand Down
32 changes: 32 additions & 0 deletions src/tiledapp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class CommandLineHandler : public CommandLineParser
void showVersion();
void justQuit();
void setDisableOpenGL();
void setProject();
void setExportMap();
void setExportTileset();
void setExportEmbedTilesets();
Expand All @@ -118,6 +119,16 @@ class CommandLineHandler : public CommandLineParser

static void initializePluginsAndExtensions()
{
// Load the project without restoring the session
if (!Preferences::startupProject().isEmpty()) {
if (auto project = Project::load(Preferences::startupProject())) {
ProjectManager::instance()->setProject(std::move(project));
} else {
qWarning().noquote() << QCoreApplication::translate("Command line", "Failed to load project '%1'.")
.arg(Preferences::startupProject());
}
}

PluginManager::instance()->loadPlugins();
ScriptManager::instance().ensureInitialized();
}
Expand Down Expand Up @@ -193,6 +204,11 @@ CommandLineHandler::CommandLineHandler()
QLatin1String("--disable-opengl"),
tr("Disable hardware accelerated rendering"));

option<&CommandLineHandler::setProject>(
QChar(),
QLatin1String("--project"),
tr("Project file to load"));

option<&CommandLineHandler::setExportMap>(
QChar(),
QLatin1String("--export-map"),
Expand Down Expand Up @@ -264,6 +280,22 @@ void CommandLineHandler::setDisableOpenGL()
disableOpenGL = true;
}

void CommandLineHandler::setProject()
{
const QString projectFile = nextArgument();
const QFileInfo fileInfo(projectFile);

if (fileInfo.suffix() != QLatin1String("tiled-project")) {
qWarning().noquote() << QCoreApplication::translate("Command line", "Project file expected: --project <.tiled-project file>");
justQuit();
} else if (!fileInfo.exists()) {
qWarning().noquote() << QCoreApplication::translate("Command line", "Project file '%1' not found.").arg(projectFile);
justQuit();
} else {
Preferences::setStartupProject(QDir::cleanPath(fileInfo.absoluteFilePath()));
}
}

void CommandLineHandler::setExportMap()
{
exportMap = true;
Expand Down

0 comments on commit 018dd3a

Please sign in to comment.