Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript API can't get tileset's image size #2733

Closed
Noah2610 opened this issue Jan 13, 2020 · 3 comments
Closed

JavaScript API can't get tileset's image size #2733

Noah2610 opened this issue Jan 13, 2020 · 3 comments

Comments

@Noah2610
Copy link

TL;DR
With the JS API, is there a way to get a tileset image's size in pixels?


Before v1.3 and the JS API / extensions feature, I was using python export scripts to create custom export formats.
I noticed a missing feature/property with the JS API, that was available with the python scripts:
Getting a tileset's real image size in pixels
You could do this with python scripts with ...

width = tileset.imageWidth()
height = tileset.imageHeight()

(see https://github.com/bjorn/tiled/blob/master/src/plugins/python/tiledbinding.py#L139)

The JS API doesn't seem to provide that information...
So I'm asking, is there a way to get this currently? If not, is this maybe a feature worth implementing?

Sadly I need this functionality to generate custom config files for the tilesets.
It would be very convenient for me to have this feature in the JS API,
otherwise I'll probably need to generate those files outside of the Tiled extension.

Thanks!

@Noah2610
Copy link
Author

Used Tiled version: 1.3.1
Although I'm primarily going off of the information on the docs:
https://doc.mapeditor.org/en/stable/reference/scripting/#tileset

@bjorn
Copy link
Member

bjorn commented Jan 13, 2020

No problem adding it, just needs to be considered if we want to match the Python API or whether we want to export the image explicitly in some form, like tileset.image.width (ah, well I see image is already the file name, so that would break compatibility... still need to decide what's better).

@Noah2610
Copy link
Author

Good point.
As you mentioned, I feel like the better way to do this is to make the image property be a new class, but I guess this would have to wait until the next minor release?

I think it would also be OK to just add the property imageSize, because the Tileset already has a tileSize property, so it would fit the API style (at least in this specific case).

Thanks for your time! Awesome, clean app, btw :)

@bjorn bjorn closed this as completed in 7792ae0 Jan 29, 2020
bjorn added a commit that referenced this issue Apr 14, 2020
    Tileset.imageWidth : int
    Tileset.imageHeight : int
    Tileset.imageSize : size

Also made Tileset.tileSize a writable property, so it can be just
assigned to instead of having to use Tileset.setTileSize(width, height).

Closes #2733

(cherry-picked from 7792ae0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants