Root causing this one was a bit of a wild chase through two repos, but it seems like when parsing a tiled map that references multiple external tilesets, all parsed tileset properties are all overwritten by the first external tileset file.
If I'm understanding the design correctly, if the Tileset is external and referenced in the .tmx file, via the 'source' property, then you need to pass in a TsxProvider to TileMapParser.parseTmx.
When parsing the tiled map in the flame engine, the code pulls the first tileset external reference, if available, and passes it in (https://github.com/flame-engine/flame/blob/5c47d7f6d7ed4705a3f19e9119364d9c6e6cff55/packages/flame_tiled/lib/src/renderable_tile_map.dart line 65):
TsxProvider? tsxProvider;
if (tsxSourcePath != null) {
tsxProvider = await FlameTsxProvider.parse(tsxSourcePath);
} else {
tsxProvider = null;
}
return TileMapParser.parseTmx(contents, tsx: tsxProvider);
This provider is passed through the parse tree for every tileset in the map (https://github.com/flame-engine/tiled.dart/blob/main/lib/src/tiled_map.dart line 221):
final tilesets = parser.getChildrenAs(
'tileset',
(e) => Tileset.parse(e, tsx: tsx),
);
Subsequently, when each tileset is parsed, if a TsxProvider is given, it seems like every property that appears in the provided external reference overwrites the properties of the tileset being parsed (e.g. name, tilecount, etc.) See _checkIfExtenalTsx method, https://github.com/flame-engine/tiled.dart/blob/main/lib/src/tileset/tileset.dart line 165.
I've been able to produce a repro of this issue with a local unit test. I've only tested multiple external tilesets, but it seems like an external + embedded tileset would potentially run into the same issue where the embedded tileset would be overwritten by the external tileset properties.
Since TsxProvider is simply a passthrough everywhere except the TileSet parser, would it be possible to generate the TsxProvider on the fly for each tileset here, rather than having the external caller pass it in?
(https://github.com/flame-engine/tiled.dart/blob/main/lib/src/tiled_map.dart line 221):
final tilesets = parser.getChildrenAs(
'tileset',
(e) => Tileset.parse(e, tsx: tsx),
);
It seems like the way it was setup today was to support when a caller want's to pass in an external reference that isn't found in the .tmx file (not sure if this is a common use case)?
I plan to proceed with embedding all of the tilesets into my map file, so this is probably a lower-pri ask, but it would be nice to have this fix at some point if possible!