Add system param Packs -- an iterator over asset pack roots
Directly addresses #272
Add system param AllPacksData -- a flattened, chained iterator over listwise data from core and supplementary asset packs
AllPacksData::iter_with takes 2 args: (1) a closure that takes a ref to the core meta and returns an iterator, (2) a closure takes a ref to a (supplementary) pack meta and returns an iterator
Application
AllPacksData will be most the most useful of the 2 in Jumpy. There are a few locations where we iterate over
a list from the core meta and do something, then we iterate over the packs and for each one iterate over a list. Since AllPacksData is a flattened, chained iterator of all of those sub-iterators, we can turn this:
fn maps_sys(asset_server: Res<AssetServer>, game: Root<GameMeta>) {
for handle in game.core.stable_maps.iter().copied() {
let map_meta = asset_server.get(handle);
/* do stuff... */
}
for pack in asset_server.packs() {
let pack_meta = asset_server.get(pack.root.typed::<PackMeta>());
for handle in pack_meta.maps.iter().copied() {
let map_meta = asset_server.get(handle);
/* do stuff... */
}
}
}
Into this:
fn maps_sys(asset_server: Res<AssetServer>, all_packs: AllPacksData<GameMeta, PackMeta>) {
for handle in all_packs.iter_with(
|game| game.core.stable_maps.iter().copied(),
|pack| pack.maps.iter().copied(),
) {
let map_meta = asset_server.get(handle);
/* do stuff... */
}
}
Closes #272
Changes
Packs
-- an iterator over asset pack rootsAllPacksData
-- a flattened, chained iterator over listwise data from core and supplementary asset packsAllPacksData::iter_with
takes 2 args: (1) a closure that takes a ref to the core meta and returns an iterator, (2) a closure takes a ref to a (supplementary) pack meta and returns an iteratorApplication
AllPacksData
will be most the most useful of the 2 in Jumpy. There are a few locations where we iterate over a list from the core meta and do something, then we iterate over the packs and for each one iterate over a list. SinceAllPacksData
is a flattened, chained iterator of all of those sub-iterators, we can turn this:Into this: