Skip to content

Commit

Permalink
Scripting: Restored compatibility for MapObject.polygon
Browse files Browse the repository at this point in the history
While it seemed like a good idea to use the Qt 6 support for
transferring a QPolygonF to/from the JS engine, it caused a
compatibility breakage since the Qt 5 version was less strict on the
type.

The new version required the use of Qt.point to create the polygon's
points, whereas previously the points could also be given by
constructing a plain JS object like "{ x: 0, y: 0 }".

This change restores the behavior as of Tiled 1.10.1.

Closes #3845
  • Loading branch information
bjorn committed Feb 8, 2024
1 parent 6b0d055 commit 97ec0bf
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 23 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Scripting: Added Tile.image for accessing a tile's image data
* Scripting: Added Tileset.imageFileName and ImageLayer.imageFileName
* Scripting: Made Tileset.margin and Tileset.tileSpacing writable
* Scripting: Restored compatibility for MapObject.polygon (#3845)
* JSON format: Fixed tile order when loading a tileset using the old format
* Godot export: Fixed positioning of tile collision shapes (by Ryan Petrie, #3862)
* tmxrasterizer: Added --hide-object and --show-object arguments (by Lars Luz, #3819)
Expand Down
6 changes: 0 additions & 6 deletions src/tiled/editablemapobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
#include "editablemap.h"
#include "editableobjectgroup.h"
#include "editabletile.h"
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include "scriptmanager.h"
#endif

#include <QCoreApplication>
#include <QJSEngine>
Expand Down Expand Up @@ -63,7 +61,6 @@ EditableMapObject::~EditableMapObject()
setObject(nullptr);
}

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QJSValue EditableMapObject::polygon() const
{
QJSEngine *engine = qjsEngine(this);
Expand All @@ -82,7 +79,6 @@ QJSValue EditableMapObject::polygon() const

return array;
}
#endif

EditableTile *EditableMapObject::tile() const
{
Expand Down Expand Up @@ -199,7 +195,6 @@ void EditableMapObject::setVisible(bool visible)
setMapObjectProperty(MapObject::VisibleProperty, visible);
}

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void EditableMapObject::setPolygon(QJSValue polygonValue)
{
if (!polygonValue.isArray()) {
Expand All @@ -225,7 +220,6 @@ void EditableMapObject::setPolygon(QJSValue polygonValue)

setPolygon(polygon);
}
#endif

void EditableMapObject::setPolygon(const QPolygonF &polygon)
{
Expand Down
17 changes: 0 additions & 17 deletions src/tiled/editablemapobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ class EditableMapObject : public EditableObject
Q_PROPERTY(QSizeF size READ size WRITE setSize)
Q_PROPERTY(qreal rotation READ rotation WRITE setRotation)
Q_PROPERTY(bool visible READ isVisible WRITE setVisible)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Q_PROPERTY(QJSValue polygon READ polygon WRITE setPolygon)
#else
Q_PROPERTY(QList<QPointF> polygon READ polygon WRITE setPolygon)
#endif
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(Tiled::Font font READ font WRITE setFont)
Q_PROPERTY(Qt::Alignment textAlignment READ textAlignment WRITE setTextAlignment)
Expand Down Expand Up @@ -119,11 +115,7 @@ class EditableMapObject : public EditableObject
QSizeF size() const;
qreal rotation() const;
bool isVisible() const;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QJSValue polygon() const;
#else
const QPolygonF &polygon() const;
#endif
QString text() const;
Font font() const;
Qt::Alignment textAlignment() const;
Expand Down Expand Up @@ -158,9 +150,7 @@ public slots:
void setSize(QSizeF size);
void setRotation(qreal rotation);
void setVisible(bool visible);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void setPolygon(QJSValue polygon);
#endif
void setPolygon(const QPolygonF &polygon);
void setText(const QString &text);
void setFont(const Font &font);
Expand Down Expand Up @@ -234,13 +224,6 @@ inline bool EditableMapObject::isVisible() const
return mapObject()->isVisible();
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
inline const QPolygonF &EditableMapObject::polygon() const
{
return mapObject()->polygon();
}
#endif

inline QString EditableMapObject::text() const
{
return mapObject()->textData().text;
Expand Down

0 comments on commit 97ec0bf

Please sign in to comment.