fishfolk / bones

An easy-to-use game engine for making real games.
https://fishfolk.org/development/bones/introduction/
Other
236 stars 20 forks source link

feat: add system params for iterating over asset packs #482

Closed nelson137 closed 1 month ago

nelson137 commented 1 month ago

Closes #272

Changes

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... */
    }
}