Skip to content

Commit

Permalink
Scripting: Expose Tileset.transformationFlags (#4100)
Browse files Browse the repository at this point in the history
* add transformationFlags property to EditableTileset
* expose enum options for transformationFlags on EditableTileset, update scripting doc
* add since tag to scripting doc, fix spacing
* Updated NEWS.md

Closes #3753

---------

Co-authored-by: Thorbjørn Lindeijer <[email protected]>
  • Loading branch information
dogboydog and bjorn authored Nov 14, 2024
1 parent 4ba08e6 commit 3281d80
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Scripting: Added `FileFormat.nameFilter`
* Scripting: Added `MapEditor.currentBrushChanged` signal
* Scripting: Added `tiled.cursor` to create mouse cursor values
* Scripting: Added `Tileset.transformationFlags` (#3753)
* Fixed saving/loading of custom properties set on worlds (#4025)
* Fixed issue with placing tile objects after switching maps (#3497)
* Fixed crash when accessing a world through a symlink (#4042)
Expand Down
15 changes: 15 additions & 0 deletions docs/scripting-doc/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3670,6 +3670,12 @@ declare class Tileset extends Asset {

static readonly Stretch: unique symbol;
static readonly PreserveAspectFit: unique symbol;

static readonly NoTransformation: unique symbol;
static readonly AllowFlipHorizontally: unique symbol;
static readonly AllowFlipVertically: unique symbol;
static readonly AllowRotate: unique symbol;
static readonly PreferUntransformed: unique symbol;

/**
* Name of the tileset.
Expand Down Expand Up @@ -3841,6 +3847,15 @@ declare class Tileset extends Asset {
*/
backgroundColor: color;

/**
* Flags describing transformations of tiles in this tileset that will be
* allowed when using the [terrains feature](https://doc.mapeditor.org/en/stable/manual/terrain/#tile-transformations)
* with this tileset.
*
* @since 1.11.1
*/
transformationFlags: number;

/**
* Whether this tileset is a collection of images (same as checking whether image is an empty string).
*
Expand Down
8 changes: 8 additions & 0 deletions src/tiled/editabletileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,14 @@ void EditableTileset::setBackgroundColor(const QColor &color)
tileset()->setBackgroundColor(color);
}

void EditableTileset::setTransformationFlags(Tileset::TransformationFlags flags)
{
if (auto doc = tilesetDocument())
push(new ChangeTilesetTransformationFlags(doc, flags));
else if (!checkReadOnly())
tileset()->setTransformationFlags(flags);
}

void EditableTileset::setDocument(Document *document)
{
Q_ASSERT(!document || document->type() == Document::TilesetDocumentType);
Expand Down
18 changes: 18 additions & 0 deletions src/tiled/editabletileset.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class EditableTileset final : public EditableAsset
Q_PROPERTY(bool collection READ isCollection) // deprecated
Q_PROPERTY(bool isCollection READ isCollection)
Q_PROPERTY(QList<QObject*> selectedTiles READ selectedTiles WRITE setSelectedTiles)
Q_PROPERTY(Tileset::TransformationFlags transformationFlags READ transformationFlags WRITE setTransformationFlags)

public:
// Synchronized with Tiled::Alignment
Expand Down Expand Up @@ -99,6 +100,16 @@ class EditableTileset final : public EditableAsset
};
Q_ENUM(FillMode)

// Synchronized with Tileset::TransformationFlag
enum TransformationFlag {
NoTransformation = 0,
AllowFlipHorizontally = 1 << 0,
AllowFlipVertically = 1 << 1,
AllowRotate = 1 << 2,
PreferUntransformed = 1 << 3,
};
Q_ENUM(TransformationFlag)

Q_INVOKABLE explicit EditableTileset(const QString &name = QString(),
QObject *parent = nullptr);
explicit EditableTileset(const Tileset *tileset, QObject *parent = nullptr);
Expand Down Expand Up @@ -130,6 +141,7 @@ class EditableTileset final : public EditableAsset
QColor transparentColor() const;
QColor backgroundColor() const;
bool isCollection() const;
Tileset::TransformationFlags transformationFlags() const;

Q_INVOKABLE void loadFromImage(Tiled::ScriptImage *image,
const QString &source = QString());
Expand Down Expand Up @@ -173,6 +185,7 @@ public slots:
void setOrientation(Orientation orientation);
void setTransparentColor(const QColor &color);
void setBackgroundColor(const QColor &color);
void setTransformationFlags(Tileset::TransformationFlags flags);

protected:
void setDocument(Document *document) override;
Expand Down Expand Up @@ -305,6 +318,11 @@ inline bool EditableTileset::isCollection() const
return tileset()->isCollection();
}

inline Tileset::TransformationFlags EditableTileset::transformationFlags() const
{
return tileset()->transformationFlags();
}

inline Tileset *EditableTileset::tileset() const
{
return static_cast<Tileset*>(object());
Expand Down

0 comments on commit 3281d80

Please sign in to comment.