-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Scripting: Add API for Worlds #3539
Comments
Currently the API implemented by #3859 does not provide such convenience methods. I considered adding this, but I wasn't sure whether it is a good idea, because:
So I think these convenience methods would make the API a little inconsistent, and the convenience is really very minor, compared to just doing |
Makes sense. I think it'd fine if we can't get TileMaps directly from Worlds, but I'd still like to see addMap and removeMap overrides that take a TileMap, as I think that would make for scripts that look cleaner. They can return false or throw an error if the TileMap has no fileName. Also, I'd love to see addMap(fileName, x, y) and addMap(TileMap, x, y) overrides that don't require a QRect and auto-calculate the bounds, for trivial adds, which I suspect most would be. Calculating the bounds isn't always trivial (especially for non-ortho maps), it'd be nice to offload that to Tiled when it's not directly relevant to the script's function, such as when just adding a bunch of maps to a World in a grid or something. |
@eishiya Hmm, good point about the bounds. Maybe it is worth it for the convenience after all. |
I had a brainfart and forgot that addMap(fileName, x, y) doesn't actually have the map open to do work with, so that one's probably too much to ask for, and adding maps via fileName should require a full rect. But addMap(TileMap, x, y) would still be great. |
At present, the only way for Tiled scripts to work with Worlds is to parse the .world file themselves. This is a hassle, especially for Worlds that use pattern-matching instead of explicitly defined maps. Working with maps in a World would be a lot more convenient if the scripting API provided access to the many functions of World that already exist on the C++ side, including opening/closing worlds, getting the current active world(s?), adding/removing maps, getting a list of maps and their rects, getting the rect for a given map, getting all maps in a given rect, and Signals for worlds loading/unloading/changing.
It looks like on the C++ side, most of the World methods work with map file paths. I think it would be good to preserve this, while also providing methods that accept/return TileMaps for convenience.
Example use cases:
The text was updated successfully, but these errors were encountered: