Skip to content
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

Loading map with TSX tileset error "Missing attribute: tilecount" #265

Closed
Bushstar opened this issue May 7, 2023 · 11 comments
Closed

Loading map with TSX tileset error "Missing attribute: tilecount" #265

Bushstar opened this issue May 7, 2023 · 11 comments

Comments

@Bushstar
Copy link

Bushstar commented May 7, 2023

Not sure if this is a bug or user error. I created a map with a compiled version of Tiled using the latest source as of the time of this issue, the map uses a TSX tilemap. When trying to load that map via load_tmx_map I get the following error.

Missing attribute: tilecount

The tileset attribute looks like the following. Note that the TMX, TSX and PNG are all in the same folder.

<tileset firstgid="1" source="simple-isometric.tsx"/>

The tilecount attr
tsx_map.tar.gz
ibute is in the simple-isometric.tsx.

<tileset version="1.10" tiledversion="1.10.1" name="simple-isometric" tilewidth="64" tileheight="64" tilecount="54" columns="6">

If I load a map with an embedded tileset then it loads without error.

@aleokdev aleokdev added the bug label May 7, 2023
@aleokdev
Copy link
Contributor

aleokdev commented May 7, 2023

Will take a look into it today.

@Bushstar
Copy link
Author

Bushstar commented May 7, 2023

Tried to upload the files to in case it helps but GitHub does not seem to like TSX or TMX files. Sharing via gist and adding the PNG here which GitHub seems happy with. It is a simple map that I created just to test a TMX with TSX tileset.

tsx_map.tmx
simple-isometric.tsx
simple-isometric.png

@aleokdev
Copy link
Contributor

aleokdev commented May 7, 2023

Hmm, I can't seem to reproduce the bug. Can you send the code you're using to load it, and the version of the crate you are using?

@Bushstar
Copy link
Author

Bushstar commented May 7, 2023

The code I'm using is linked below. The version being used is 0.11.0. The repo below is a fork of bevy_ecs_tilemap which I updated to 0.11.0. It was on 0.10.2 before but TSX maps did not work then either, thought I would update to 0.11.0 first.

Bevy has an AssetLoader, to load TMX maps via it the AssetLoader trait needs to be implemented. This trait provides a bytes to the file which I have added to BytesResourceReader which is implemented in the file below just above the lines linked.

The code linked works with regular maps, just not TSX maps.

https://github.com/Bushstar/bevy_ecs_tilemap/blob/8dc5097fc9c3cead2471775947162a2a4050a3f5/examples/helpers/tiled.rs#L112-L114

@Bushstar
Copy link
Author

Bushstar commented May 7, 2023

I've pushed a demo of this error to the above repo on this branch.

https://github.com/Bushstar/bevy_ecs_tilemap/tree/map_loading_error

You can run it with...

cargo run --example 3d_iso

@aleokdev
Copy link
Contributor

aleokdev commented May 7, 2023

Loader calls tiled::ResourceReader::read_from for every dependency required in the map. I'm pretty sure that what is happening is that it's trying to load the tileset, but since you are ignoring the path given, you are giving the map byte data once again, so the tiled crate tries to interpret it as a tileset, and fails.

One of the goals for 0.11 was for the crate to work with bevy's loading system - However, due to lack of time on my side, I had to upload it as-is. I'm pretty sure the crate cannot work with bevy because our crate expects dependencies to be loaded secuentially without stopping, however, bevy loads files one by one.

You'll have to go the embedded way, or try to add support for it on the crate (which would be really appreciated!)

@aleokdev aleokdev removed the bug label May 7, 2023
@Bushstar
Copy link
Author

Bushstar commented May 7, 2023

Thanks for the explanation, that makes sense.

Based on this I'll take a look at updating bevy_ecs_tilemap to work with TSX maps and will create a PR if successful.

@Bushstar
Copy link
Author

Bushstar commented May 7, 2023

Managed to get TSX maps working with the commit below. Not so happy about manually specifying the assets directory, LoadContext has an AssetIO which should have the path, but this is private outside of the crate. could create a CustomAssetIo to get around this, but this then gets more complex than it should, especially for an example. Will create a PR on bevy_ecs_tilemap and wait for feedback as it is.

Bushstar/bevy_ecs_tilemap@a46094d

@aleokdev
Copy link
Contributor

aleokdev commented May 7, 2023

Neat! Ideally we should probably have support for loading dependencies separately from their parents, but that would work for now. It ain't perfect since Bevy has no idea about the deps and it won't work with other filesystems that aren't the system one, but it'll do until we update the crate to support this usecase. Thanks!

@Bushstar
Copy link
Author

Bushstar commented May 7, 2023

I've got it, went back and checked LoadContext, it has a method to get the AssetIo so we do not need to hard code the assets directory and use the path set from Bevy.

Bushstar/bevy_ecs_tilemap@ef9d876

@aleokdev
Copy link
Contributor

aleokdev commented May 7, 2023

Perfect. I'll close this issue for now then. Thank you very much for opening it and bringing it to my attention :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants