Skip to content

Commit

Permalink
Scripting: Added MapEditor.currentBrushChanged signal (#4005)
Browse files Browse the repository at this point in the history
So scripts can respond to brush changes. If they are careful, they can
also adjust the brush, though this will trigger another
`currentBrushChanged` call.
  • Loading branch information
bjorn authored Jul 18, 2024
1 parent af62ed7 commit 29aa44b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### Unreleased

* Scripting: Added `FileFormat.nameFilter`
* Scripting: Added `MapEditor.currentBrushChanged` signal

### Tiled 1.11.0 (27 June 2024)

Expand Down
24 changes: 17 additions & 7 deletions docs/scripting-doc/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ declare class Asset extends TiledObject {
/**
* The signal emitted when {@link modified} changes.
*/
readonly modifiedChanged: Signal<null>;
readonly modifiedChanged: Signal<void>;

/**
* Whether the asset is a {@link TileMap}.
Expand Down Expand Up @@ -2369,6 +2369,16 @@ interface MapEditor {
*/
currentBrush : TileMap

/**
* Signal emitted when the current brush has changed.
*
* This signal is also emitted when assigning to {@link currentBrush}, so be
* careful not to cause an infinite loop.
*
* @since 1.11.1
*/
currentBrushChanged : Signal<void>;

/**
* Gets the currently selected {@link WangSet} in the "Terrain Sets" view.
*
Expand All @@ -2383,7 +2393,7 @@ interface MapEditor {
*
* @since 1.8
*/
readonly currentWangSetChanged: Signal<null>;
readonly currentWangSetChanged: Signal<void>;

/**
* Gets the currently selected Wang color index in the "Terrain Sets" view.
Expand Down Expand Up @@ -2430,7 +2440,7 @@ interface TilesetsView {
*
* @since 1.9.1
*/
readonly currentTilesetChanged: Signal<null>;
readonly currentTilesetChanged: Signal<void>;

/**
* A list of the tiles that are selected in the current tileset.
Expand Down Expand Up @@ -2876,7 +2886,7 @@ declare class TileMap extends Asset {
/**
* The signal emitted when {@link currentLayer} changes.
*/
readonly currentLayerChanged: Signal<null>;
readonly currentLayerChanged: Signal<void>;

/**
* Selected layers.
Expand All @@ -2889,7 +2899,7 @@ declare class TileMap extends Asset {
/**
* The signal emitted when {@link selectedLayers} changes.
*/
readonly selectedLayersChanged: Signal<null>;
readonly selectedLayersChanged: Signal<void>;

/**
* Selected objects.
Expand All @@ -2902,7 +2912,7 @@ declare class TileMap extends Asset {
/**
* The signal emitted when {@link selectedObjects} changes.
*/
readonly selectedObjectsChanged: Signal<null>;
readonly selectedObjectsChanged: Signal<void>;

/**
* Constructs a new map.
Expand Down Expand Up @@ -3880,7 +3890,7 @@ interface TilesetEditor {
*
* @since 1.9
*/
readonly currentWangSetChanged: Signal<null>;
readonly currentWangSetChanged: Signal<void>;

/**
* Gets the currently selected Wang color index in the "Terrain Sets" view.
Expand Down
2 changes: 2 additions & 0 deletions src/tiled/mapeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,8 @@ void MapEditor::setStamp(const TileStamp &stamp)
mToolManager->selectTool(mStampBrush);

mTilesetDock->selectTilesInStamp(stamp);

emit currentBrushChanged();
}

void MapEditor::selectWangBrush()
Expand Down
3 changes: 2 additions & 1 deletion src/tiled/mapeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class MapEditor final : public Editor
Q_OBJECT

Q_PROPERTY(Tiled::TilesetDock *tilesetsView READ tilesetDock CONSTANT)
Q_PROPERTY(Tiled::EditableMap *currentBrush READ currentBrush WRITE setCurrentBrush)
Q_PROPERTY(Tiled::EditableMap *currentBrush READ currentBrush WRITE setCurrentBrush NOTIFY currentBrushChanged)
Q_PROPERTY(Tiled::EditableWangSet *currentWangSet READ currentWangSet NOTIFY currentWangSetChanged)
Q_PROPERTY(int currentWangColorIndex READ currentWangColorIndex NOTIFY currentWangColorIndexChanged)
Q_PROPERTY(Tiled::MapView *currentMapView READ currentMapView CONSTANT)
Expand Down Expand Up @@ -130,6 +130,7 @@ class MapEditor final : public Editor
AbstractTool *selectedTool() const;

signals:
void currentBrushChanged();
void currentWangSetChanged();
void currentWangColorIndexChanged(int colorIndex);

Expand Down

0 comments on commit 29aa44b

Please sign in to comment.