Trouv / bevy_ecs_ldtk

ECS-friendly ldtk plugin for bevy, leveraging bevy_ecs_tilemap
Other
674 stars 76 forks source link

feat: add LdtkProjectData for representing either internal- or external-level project data concretely #243

Closed Trouv closed 11 months ago

Trouv commented 11 months ago

This continues work towards redesigning the asset types. In a previous PR, LdtkProjectWithMetadata<L> was added to store LDtk data in a way that it is generic over its level locale. This was done because some methods need to be exclusive to internal-levels projects, some need to be exclusive to external-levels projects, while some need to be the same between the two. However, it is still necessary to represent both cases with the same concrete type (not generic, as that basically treats them as two separate concrete types). This is so we can use these types in bevy's asset system, which doesn't accept multiple asset types being assigned to the same file extension (.ldtk in this case).

This PR adds LdtkProjectData which is an enum one layer above LdtkProjectWithMetadata that has variants for each level locale. It has transparent implementations of RawLevelAccessor and LevelMetadataAccessor for easy raw level data access, but it does not have methods for accessing loaded levels. Accessing loaded levels requires going one level deeper, to the internal LdtkProjectWithMetadata. .as_standalone() and .as_parent() have been added for convenient unwrapping to the internal type since most (all?) users will know whether or not they are using internal levels or external levels at compile time.

Note that this is still not used in the rest of the plugin. Incorporating this into the LdtkProject and updating the rest of the repository accordingly will be accomplished in a future PR.

(Ignore broken doc-links here, they will no longer be broken in future PRs)