Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a tile's object group (collision objects) be cleared via script #3502

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### Unreleased

* Scripting: Fixed painting issues after changing TileLayer size (#3481)
* Scripting: Allow assigning null to Tile.objectGroup (by Logan Higinbotham, #3495)
* Defold plugin: Allow overriding z value also when exporting to .collection (#3214)
* Qt 6: Fixed invisible tileset tabs when only a single tileset is open
* Fixed compile against Qt 6.4
Expand Down
27 changes: 15 additions & 12 deletions src/tiled/editabletile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,19 @@ void EditableTile::setProbability(qreal probability)

void EditableTile::setObjectGroup(EditableObjectGroup *editableObjectGroup)
{
if (!editableObjectGroup) {
ScriptManager::instance().throwNullArgError(0);
if (checkReadOnly())
return;
}

if (!editableObjectGroup->isOwning()) {
ScriptManager::instance().throwError(QCoreApplication::translate("Script Errors", "ObjectGroup is in use"));
return;
}
std::unique_ptr<ObjectGroup> og;

if (checkReadOnly())
return;
if (editableObjectGroup) {
if (!editableObjectGroup->isOwning()) {
ScriptManager::instance().throwError(QCoreApplication::translate("Script Errors", "ObjectGroup is in use"));
return;
}

std::unique_ptr<ObjectGroup> og(static_cast<ObjectGroup*>(editableObjectGroup->release()));
og.reset(static_cast<ObjectGroup*>(editableObjectGroup->release()));
}

if (TilesetDocument *doc = tilesetDocument()) {
asset()->push(new ChangeTileObjectGroup(doc, tile(), std::move(og)));
Expand All @@ -193,8 +192,12 @@ void EditableTile::setObjectGroup(EditableObjectGroup *editableObjectGroup)
tile()->setObjectGroup(std::move(og));
}

Q_ASSERT(editableObjectGroup->objectGroup() == tile()->objectGroup());
Q_ASSERT(!editableObjectGroup->isOwning());
if (editableObjectGroup) {
Q_ASSERT(editableObjectGroup->objectGroup() == tile()->objectGroup());
Q_ASSERT(!editableObjectGroup->isOwning());
} else {
Q_ASSERT(tile()->objectGroup() == nullptr);
}
}

void EditableTile::setFrames(QJSValue value)
Expand Down