diff --git a/Cargo.lock b/Cargo.lock index 73d88d0..91a2552 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -123,6 +123,7 @@ name = "among-me" version = "0.1.0" dependencies = [ "bevy", + "bevy_asset_loader", ] [[package]] @@ -167,6 +168,12 @@ dependencies = [ "libc", ] +[[package]] +name = "anyhow" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" + [[package]] name = "approx" version = "0.5.1" @@ -421,6 +428,31 @@ dependencies = [ "web-sys", ] +[[package]] +name = "bevy_asset_loader" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d806c255faca43ace03fe99889dd322e295a55ed4dd478a5d8ea6efe523158fe" +dependencies = [ + "anyhow", + "bevy", + "bevy_asset_loader_derive", + "bevy_common_assets", + "path-slash", + "serde", +] + +[[package]] +name = "bevy_asset_loader_derive" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b758b06fa9ec729c925f1fc256b503ca438f1ea345636af362b5fae71f5d8868" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "bevy_asset_macros" version = "0.15.3" @@ -467,6 +499,19 @@ dependencies = [ "wgpu-types", ] +[[package]] +name = "bevy_common_assets" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3521990269672c442f2bf0fbed0fce9db719e3dd136dd4012a97809464a4389d" +dependencies = [ + "anyhow", + "bevy", + "ron", + "serde", + "thiserror", +] + [[package]] name = "bevy_core" version = "0.15.3" @@ -2119,7 +2164,7 @@ dependencies = [ "vec_map", "wasm-bindgen", "web-sys", - "windows 0.54.0", + "windows 0.58.0", ] [[package]] @@ -2235,7 +2280,7 @@ dependencies = [ "log", "presser", "thiserror", - "windows 0.54.0", + "windows 0.58.0", ] [[package]] @@ -3122,6 +3167,12 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "path-slash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42" + [[package]] name = "percent-encoding" version = "2.3.1" diff --git a/Cargo.toml b/Cargo.toml index 508c68c..b69d09c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,4 @@ edition = "2024" [dependencies] bevy = "0.15.3" +bevy_asset_loader = { version ="0.22.0", features = ["standard_dynamic_assets"] } diff --git a/assets/images/KingLebron.jpg b/assets/images/KingLebron.jpg new file mode 100644 index 0000000..f75a822 Binary files /dev/null and b/assets/images/KingLebron.jpg differ diff --git a/assets/images/KingLebron.png b/assets/images/KingLebron.png new file mode 100644 index 0000000..a15ef2b Binary files /dev/null and b/assets/images/KingLebron.png differ diff --git a/assets/main.assets.ron b/assets/main.assets.ron new file mode 100644 index 0000000..f7b7b12 --- /dev/null +++ b/assets/main.assets.ron @@ -0,0 +1,3 @@ +({ + "lebron": File (path: "images/KingLebron.png"), +}) diff --git a/src/asset_loading/mod.rs b/src/asset_loading/mod.rs new file mode 100644 index 0000000..7572579 --- /dev/null +++ b/src/asset_loading/mod.rs @@ -0,0 +1,46 @@ +use bevy::prelude::*; + +use crate::GameState; +use bevy_asset_loader::prelude::*; +// use bevy_egui::{EguiContexts, egui, egui::ProgressBar}; +// use bevy_kira_audio::AudioSource; +// use iyes_progress::{ProgressCounter, ProgressPlugin}; + +/// Loads resources and assets for the game. +/// See assets/main.assets.ron for the actual paths used. +pub(super) fn plugin(app: &mut App) { + app.add_loading_state( + LoadingState::new(GameState::Loading) + .continue_to_state(GameState::Menu) + .with_dynamic_assets_file::("main.assets.ron") + .load_collection::(), // .load_collection::() + // .load_collection::() + // .load_collection::() + // .load_collection::() + // .load_collection::(), + ); +} + +// the following asset collections will be loaded during the State `GameState::InitialLoading` +// when done loading, they will be inserted as resources (see ) + +#[derive(AssetCollection, Resource, Clone)] +pub(crate) struct AudioAssets {} + +#[derive(AssetCollection, Resource, Clone)] +pub(crate) struct GltfAssets {} + +#[derive(AssetCollection, Resource, Clone)] +pub(crate) struct TextureAssets {} + +#[derive(AssetCollection, Resource, Clone)] +pub(crate) struct GrassAssets {} + +#[derive(AssetCollection, Resource, Clone)] +pub(crate) struct ConfigAssets {} + +#[derive(AssetCollection, Resource, Clone)] +pub(crate) struct ImageAssets { + #[asset(key = "lebron")] + pub(crate) king: Handle, +} diff --git a/src/main.rs b/src/main.rs index 2fad18b..17f6e09 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,29 @@ -use bevy::prelude::*; +use asset_loading::ImageAssets; +use bevy::{prelude::*, state::app::StatesPlugin}; + +mod asset_loading; fn main() -> AppExit { App::new() - .add_plugins((DefaultPlugins)) + .add_plugins((DefaultPlugins, asset_loading::plugin)) + .init_state::() // We need to register components to make them visible to Blenvy - .register_type::() .add_systems(Startup, setup) + .add_systems(OnExit(GameState::Loading), debug_our_king) .run() } +#[derive(States, Default, Clone, Eq, PartialEq, Debug, Hash)] +enum GameState { + /// During the loading State the loading_plugin will load our assets + #[default] + Loading, + /// During this State the actual game logic is executed + Playing, + /// Here the menu is drawn and waiting for player interaction + Menu, +} + #[derive(Component, Reflect)] struct Player { strength: f32, @@ -20,4 +35,10 @@ struct Player { luck: f32, } -fn setup(mut commands: Commands) {} +fn setup(mut commands: Commands) { + commands.spawn(Camera2d); +} + +fn debug_our_king(mut commands: Commands, images: Res) { + commands.spawn(Sprite::from_image(images.king.clone())); +}