Need layer tiles to inherit tile index properties

Oct 18, 2013 at 2:03 PM
Edited Oct 18, 2013 at 2:08 PM
This discussion [discussion:252294] seems close to what I'm looking for. I believe the current version accounts for that request by allowing you to set a property at the tile index. Anything that reads the tile map could then determine the tile properties by keying to the referenced tile index.

Here is why that doesn't meet my requirements...The tile index properties are then the same for every instance of the tile on the layer. What I'm looking for is a map editor that allows me to set the default properties in the tile set, which are then inherited by each instance on the layer. Example:

I'm building a conveyor map with straight pieces, curves, and diverts. In the tile sheet I want to define a "Type" and assign values like "straight", "curve", "divert". So far so good. I can key to the index to get that. However, I also want to define properties for each divert like "LogicalID", "ScannerID" etc... I want to define these in the tile sheet, but set the actual values for each instance of that tile on the layer. I don't want to add these properties when adding these tiles to the layer because...
a) that's cumbersome and unnecessary extra typing
b) now I have to provide some sort of glossary of what the user must enter
c) it's inevitable that the users will fat finger the property names

So it would work if each child instance of the tile inherited the parent properties and let me edit them. I can understand that this could eliminate a benefit of having a property defined just at the parent, since there I could change it in one place. So the ideal in my mind would be to have a way to select which properties are inheritable by the child. In my above example "Type" would not be inheritable. A "divert" tile should always be a divert. But "LogicalID" or "ScannerID" would be inheritable.

Any thoughts on this?
Oct 18, 2013 at 3:34 PM
Edited Oct 18, 2013 at 3:40 PM
You can use the TileIndexProperties collection property of a Tile, or equivalently the TileIndexProperties[] indexer of the tile's TileSheet to get and set properties at tile index level.

Under the bonnet this works through custom properties at TileSheet level using keys with
the format __@TileIndex@tileindex@key_. For example, if you call tile.TileIndexProperties["foo"] = 34 (where we assume tile's tile index = 8), this will create a property within the corresponding tilesheet with key @TileIndex@8@foo with value 34.

Unfortunately the editor has no direct way to allow you to specify tile properties at tile index level, but you could use the convention described above to enter them manually in the TileSheet properties.
Oct 18, 2013 at 4:56 PM
Maybe I'm misinterpreting you, but setting properties at the tile index level isn't my issue since that is already supported. I can right click on a particular tile index in the tile picker and select "Tile Index Properties". I can also set individual tile properties on a layer by right-clicking there and selecting "Tile Properties". My issue is that when I do the latter, I get none of the properties I entered in "Tile Index Properties". I have to start from scratch entering the properties each time I drop a tile, which is very labor-intensive and error-prone as I mentioned. I'm looking for a solution that has the tile index properties getting copied to the tile properties - I'd be content if they were all copied there, but ecstatic if I could specify which ones were copied (i.e. inheritable).

"Unfortunately the editor has no direct way to allow you to specify tile properties at tile index level, but you could use the convention described above to enter them manually in the TileSheet properties."

I'm not sure how this is better than what's there now...the ability in the editor to enter any custom property for each individual tile. I'm just looking for something that supports this in the editor, so as to avoid the 3 negative issues described above.

I'm looking at Tiled as well, and found a thread where a couple of other people wanted virtually the same thing. One of them forked a solution, but I don't know if it was integrated. But this is proof that this is a definite need out here for certain applications of tile mapping.
Oct 19, 2013 at 3:00 PM
Regarding what you quoted, I'm ashamed to say I forgot that I implemented a TileIndexProperties GUI within the editor and for a moment I thought that I only implemented it within the API! It's been a while and I'm getting old :) So yes, basically you can set Tile Index Properties within both the editor and the API.

The idea of Tile Index Properties is for a level designer to assign properties associated with a tile index, regardless of the tile instances in the layers. Obviously to check for these properties you would need to specifically check the Tile's TileIndexProperties rather than Properties.

What you seem to want is the ability to use tile index properties as a kind of properties template for tile instances within in the layers, which is currently not a supported feature of the editor.

I can suggest three possible solutions:
1) You could write a tool (using the xTile API) that loads a map, for all tile instances in the layers, copy all TileIndexProperties corresponding to the respective tile indexes and save the map back. You might want to do this only for properties that are not set in the instances so you can safely add new tile index properties and rerun the tool without overwriting the tile instance properties.

2) You could do (1) in the form of a plugin for the editor. You can see a sample plugin implementation here.

3) I could do something about it, like add a context menu item to replicate tile index properties into the tile instance properties i.e. the user right-clicks on a tile instance and chooses a command called "Inherit tile index properties" (or similar) from the tile instance context menu. The user would have to do this for all each tile instance, but at least it's just a two clicks rather than typing in the properties. I'll give this a thought since others may appreciate such a feature.