Trouv / bevy_ecs_ldtk

ECS-friendly ldtk plugin for bevy, leveraging bevy_ecs_tilemap
Other
629 stars 74 forks source link

feat: add types and traits around LevelMetadata #229

Closed Trouv closed 10 months ago

Trouv commented 10 months ago

Works towards #205.

The asset types are being redesigned a bit to clone less and provide better APIs. One design goal is to correctly handle both external level projects and internal level projects. Since we want to avoid loading level data into a separate asset in the internal level case, these two scenarios will produce different level metadata on loading. Both need to map level iids to their indices and background image handles. External level projects additionally need to produce a handle to the external level asset. This PR provides LevelMetadata and ExternalLevelMetadata types to represent the metadata produced during project loading.

Mapping iids to level indices with the help of the level metadata types allows constant-time lookup of levels by iid. This is handy since users can have access to the level iid thanks to the new LevelIid component, and can use it for finding level data. This also speeds up accessing levels by LevelSelection - two of the 4 level selection variants can now be constant-time-lookup. To aid in these two use cases, a LevelMetadataAccessor trait is also added in this PR. It can be implemented for types that store raw level data and a mapping of level iids to LevelMetadata. It provides methods for accessing raw level data by iid and by LevelSelection.

These types/traits have not actually been integrated into LdtkProject in this PR. Doing so is a pretty major change and will be a large PR. These types/traits have been given their own PR in an attempt to keep PRs small.