Skip to content

Commit

Permalink
Scripting: Added containsMap(map:TileMap) scripting method (#3880)
Browse files Browse the repository at this point in the history
  • Loading branch information
dogboydog committed Jan 24, 2024
1 parent b172c31 commit a842ee2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/scripting-doc/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,12 @@ declare class World extends Asset {
*/
containsMap(fileName : string) : boolean;

/**
* Returns true if this world contains the given map.
* @param map The TileMap to check for.
*/
containsMap(map : TileMap) : boolean;

/**
* Change the position and size of a map within this world.
* @param fileName The file name of the map to change the position and size for.
Expand Down
14 changes: 14 additions & 0 deletions src/tiled/editableworld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ bool EditableWorld::containsMap(const QString &fileName) const
return world()->containsMap(fileName);
}

bool EditableWorld::containsMap(EditableMap *map) const
{
if (!map) {
ScriptManager::instance().throwNullArgError(0);
return false;
}

if (map->fileName().isEmpty()) {
return false;
}

return containsMap(map->fileName());
}

QVector<WorldMapEntry> EditableWorld::maps() const
{
return world()->maps;
Expand Down
1 change: 1 addition & 0 deletions src/tiled/editableworld.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class EditableWorld final : public EditableAsset
Q_INVOKABLE QVector<WorldMapEntry> mapsInRect(const QRect &rect) const;
Q_INVOKABLE QVector<WorldMapEntry> allMaps() const;
Q_INVOKABLE bool containsMap(const QString &fileName) const;
Q_INVOKABLE bool containsMap(EditableMap *fileName) const;
Q_INVOKABLE void setMapRect(const QString &mapFileName, const QRect &rect);
Q_INVOKABLE void setMapPos(EditableMap *map, int x, int y);
Q_INVOKABLE void addMap(const QString &mapFileName, const QRect &rect);
Expand Down

0 comments on commit a842ee2

Please sign in to comment.