From aec06aeacc86c9233ea78a4e8a629b2feff8ce0c Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 5 Oct 2024 15:46:26 +0200 Subject: [PATCH 1/2] tiled-api: add missing EditableWangSet::SetColorImageTile --- src/tiled/editablewangset.cpp | 14 ++++++++++++++ src/tiled/editablewangset.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/tiled/editablewangset.cpp b/src/tiled/editablewangset.cpp index 3d010d2e72..76f876c3a1 100644 --- a/src/tiled/editablewangset.cpp +++ b/src/tiled/editablewangset.cpp @@ -140,6 +140,20 @@ void EditableWangSet::setName(const QString &name) wangSet()->setName(name); } +void EditableWangSet::setColorImageTile(int colorIndex, EditableTile *imageTile) +{ + if (colorIndex <= 0 || colorIndex > colorCount()) { + ScriptManager::instance().throwError(QCoreApplication::translate("Script Errors", "Index out of range")); + return; + } + + int tileId = imageTile ? imageTile->id() : -1; + if (auto doc = tilesetDocument()) + asset()->push(new ChangeWangColorImage(doc, wangSet()->colorAt(colorIndex).data(), tileId)); + else if (!checkReadOnly()) + wangSet()->colorAt(colorIndex)->setImageId(name); +} + void EditableWangSet::setType(EditableWangSet::Type type) { if (auto document = tilesetDocument()) { diff --git a/src/tiled/editablewangset.h b/src/tiled/editablewangset.h index d8b2ce4ab4..cdb252e45d 100644 --- a/src/tiled/editablewangset.h +++ b/src/tiled/editablewangset.h @@ -65,6 +65,7 @@ class EditableWangSet : public EditableObject Q_INVOKABLE QString colorName(int colorIndex) const; Q_INVOKABLE void setColorName(int colorIndex, const QString &name); + Q_INVOKABLE void setColorImageTile(int colorIndex, Tiled::EditableTile *imageTile); Q_INVOKABLE Type effectiveTypeForColor(int color) const; From c54d604ae4c446228a15cbcdd862117897921b32 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 5 Oct 2024 15:52:33 +0200 Subject: [PATCH 2/2] tiled-api: add missing EditableWangSet::SetColorProbability --- src/tiled/editablewangset.cpp | 14 ++++++++++++++ src/tiled/editablewangset.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/tiled/editablewangset.cpp b/src/tiled/editablewangset.cpp index 76f876c3a1..97001dfe58 100644 --- a/src/tiled/editablewangset.cpp +++ b/src/tiled/editablewangset.cpp @@ -154,6 +154,20 @@ void EditableWangSet::setColorImageTile(int colorIndex, EditableTile *imageTile) wangSet()->colorAt(colorIndex)->setImageId(name); } +void EditableWangSet::setColorProbability(int colorIndex, qreal probability) +{ + if (colorIndex <= 0 || colorIndex > colorCount()) { + ScriptManager::instance().throwError(QCoreApplication::translate("Script Errors", "Index out of range")); + return; + } + + int tileId = imageTile ? imageTile->id() : -1; + if (auto doc = tilesetDocument()) + asset()->push(new ChangeWangColorProbability(doc, wangSet()->colorAt(colorIndex).data(), probability)); + else if (!checkReadOnly()) + wangSet()->colorAt(colorIndex)->setProbability(probability); +} + void EditableWangSet::setType(EditableWangSet::Type type) { if (auto document = tilesetDocument()) { diff --git a/src/tiled/editablewangset.h b/src/tiled/editablewangset.h index cdb252e45d..7786bae476 100644 --- a/src/tiled/editablewangset.h +++ b/src/tiled/editablewangset.h @@ -66,6 +66,7 @@ class EditableWangSet : public EditableObject Q_INVOKABLE QString colorName(int colorIndex) const; Q_INVOKABLE void setColorName(int colorIndex, const QString &name); Q_INVOKABLE void setColorImageTile(int colorIndex, Tiled::EditableTile *imageTile); + Q_INVOKABLE void setColorProbability(int colorIndex, qreal probability); Q_INVOKABLE Type effectiveTypeForColor(int color) const;