Merge pull request #1 from Back777space/asset-loading
lebron asset loading
This commit is contained in:
55
Cargo.lock
generated
55
Cargo.lock
generated
@@ -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"
|
||||
|
||||
@@ -5,3 +5,4 @@ edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.15.3"
|
||||
bevy_asset_loader = { version ="0.22.0", features = ["standard_dynamic_assets"] }
|
||||
|
||||
BIN
assets/images/KingLebron.jpg
Normal file
BIN
assets/images/KingLebron.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 84 KiB |
BIN
assets/images/KingLebron.png
Normal file
BIN
assets/images/KingLebron.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 735 KiB |
3
assets/main.assets.ron
Normal file
3
assets/main.assets.ron
Normal file
@@ -0,0 +1,3 @@
|
||||
({
|
||||
"lebron": File (path: "images/KingLebron.png"),
|
||||
})
|
||||
46
src/asset_loading/mod.rs
Normal file
46
src/asset_loading/mod.rs
Normal file
@@ -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::<StandardDynamicAssetCollection>("main.assets.ron")
|
||||
.load_collection::<ImageAssets>(), // .load_collection::<AudioAssets>()
|
||||
// .load_collection::<GltfAssets>()
|
||||
// .load_collection::<TextureAssets>()
|
||||
// .load_collection::<GrassAssets>()
|
||||
// .load_collection::<ConfigAssets>(),
|
||||
);
|
||||
}
|
||||
|
||||
// the following asset collections will be loaded during the State `GameState::InitialLoading`
|
||||
// when done loading, they will be inserted as resources (see <https://github.com/NiklasEi/bevy_asset_loader>)
|
||||
|
||||
#[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<Image>,
|
||||
}
|
||||
29
src/main.rs
29
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::<GameState>()
|
||||
// We need to register components to make them visible to Blenvy
|
||||
.register_type::<Player>()
|
||||
.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<ImageAssets>) {
|
||||
commands.spawn(Sprite::from_image(images.king.clone()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user