forked from mapeditor/tiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add UnloadAllWorlds actions, exposed in World > Unload World when two…
… or more worlds are loaded expose world related signals to scripting expose loading, unloading, accessing worlds to scripting
- Loading branch information
Showing
11 changed files
with
375 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* editableworld.cpp | ||
* Copyright 2023, Chris Boehm AKA dogboydog | ||
* Copyright 2023, Thorbjørn Lindeijer <[email protected]> | ||
* | ||
* This file is part of Tiled. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "editableworld.h" | ||
#include "worlddocument.h" | ||
#include "worldmanager.h" | ||
|
||
namespace Tiled { | ||
|
||
ScriptWorld::ScriptWorld(World *world) | ||
: Object(*this) | ||
{ | ||
this->world = world; | ||
} | ||
|
||
EditableWorld::EditableWorld(WorldDocument *worldDocument, QObject *parent) | ||
: EditableAsset(worldDocument, &mWorldObject, parent), | ||
mWorldObject(ScriptWorld(WorldManager::instance().worlds().value(worldDocument->fileName()))) | ||
{ | ||
} | ||
|
||
|
||
ScriptWorldMapEntry::ScriptWorldMapEntry(World::MapEntry *mapEntry) | ||
: mMapEntry(mapEntry) | ||
{ | ||
|
||
} | ||
|
||
QString ScriptWorldMapEntry::fileName() const | ||
{ | ||
return mMapEntry->fileName; | ||
} | ||
QRect ScriptWorldMapEntry::rect() const | ||
{ | ||
return mMapEntry->rect; | ||
} | ||
QString EditableWorld::displayName() const | ||
{ | ||
return world()->displayName(); | ||
} | ||
|
||
bool EditableWorld::containsMap(const QString &fileName) | ||
{ | ||
return world()->containsMap(fileName); | ||
} | ||
|
||
QVector<ScriptWorldMapEntry*> EditableWorld::allMaps() const | ||
{ | ||
QVector<ScriptWorldMapEntry*> maps; | ||
for (auto &entry : world()->allMaps()) | ||
maps.append(new ScriptWorldMapEntry(&entry)); | ||
return maps; | ||
} | ||
QVector<ScriptWorldMapEntry*> EditableWorld::mapsInRect(const QRect &rect) const | ||
{ | ||
QVector<ScriptWorldMapEntry*> maps; | ||
for (auto &entry : world()->mapsInRect(rect)) | ||
maps.append(new ScriptWorldMapEntry(&entry)); | ||
return maps; | ||
} | ||
bool EditableWorld::isReadOnly() const | ||
{ | ||
return !world()->canBeModified(); | ||
} | ||
|
||
QSharedPointer<Document> EditableWorld::createDocument() | ||
{ | ||
// We don't currently support opening a world in its own tab, which this | ||
// function is meant for. | ||
return nullptr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* editableworld.h | ||
* Copyright 2023, Chris Boehm AKA dogboydog | ||
* Copyright 2023, Thorbjørn Lindeijer <[email protected]> | ||
* | ||
* This file is part of Tiled. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#pragma once | ||
|
||
#include "editableasset.h" | ||
#include "worlddocument.h" | ||
#include "worldmanager.h" | ||
#include <QObject> | ||
|
||
namespace Tiled { | ||
/* | ||
* Wrapper which allows world structs to be used with the EditableAsset | ||
* class | ||
*/ | ||
class ScriptWorld : public Object | ||
{ | ||
|
||
public: | ||
ScriptWorld(World *world); | ||
World *world; | ||
}; | ||
|
||
/* | ||
* Exposes the World::MapEntry struct to scripting | ||
*/ | ||
class ScriptWorldMapEntry : public QObject | ||
{ | ||
Q_OBJECT | ||
Q_PROPERTY(QString fileName READ fileName CONSTANT) | ||
Q_PROPERTY(QRect rect READ rect CONSTANT) | ||
|
||
public: | ||
ScriptWorldMapEntry(World::MapEntry *mapEntry); | ||
QString fileName() const; | ||
QRect rect() const; | ||
|
||
private: | ||
World::MapEntry *mMapEntry; | ||
}; | ||
|
||
/** | ||
* @brief The EditableWorld class provides access to Worlds via scripting | ||
*/ | ||
class EditableWorld final : public EditableAsset | ||
{ | ||
|
||
Q_OBJECT | ||
Q_PROPERTY(QString displayName READ displayName) | ||
Q_PROPERTY(QVector<ScriptWorldMapEntry*> allMaps READ allMaps) | ||
|
||
public: | ||
EditableWorld(WorldDocument *worldDocument, QObject *parent = nullptr); | ||
bool isReadOnly() const override; | ||
World *world() const; | ||
QString displayName() const; | ||
Q_INVOKABLE QVector<ScriptWorldMapEntry*> allMaps() const; | ||
Q_INVOKABLE QVector<ScriptWorldMapEntry*> mapsInRect(const QRect &rect) const; | ||
Q_INVOKABLE bool containsMap(const QString &fileName); | ||
|
||
QSharedPointer<Document> createDocument() override; | ||
|
||
private: | ||
ScriptWorld mWorldObject; | ||
}; | ||
|
||
inline World *EditableWorld::world() const | ||
{ | ||
return static_cast<ScriptWorld*>(object())->world; | ||
} | ||
|
||
} | ||
|
||
Q_DECLARE_METATYPE(Tiled::EditableWorld*) | ||
Q_DECLARE_METATYPE(Tiled::ScriptWorldMapEntry*) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.