-
-
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
accessing tileset firstgid property from python missing? #2191
Comments
Tilesets don't inherently have a firstgid property. They are assigned and used by the JSON and TMX formats to map references to possibly multiple tilesets into a single range of numbers. But any other system could be used, like for example storing each tile as a tileset index + tile id pair. If you want to use the same mechanism in your Python plugin, the assigning of firstgids is quite straight-forward since it starts with 1 for the first tileset and then goes up by the value of the highest local tile ID + 1 for each tileset. For figuring out the highest local tile ID + 1, you could rely on the |
I see no way to get the tileset index directly from a tileset.
any hint? |
@sverx I can't really explain this, apart from that they are apparently not the same Python objects while still holding the same |
using: I'd say I can live with it, even if probably having an Thanks! |
Right, tilesets don't currently have an ID. I have been considering to add globally unique IDs to each asset, but actually the file name should already be uniquely identifying the asset. The only problem with file names is that relative paths can break when you move files around and having globally unique IDs would provide a way to fix up these references, at least within one project. One problem with globally unique IDs is of course that if you copy a file you end up with two files that have the same "unique" IDs. In any case, ideally, the direct |
I actually think some method ( |
@sverx The tileset could be used by multiple maps, and it could have a different index in each map. But, I could imagine to add a function to the map to get the index of the tileset, so |
... so that you'll get the index that the specified tileset has in the map, which means you'll then be able to scan all the tilesets that are 'before' this one to calculate the needed tile's GID adding up the previous tileset's tileCount() - if I got that correctly. |
Hrm, I just noticed that However, it takes a |
To get the shared pointer from a Tileset* value, since this is needed to pass it as an arguement to Map.indexOfTileset(). Also added trimming of trailing whitespace, which was causing empty lines in the Issues view (affecting Python script output). See issue #2191
The above commit adds the needed function, which should enable you to get the index of the tileset. It will be available in the next development snapshot (or if you compile Tiled yourself from
Actually it's a bit easier, the steps I imagined were:
Hope that helps! |
Got it! I'll try it when the next development snapshot will be out. |
OK I tried with latest development snapshot to use the new sharedPointer() instead of comparing the names of the tilesets.
now it won't work, even using == instead of is I'll try a different approach, as you suggested, but I'm quite puzzled about why the above wouldn't work. |
this seems to work, instead:
|
In one situation, the pointer comparison happens on the C++ side, where raw tileset pointers are compared and it will say whether they are the same tileset instance. In your situation, the comparison happens by Python and who knows what its comparison boils down to. At least we know, that it's comparing something else than tileset pointers. The Python API exposed for Tiled plugins may be creating different Python objects to wrap around the same tileset pointers, which could throw off that comparison. Your last snippet should indeed work in general, but doing that for each tile it should be faster to set up a small array of "first global tile ID" first, then you could trivially add it for a given tileset index instead of having to do a for loop. |
I see, so we really shouldn't trust pointer comparisons. As for your hint, that's surely a possibile optimization. As in my current scenario I have only two tilesets and tiles in the second one are very rarely used, I think I don't even need that :) Thanks! |
In a python exporter I'm writing, I'd like to access the tileset's firstgid property but I can't find any way to do that. Is that missing?
(the point is that
tileLayer.cellAt(x, y).tile().id()
returns the id of the tile, not his gid, so if I'm using more than one tileset I can't really tell tiles apart...)Any suggestion?
The text was updated successfully, but these errors were encountered: