Skip to content

Commit

Permalink
Scripting: Replaced TileMap.selectedArea with TileMap.selectedRegion
Browse files Browse the repository at this point in the history
This new property has type `region` instead of `SelectedArea`, with the
goal of unifying region values in the JS API.
  • Loading branch information
bjorn committed Jun 17, 2024
1 parent bd891d6 commit 83f63de
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/scripting-doc/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2657,6 +2657,8 @@ declare class Layer extends TiledObject {
* get the {@link region} of this area, modify that region, and then assign it
* back. The necessary methods have been added to the {@link region} type with
* Tiled 1.8.
*
* @deprecated Use {@link region} instead.
*/
interface SelectedArea {
/**
Expand Down Expand Up @@ -2837,9 +2839,25 @@ declare class TileMap extends Asset {

/**
* The selected area of tiles.
*
* @deprecated Use {@link selectedRegion} instead, which returns {@link region}.
*/
readonly selectedArea : SelectedArea

/**
* The selected area of tiles.
*
* @since 1.11
*/
selectedRegion : region

/**
* The selected area of tiles has changed.
*
* @since 1.11
*/
selectedRegionChanged : Signal<null>;

/**
* The current layer.
*/
Expand Down
13 changes: 13 additions & 0 deletions src/tiled/editablemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ QList<QObject *> EditableMap::layers()
return editables;
}

RegionValueType EditableMap::selectedRegion() const
{
if (auto document = mapDocument())
return RegionValueType(document->selectedArea());
return {};
}

EditableLayer *EditableMap::currentLayer()
{
if (auto document = mapDocument())
Expand Down Expand Up @@ -599,6 +606,11 @@ void EditableMap::setLayerDataFormat(LayerDataFormat value)
map()->setLayerDataFormat(static_cast<Map::LayerDataFormat>(value));
}

void EditableMap::setSelectedRegion(const RegionValueType &region)
{
push(new ChangeSelectedArea(mapDocument(), region.region()));
}

void EditableMap::setCurrentLayer(EditableLayer *layer)
{
QList<QObject*> layers;
Expand Down Expand Up @@ -687,6 +699,7 @@ void EditableMap::setDocument(Document *document)
connect(doc, &MapDocument::layerAdded, this, &EditableMap::attachLayer);
connect(doc, &MapDocument::layerRemoved, this, &EditableMap::detachLayer);

connect(doc, &MapDocument::selectedAreaChanged, this, &EditableMap::selectedRegionChanged);
connect(doc, &MapDocument::currentLayerChanged, this, &EditableMap::currentLayerChanged);
connect(doc, &MapDocument::selectedLayersChanged, this, &EditableMap::selectedLayersChanged);
connect(doc, &MapDocument::selectedObjectsChanged, this, &EditableMap::selectedObjectsChanged);
Expand Down
4 changes: 4 additions & 0 deletions src/tiled/editablemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class EditableMap final : public EditableAsset
Q_PROPERTY(QList<QObject*> tilesets READ tilesets)
Q_PROPERTY(QList<QObject*> layers READ layers)
Q_PROPERTY(Tiled::EditableSelectedArea *selectedArea READ selectedArea CONSTANT)
Q_PROPERTY(Tiled::RegionValueType selectedRegion READ selectedRegion WRITE setSelectedRegion NOTIFY selectedRegionChanged)
Q_PROPERTY(Tiled::EditableLayer* currentLayer READ currentLayer WRITE setCurrentLayer NOTIFY currentLayerChanged)
Q_PROPERTY(QList<QObject*> selectedLayers READ selectedLayers WRITE setSelectedLayers NOTIFY selectedLayersChanged)
Q_PROPERTY(QList<QObject*> selectedObjects READ selectedObjects WRITE setSelectedObjects NOTIFY selectedObjectsChanged)
Expand Down Expand Up @@ -134,6 +135,7 @@ class EditableMap final : public EditableAsset
QList<QObject*> tilesets() const;
QList<QObject*> layers();
EditableSelectedArea *selectedArea();
RegionValueType selectedRegion() const;
EditableLayer *currentLayer();
QList<QObject*> selectedLayers();
QList<QObject*> selectedObjects();
Expand Down Expand Up @@ -193,6 +195,7 @@ class EditableMap final : public EditableAsset
void setRenderOrder(RenderOrder value);
void setBackgroundColor(const QColor &value);
void setLayerDataFormat(LayerDataFormat value);
void setSelectedRegion(const RegionValueType &region);
void setCurrentLayer(EditableLayer *layer);
void setSelectedLayers(const QList<QObject*> &layers);
void setSelectedObjects(const QList<QObject*> &objects);
Expand All @@ -203,6 +206,7 @@ class EditableMap final : public EditableAsset
QSharedPointer<Document> createDocument() override;

signals:
void selectedRegionChanged();
void currentLayerChanged();
void selectedLayersChanged();
void selectedObjectsChanged();
Expand Down

0 comments on commit 83f63de

Please sign in to comment.