Open Phlosioneer opened 4 years ago
What image format are you looking to support? Qt only supports adding custom image formats through C++ plugins and I don't think it even supports even a C++ API to register custom formats. If this is about adding support for a common image format then maybe we could ship another image format plugin.
Alternatively, we could of course route all image loading through a custom function that also takes registered formats from JavaScript into account.
Why the custom hasChanged
check? As long as the image is simply a file on disk, Tiled already watches it for changes (if it's a tileset image, because individual tile images and image layer images are not yet watched for changes...).
I'm trying to use a generated image as a tileset image. That generated image has two input files. So the normal "watch the file" approach that's built in wouldn't work.
Currently I have to remember to update it whenever either file changes, and I have to perform the generation in a particular order. It's error prone.
As for the image format, in this case I'm just going to make a temporary png file and load that, after running the generator (if needed). So QT doesn't have to bend over backwards for the format, I just need to be able to intercept reads and override the auto-checking behavior.
The exact process in my case is that I'm taking a .ase
file, exporting it to PNG, and then running a postprocessing script afterwards. If the script or the ase file change, I want the output to update accordingly.
In the more general case, could we allow a script to generate BMP-formatted image data and then "trick" qt into thinking that it's a bmp file?
Currently I have to remember to update it whenever either file changes, and I have to perform the generation in a particular order. It's error prone.
I think the best way to support this case would be to expose the FileSystemWatcher
class in the script API and give the script a way to trigger a reload.
In the more general case, could we allow a script to generate BMP-formatted image data and then "trick" qt into thinking that it's a bmp file?
We can definitely also expose a script function to turn a byte array into an image with any supported format. Essentially exposing QImage::fromData
.
@bjorn exposing QImage::fromData
would be great, yes. Right now there is no equivalent to the Python way of doing Tileset.data().loadFromImage()
.
Hi, sorry for not getting back to you sooner about this feature, but I had trouble building Tiled and then got busy with other things.
The above branch (which I synced with master
in #2906) works very well for me. I successfully ported my plugin from Python to JavaScript.
I only came across two minor problems:
Image.setColorTable(["#123abc"])
does not work properly, because ScriptImage::setColorTable
explicitly casts the array elements to UInt
. I have to do Image.setColorTable([0xff123abc])
instead, which is OK but a bit inconsistent with e.g. Tileset.backgroundColor
which accepts the "#123abc"
argument.Tileset.ladFromImage()
before Tileset.setTileSize()
does not work; the order matters here, otherwise Tiled tries to reload a non-existent image.
Hey, I'm trying to use the new scripting API to allow tiled to read a new image format for tilesets. However, the API only allows registering handlers for Tileset files and TileMap files.
I'd like to suggest this as a workable API: