diff --git a/src/tiled/editablewangset.cpp b/src/tiled/editablewangset.cpp index 3d010d2e72..97001dfe58 100644 --- a/src/tiled/editablewangset.cpp +++ b/src/tiled/editablewangset.cpp @@ -140,6 +140,34 @@ 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::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 d8b2ce4ab4..7786bae476 100644 --- a/src/tiled/editablewangset.h +++ b/src/tiled/editablewangset.h @@ -65,6 +65,8 @@ 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;