bevy_tilemap icon indicating copy to clipboard operation
bevy_tilemap copied to clipboard

Arbitrary data attached to tile

Open thorlucas opened this issue 4 years ago • 4 comments

What problem does this solve or what need does it fill?

In games, tiles often need to store extra data. For example, in Minecraft, blocks have block states and block entity data.

Describe the solution would you like?

I would like Tilemap and Tile to be generic over T, allowing us to attach additional data T to each Tile. This could be something like this:

struct Tile<T> where T: ... {
    ...
    data: T,
}

Describe the alternative(s) you've considered?

While this could be stored separately, it would require implementing an additional system that functions pretty much identically to the existing Tilemap for spawning / despawning / etc.

thorlucas avatar Apr 05 '21 23:04 thorlucas

I had thought about doing this. I know it has been requested before. I was initially worried about arbitrary data only being useful for few. There may be a better solution to this with having a seperate database of this data.

joshuajbouw avatar Apr 07 '21 07:04 joshuajbouw

I had thought about doing this. I know it has been requested before. I was initially worried about arbitrary data only being useful for few. There may be a better solution to this with having a seperate database of this data.

Perhaps some Tilemap component with a sparse representation? This could be similar to a mirror of the original tilemap but with all sparse layers. I'm not sure how tiles are stored internally, but I assume it could be stored similar to the sparse tilemap layers.

fn my_sys(mut data: Query<&mut TileData>) {
    ...
}

thorlucas avatar Apr 07 '21 10:04 thorlucas

Yeah, sort of like data layers that are entirely optional and modular, that would be better then there is less null space if someone chooses not to use it.

joshuajbouw avatar Apr 08 '21 02:04 joshuajbouw

I've added some discussion about solutions to this on #151.

thorlucas avatar Apr 13 '21 11:04 thorlucas