Skip to content

Commit

Permalink
Scripting: Added MapEditor.currentBrushChanged signal
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 committed Jul 11, 2024
1 parent af62ed7 commit 1071ccc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
22 changes: 15 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,14 @@ 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.
*/
currentBrushChanged : Signal<void>;

/**
* Gets the currently selected {@link WangSet} in the "Terrain Sets" view.
*
Expand All @@ -2383,7 +2391,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 +2438,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 +2884,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 +2897,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 +2910,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 +3888,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 1071ccc

Please sign in to comment.