Trouv / bevy_ecs_ldtk

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

feat!: add `RawLevelAccessor` trait for `LdtkJson` level borrowing/iteration, replacing existing methods #225

Closed Trouv closed 10 months ago

Trouv commented 10 months ago

The asset types are being redesigned a bit to clone less and provide better APIs. As a result, there will be more types that store a single LdtkJson, and it would be convenient to have them implement the level borrowing/lookup/iteration methods that have already been provided for LdtkJson and LdtkProject. This PR adds RawLevelAccessor which provides these convenience methods with only a couple small required methods.

Finding a level by level selection is not included in this trait. For this to be efficient, we require a little more metadata that will be available on some of these types but not all. So, a LevelMetadataAccessor will be added in a future PR for this purpose.

The "raw levels" terminology here is intended to oppose "loaded levels". Raw levels are just that - the exact level data from the type with no type guarantee on top of it. Some existing methods that have been moved to this trait are now named more verbosely to make this extra clear.

BREAKING-CHANGE: move iter_levels, iter_levels_with_indices, and get_level_at_indices to RawLevelAccessor trait. Rename them iter_raw_levels, iter_raw_levels_with_indices, and get_raw_level_at_indices respectively.