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
add LevelIndices type
add iter_levels_with_indices methods to LdtkProject and LdtkJson that iterate through levels while enumerating them using the new type
add get_level_at_indices methods to LdtkProject and LdtkJson for constant lookup of levels with LevelIndices
add LevelSelection::index constructor method for easing migration to new variant for most users
add LevelSelection::indices constructor method for more ergonomically using the new variant in multi-world projects
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.
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 typeLevelIndices
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 toLdtkJson
/LdtkProject
. It is also further integrated with the API by being used in a newLevelSelection::Indices
variant, which replacesLevelSelection::Index
.Getting a level by
LevelSelection
can now be made more performant if users are using theIndices
variant, but this optimization will be implemented in a future PR. Some new convenience constructor methods have been added toLevelSelection
to ease the migration.Changes
LevelIndices
typeiter_levels_with_indices
methods toLdtkProject
andLdtkJson
that iterate through levels while enumerating them using the new typeget_level_at_indices
methods toLdtkProject
andLdtkJson
for constant lookup of levels withLevelIndices
LevelSelection::index
constructor method for easing migration to new variant for most usersLevelSelection::indices
constructor method for more ergonomically using the new variant in multi-world projectsBreaking
feat!: replace
LevelSelection::Index
withLevelSelection::Indices
variant that usesLevelIndices
internally BREAKING-CHANGE: Since it has been replaced byLevelSelection::Indices
, any usage ofLevelSelection::Index
will break. Construction of the new variant can easily be migrated for non-multi-world projects with theLevelSelection::index
constructor.