head database for aim and ai
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
use crate::GameState;
|
||||
use crate::{
|
||||
GameState,
|
||||
head_asset::{HeadDatabaseAsset, HeadsDatabase},
|
||||
};
|
||||
use bevy::{prelude::*, utils::HashMap};
|
||||
use bevy_asset_loader::prelude::*;
|
||||
|
||||
@@ -43,6 +46,12 @@ pub struct AudioAssets {
|
||||
pub head: HashMap<AssetFileName, Handle<AudioSource>>,
|
||||
}
|
||||
|
||||
#[derive(AssetCollection, Resource)]
|
||||
struct HeadsAssets {
|
||||
#[asset(path = "all.headsdb.ron")]
|
||||
heads: Handle<HeadDatabaseAsset>,
|
||||
}
|
||||
|
||||
#[derive(AssetCollection, Resource)]
|
||||
pub struct UIAssets {
|
||||
#[asset(path = "font.ttf")]
|
||||
@@ -98,12 +107,26 @@ pub struct GameAssets {
|
||||
pub struct LoadingPlugin;
|
||||
impl Plugin for LoadingPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(OnExit(GameState::AssetLoading), on_exit);
|
||||
app.add_loading_state(
|
||||
LoadingState::new(GameState::AssetLoading)
|
||||
.continue_to_state(GameState::MapLoading)
|
||||
.load_collection::<AudioAssets>()
|
||||
.load_collection::<GameAssets>()
|
||||
.load_collection::<HeadsAssets>()
|
||||
.load_collection::<UIAssets>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn on_exit(
|
||||
mut cmds: Commands,
|
||||
res: Res<HeadsAssets>,
|
||||
mut assets: ResMut<Assets<HeadDatabaseAsset>>,
|
||||
) {
|
||||
let asset = assets
|
||||
.remove(res.heads.id())
|
||||
.expect("headsdb failed to load");
|
||||
|
||||
cmds.insert_resource(HeadsDatabase { heads: asset.0 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user