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 Aug 3, 2023
1 parent 99e0599 commit 3c1f76b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
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
4 changes: 3 additions & 1 deletion src/tiled/projectmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "project.h"

#include "tilededitor_global.h"

#include <QObject>

namespace Tiled {
Expand All @@ -34,7 +36,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 3c1f76b

Please sign in to comment.