Add Asset loader, added and configured various states
This commit is contained in:
30
Cargo.lock
generated
30
Cargo.lock
generated
@@ -565,6 +565,29 @@ dependencies = [
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bevy_asset_loader"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "653857e8685ba3c6f237a7aa67620ae440c87e975f8a843ef098c90c49b9dde6"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bevy",
|
||||
"bevy_asset_loader_derive",
|
||||
"path-slash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bevy_asset_loader_derive"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ea90451960d44a9908e95de892511dead119b909da68e56b92527efcfac8691"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bevy_asset_macros"
|
||||
version = "0.16.1"
|
||||
@@ -4009,6 +4032,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"
|
||||
@@ -4798,6 +4827,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"bevy",
|
||||
"bevy-inspector-egui",
|
||||
"bevy_asset_loader",
|
||||
"bevy_rapier3d",
|
||||
]
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ edition = "2024"
|
||||
bevy = { version = "0.16.1", features = [] }
|
||||
# bevy_rapier3d = { version = "0.29.0", features = ["simd-stable", "parallel"] }
|
||||
bevy-inspector-egui = "0.31.0"
|
||||
bevy_asset_loader = "0.23.0"
|
||||
bevy_rapier3d = "0.30.0"
|
||||
|
||||
[features]
|
||||
|
||||
16
src/macros.rs
Normal file
16
src/macros.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
#[macro_export]
|
||||
macro_rules! configure_sets {
|
||||
(
|
||||
$app: expr,
|
||||
$system_set: expr,
|
||||
$condition: expr
|
||||
) => {
|
||||
$app.configure_sets(PreUpdate, $system_set.run_if($condition))
|
||||
.configure_sets(Update, $system_set.run_if($condition))
|
||||
.configure_sets(PostUpdate, $system_set.run_if($condition))
|
||||
.configure_sets(Last, $system_set.run_if($condition));
|
||||
$app.configure_sets(FixedPreUpdate, $system_set.run_if($condition))
|
||||
.configure_sets(FixedUpdate, $system_set.run_if($condition))
|
||||
.configure_sets(FixedPostUpdate, $system_set.run_if($condition));
|
||||
};
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
mod macros;
|
||||
mod plugins;
|
||||
mod states;
|
||||
mod utils;
|
||||
|
||||
@@ -5,12 +5,18 @@ use crate::{
|
||||
tags::{Player, Ship},
|
||||
},
|
||||
plugins::{state_management::StateManagementPlugin, *},
|
||||
states::input::{InputState, PlayerState},
|
||||
states::{
|
||||
game::*,
|
||||
input::{InputState, PlayerState},
|
||||
loading::{AssetLoadingState, StartupLoadingState},
|
||||
menu::MenuState,
|
||||
},
|
||||
};
|
||||
use bevy::{
|
||||
prelude::*,
|
||||
window::{CursorGrabMode, PrimaryWindow},
|
||||
};
|
||||
use bevy_asset_loader::prelude::*;
|
||||
use bevy_rapier3d::prelude::*;
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -18,6 +24,18 @@ pub struct GamePlugin;
|
||||
|
||||
impl Plugin for GamePlugin {
|
||||
fn build(&self, app: &mut bevy::app::App) {
|
||||
app.init_state::<AssetLoadingState>();
|
||||
app.init_state::<StartupLoadingState>();
|
||||
app.insert_state(GameState::Startup);
|
||||
app.init_state::<MenuState>();
|
||||
app.init_state::<PlayerState>();
|
||||
app.add_loading_state(
|
||||
LoadingState::new(AssetLoadingState::Loading).continue_to_state(AssetLoadingState::Finalizing),
|
||||
)
|
||||
.add_loading_state(
|
||||
LoadingState::new(StartupLoadingState::Loading).continue_to_state(StartupLoadingState::Finalizing),
|
||||
);
|
||||
|
||||
app.add_plugins((
|
||||
FollowCamPlugin,
|
||||
CameraPlugin,
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::states::input::{InputState, PlayerInputSystems, PlayerState};
|
||||
use crate::{
|
||||
configure_sets,
|
||||
states::{
|
||||
input::{InputState, PlayerInputSystems, PlayerState},
|
||||
menu::{
|
||||
MainMenuSystems, MenuCleanupSystems, MenuStartupSystems, MenuState, OptionsMenuSystems, SavesMenuSystems,
|
||||
},
|
||||
play::{PausedSystems, PlayCleanupSystems, PlayStartupSystems, PlayState, PlaySystems},
|
||||
},
|
||||
};
|
||||
|
||||
pub struct StateManagementPlugin;
|
||||
|
||||
@@ -9,8 +18,24 @@ impl Plugin for StateManagementPlugin {
|
||||
app.init_state::<PlayerState>();
|
||||
app.init_state::<InputState>();
|
||||
|
||||
app.configure_sets(PreUpdate, PlayerInputSystems.run_if(in_state(InputState::World)));
|
||||
app.configure_sets(Update, PlayerInputSystems.run_if(in_state(InputState::World)));
|
||||
app.configure_sets(PostUpdate, PlayerInputSystems.run_if(in_state(InputState::World)));
|
||||
//Menu
|
||||
configure_sets!(app, MenuStartupSystems, in_state(MenuState::Startup));
|
||||
configure_sets!(app, MainMenuSystems, in_state(MenuState::Main));
|
||||
configure_sets!(app, OptionsMenuSystems, in_state(MenuState::Options));
|
||||
configure_sets!(app, SavesMenuSystems, in_state(MenuState::Saves));
|
||||
configure_sets!(app, MenuCleanupSystems, in_state(MenuState::Cleanup));
|
||||
|
||||
//Play
|
||||
configure_sets!(app, PlayStartupSystems, in_state(PlayState::Startup));
|
||||
configure_sets!(app, PausedSystems, in_state(PlayState::Paused));
|
||||
configure_sets!(app, PlaySystems, in_state(PlayState::Playing));
|
||||
configure_sets!(app, PlayCleanupSystems, in_state(PlayState::Cleanup));
|
||||
|
||||
//Input
|
||||
configure_sets!(
|
||||
app,
|
||||
PlayerInputSystems,
|
||||
in_state(InputState::World).and(in_state(PlayState::Playing))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
9
src/states/game.rs
Normal file
9
src/states/game.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
#[derive(States, Debug, Reflect, Default, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum GameState {
|
||||
#[default]
|
||||
Startup,
|
||||
MainMenu,
|
||||
PlayGame,
|
||||
}
|
||||
18
src/states/loading.rs
Normal file
18
src/states/loading.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use bevy::prelude::*;
|
||||
#[derive(States, Debug, Default, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum StartupLoadingState {
|
||||
#[default]
|
||||
Pending,
|
||||
Loading,
|
||||
Finalizing,
|
||||
Done,
|
||||
}
|
||||
|
||||
#[derive(States, Debug, Default, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum AssetLoadingState {
|
||||
#[default]
|
||||
Pending,
|
||||
Loading,
|
||||
Finalizing,
|
||||
Done,
|
||||
}
|
||||
27
src/states/menu.rs
Normal file
27
src/states/menu.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
#[derive(States, Debug, Reflect, Default, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum MenuState {
|
||||
#[default]
|
||||
Loading,
|
||||
Startup,
|
||||
Main,
|
||||
Saves,
|
||||
Options,
|
||||
Cleanup,
|
||||
}
|
||||
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct MenuStartupSystems;
|
||||
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct MainMenuSystems;
|
||||
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct OptionsMenuSystems;
|
||||
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct SavesMenuSystems;
|
||||
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct MenuCleanupSystems;
|
||||
@@ -1 +1,5 @@
|
||||
pub mod game;
|
||||
pub mod input;
|
||||
pub mod loading;
|
||||
pub mod menu;
|
||||
pub mod play;
|
||||
|
||||
23
src/states/play.rs
Normal file
23
src/states/play.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
#[derive(States, Debug, Reflect, Default, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum PlayState {
|
||||
#[default]
|
||||
Loading,
|
||||
Startup,
|
||||
Playing,
|
||||
Paused,
|
||||
Cleanup,
|
||||
}
|
||||
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct PlayStartupSystems;
|
||||
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct PlaySystems;
|
||||
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct PlayCleanupSystems;
|
||||
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct PausedSystems;
|
||||
Reference in New Issue
Block a user