Trouv / bevy_ecs_ldtk

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

feat!: add `LevelIndices` type defining a level's location in a project and use it in `LevelSelection::Indices` #221

Closed Trouv closed 10 months ago

Trouv commented 11 months ago

To provide constant lookup of raw/loaded levels in an asset, we need to use its world index/level index separately. Simply iterating through all the levels with the existing LdtkProject::iter_levels and getting the .nth() element isn't constant, even though it does chain together root levels and world levels. This PR provides a simple type LevelIndices that stores a world index and a level index, which can be used for this kind of lookup. Methods for performing this lookup and more have been added to LdtkJson/LdtkProject. It is also further integrated with the API by being used in a new LevelSelection::Indices variant, which replaces LevelSelection::Index.

Getting a level by LevelSelection can now be made more performant if users are using the Indices variant, but this optimization will be implemented in a future PR. Some new convenience constructor methods have been added to LevelSelection to ease the migration.

Changes

Breaking

feat!: replace LevelSelection::Index with LevelSelection::Indices variant that uses LevelIndices internally BREAKING-CHANGE: Since it has been replaced by LevelSelection::Indices, any usage of LevelSelection::Index will break. Construction of the new variant can easily be migrated for non-multi-world projects with the LevelSelection::index constructor.