Skip to content

Commit

Permalink
Scripting: Added ImageLayer.imageFileName
Browse files Browse the repository at this point in the history
As a generally more convenient alternative to imageSource, which is a
URL.
  • Loading branch information
bjorn committed Jan 31, 2024
1 parent 37f7826 commit 2bdee6a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Added --project command-line parameter for use when exporting (#3797)
* Scripting: Added API for working with worlds (#3539)
* 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
* 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)
Expand Down
15 changes: 13 additions & 2 deletions docs/scripting-doc/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2214,14 +2214,25 @@ declare class ImageLayer extends Layer {

/**
* Reference to the image rendered by this layer.
*
* If you need a plain string, you'll want to use {@link imageFileName}
* instead.
*/
imageSource: Qt.QUrl;

/**
* Reference to the image rendered by this layer.
*
* @since 1.10.3
*/
imageFileName: string;

/**
* Returns a copy of this layer's image.
*
* When assigning an image to this property, the imageSource property is
* cleared. Use {@link setImage} when you want to also set the imageSource.
* When assigning an image to this property, the {@link imageFileName}
* property is cleared. Use {@link setImage} when you want to also set the
* imageSource.
*
* @warning This property is writable but has no undo!
*
Expand Down
5 changes: 5 additions & 0 deletions src/tiled/editableimagelayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ void EditableImageLayer::setImageSource(const QUrl &imageSource)
}
}

void EditableImageLayer::setImageFileName(const QString &fileName)
{
setImageSource(QUrl::fromLocalFile(fileName));
}

void EditableImageLayer::setImage(ScriptImage *image, const QUrl &source)
{
if (checkReadOnly())
Expand Down
8 changes: 8 additions & 0 deletions src/tiled/editableimagelayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class EditableImageLayer : public EditableLayer

Q_PROPERTY(QColor transparentColor READ transparentColor WRITE setTransparentColor)
Q_PROPERTY(QUrl imageSource READ imageSource WRITE setImageSource)
Q_PROPERTY(QString imageFileName READ imageFileName WRITE setImageFileName)
Q_PROPERTY(Tiled::ScriptImage *image READ image WRITE setImage)
Q_PROPERTY(bool repeatX READ repeatX WRITE setRepeatX)
Q_PROPERTY(bool repeatY READ repeatY WRITE setRepeatY)
Expand All @@ -47,12 +48,14 @@ class EditableImageLayer : public EditableLayer

const QColor &transparentColor() const;
const QUrl &imageSource() const;
QString imageFileName() const;
ScriptImage *image() const;
bool repeatX() const;
bool repeatY() const;

void setTransparentColor(const QColor &transparentColor);
void setImageSource(const QUrl &imageSource);
void setImageFileName(const QString &fileName);
void setRepeatX(bool repeatX);
void setRepeatY(bool repeatY);

Expand All @@ -72,6 +75,11 @@ inline const QUrl &EditableImageLayer::imageSource() const
return imageLayer()->imageSource();
}

inline QString EditableImageLayer::imageFileName() const
{
return imageLayer()->imageSource().toString(QUrl::PreferLocalFile);
}

inline bool EditableImageLayer::repeatX() const
{
return imageLayer()->repeatX();
Expand Down

0 comments on commit 2bdee6a

Please sign in to comment.