SSBMTonberry/tileson

How to parse infinite maps?

ProfAndreaPollini opened this issue · 2 comments

I'm trying to read a infinite map in my roguelike project.

 tson::Tileson t;
  auto map = t.parse("assets/maps/map02.json");

  for (auto &layer : map->getLayers())
  {
	std::cout << "LAYER: "<< layer.getName() << "("<< layer.getSize().y << ", "<< layer.getSize().x<<")" << std::endl;
	auto chunks = layer.getChunks();

	for (auto &chunk : chunks)
	{
		std::cout << "CHUNK: "<< chunk.getSize().y << ", "<< chunk.getSize().x<< std::endl;
		auto tiles = chunk.getData();
		for (auto tile : tiles)
		{
			std::cout << "TILE: "<< tile << std::endl;
		}
	}

	const auto& tileData = layer.getTileObjects();

	for (auto &tile : tileData) {
	  std::cout << "(" << std::get<0>(tile.first) << ", " << std::get<1>(tile.first) << ") " << std::endl;
	}
  }

here tileData is simply empty, so I'm doing something wrong but also looking at the example, I can't find out my error.

link to the map: https://pastebin.com/x4LTevZD

It's not you, it's me 🙂
There has been an issue on this for quite a while, and I've put it in the next release of Tileson: v1.4.0.
That issue can be found here: #2
Reason why it's been delayed for so long is simply that no one has asked for it, and I've prioritized other stuff.

Basicly Tileson is not able to resolve tile data for infinite maps in the same fashion as fixed size tile maps can be resolved. This also basicly means that TileObjects, which also are Tileson specific objects resolved by tiles also are affected by this, and you would get no tiles as a result.

I presume the for-loop using chunks gives you the tiles you want? If not there is an error somewhere, but if it does it's sadly the only way to resolve tile data for infinite maps until the feature has been implemented. Alternatively I think you can just change the map from infinite to fixed size before saving, and you should be fine. I think you can change back and forth between infinite and fixed as a map property in Tiled, if I'm not mistaken.

Closing this, as it's related to issue #2