Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Bevy 0.14 Running but not fully working #331

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
292 changes: 292 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ homepage = "https://janhohenheim.github.io/foxtrot/"
[features]
default = ["dev"]
dev = [
"dep:bevy_editor_pls",
"dep:bevy-inspector-egui",
"bevy/file_watcher",
"bevy/dynamic_linking",
Expand Down Expand Up @@ -54,10 +55,13 @@ bevy_hanabi = { version = "0.12", default-features = false, features = ["3d"] }
bevy_yarnspinner = "0.3"
bevy_yarnspinner_example_dialogue_view = "0.3"
bevy-tnua-avian3d = "0.1"
avian3d = { version = "0.1", features = ["simd"] }
avian3d = { version = "0.1", features = ["simd", "default-collider"] }
bevy-tnua = "0.19"
bevy_atmosphere = "0.10"
blenvy = { git = "https://github.com/kaosat-dev/blenvy", branch = "blenvy" }
bevy_gltf_blueprints = { git = "https://github.com/kaosat-dev/Blenvy", branch = "bevy-0.14" }
bevy_editor_pls = { version = "0.9", optional = true }
parry3d = { version = "0.15" }

[build-dependencies]
embed-resource = "2"
Expand Down
47 changes: 29 additions & 18 deletions src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,37 @@ use bevy::{
prelude::*,
};
use bevy_inspector_egui::quick::WorldInspectorPlugin;
use bevy_editor_pls::prelude::*;

pub(crate) mod dev_editor;

/// Plugin with debugging utility intended for use during development only.
/// Don't include this in a release build.
pub(super) fn plugin(app: &mut App) {
{
app.add_plugins((
WorldInspectorPlugin::new(),
FrameTimeDiagnosticsPlugin,
LogDiagnosticsPlugin::filtered(vec![]),
PhysicsDebugPlugin::default(),
))
.insert_gizmo_group(
PhysicsGizmos {
aabb_color: Some(Color::WHITE),
..default()
},
GizmoConfig {
enabled: false,
..default()
},
);
}

app.add_plugins(EditorPlugin::new())
.insert_resource(default_editor_controls())
.add_plugins((
FrameTimeDiagnosticsPlugin,
dev_editor::plugin,
LogDiagnosticsPlugin::filtered(vec![]),
PhysicsDebugPlugin::default(),
))
.init_gizmo_group::<DefaultGizmoConfigGroup>();

}


fn default_editor_controls() -> bevy_editor_pls::controls::EditorControls {
use bevy_editor_pls::controls::*;
let mut editor_controls = EditorControls::default_bindings();
editor_controls.unbind(Action::PlayPauseEditor);
editor_controls.insert(
Action::PlayPauseEditor,
Binding {
input: UserInput::Single(Button::Keyboard(KeyCode::KeyQ)),
conditions: vec![BindingCondition::ListeningForText(false)],
},
);
editor_controls
}
85 changes: 85 additions & 0 deletions src/dev/dev_editor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use crate::player_control::camera::ForceCursorGrabMode;
use crate::util::error;
use anyhow::Context;
use bevy::{prelude::*, window::CursorGrabMode};
use bevy_editor_pls::{
editor::{Editor, EditorEvent},
editor_window::EditorWindow,
AddEditorWindow,
};
use bevy_egui::egui;
use avian3d::prelude::PhysicsGizmos;
use serde::{Deserialize, Serialize};

pub(super) fn plugin(app: &mut App) {
app.init_resource::<DevEditorState>()
.add_editor_window::<DevEditorWindow>()
.add_systems(
Update,
(handle_debug_render.pipe(error), set_cursor_grab_mode),
);
}

pub(crate) struct DevEditorWindow;

impl EditorWindow for DevEditorWindow {
type State = DevEditorState;
const NAME: &'static str = "Foxtrot Dev";
const DEFAULT_SIZE: (f32, f32) = (200., 150.);
fn ui(
_world: &mut World,
mut cx: bevy_editor_pls::editor_window::EditorWindowContext,
ui: &mut egui::Ui,
) {
let state = cx
.state_mut::<DevEditorWindow>()
.expect("Failed to get dev window state");

state.open = true;
ui.heading("Debug Rendering");
ui.checkbox(&mut state.collider_render_enabled, "Colliders");
ui.checkbox(&mut state.navmesh_render_enabled, "Navmeshes");
}
}

#[derive(Debug, Clone, Eq, PartialEq, Resource, Reflect, Serialize, Deserialize)]
#[reflect(Resource, Serialize, Deserialize)]
#[derive(Default)]
pub(crate) struct DevEditorState {
pub(crate) open: bool,
pub(crate) collider_render_enabled: bool,
pub(crate) navmesh_render_enabled: bool,
}

fn handle_debug_render(
state: Res<Editor>,
mut last_enabled: Local<bool>,
mut config_store: ResMut<GizmoConfigStore>,
) -> anyhow::Result<()> {
let current_enabled = state
.window_state::<DevEditorWindow>()
.context("Failed to read dev window state")?
.collider_render_enabled;
if current_enabled == *last_enabled {
return Ok(());
}
*last_enabled = current_enabled;
let config = config_store.config_mut::<PhysicsGizmos>().0;
config.enabled = current_enabled;
Ok(())
}

fn set_cursor_grab_mode(
mut events: EventReader<EditorEvent>,
mut force_cursor_grab: ResMut<ForceCursorGrabMode>,
) {
for event in events.read() {
if let EditorEvent::Toggle { now_active } = event {
if *now_active {
force_cursor_grab.0 = Some(CursorGrabMode::None);
} else {
force_cursor_grab.0 = None;
}
}
}
}
2 changes: 1 addition & 1 deletion src/ingame_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn handle_pause(
ui.add_space(100.0);

if ui.button("Quit Game").clicked() {
app_exit_events.send(AppExit);
app_exit_events.send(AppExit::Success);
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/level_instantiation/on_spawn/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub(crate) trait MeshAssetsExt {

impl MeshAssetsExt for Assets<Mesh> {
fn get_or_add(&mut self, handle: Handle<Mesh>, create_mesh: impl Fn() -> Mesh) -> Handle<Mesh> {
self.get_or_insert_with(handle.clone_weak(), create_mesh);
self.get_or_insert_with(&handle.clone_weak(), create_mesh);
handle
}
}
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ pub struct GamePlugin;

impl Plugin for GamePlugin {
fn build(&self, app: &mut App) {
app.init_state::<GameState>().add_plugins((
app
.add_plugins((
system_set::plugin,
bevy_config::plugin,
menu::plugin,
Expand All @@ -72,6 +73,8 @@ impl Plugin for GamePlugin {
particles::plugin,
#[cfg(feature = "dev")]
dev::plugin,
));
))
.init_state::<GameState>()
;
}
}
10 changes: 3 additions & 7 deletions src/menu.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
use crate::GameState;
use bevy::prelude::*;
use bevy_egui::{
egui,
egui::{
FontFamily::Proportional,
FontId,
TextStyle::{Body, Button, Heading},
},
egui::{self, FontFamily::Proportional, FontId, Margin, TextStyle::{Body, Button, Heading}},
EguiContexts,
};

Expand All @@ -33,7 +28,8 @@ fn setup_menu(mut egui_contexts: EguiContexts, mut next_state: ResMut<NextState<

fn get_menu_panel() -> egui::CentralPanel {
egui::CentralPanel::default().frame(egui::Frame {
inner_margin: egui::style::Margin::same(60.),
// inner_margin: egui::style::Margin::same(60.),
inner_margin: Margin::same(60.),
..default()
})
}
Expand Down
73 changes: 47 additions & 26 deletions src/movement/character_controller/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn play_animations(
TnuaAnimatingStateDirective::Maintain { state } => {
if let AnimationState::Running(speed) = state {
let anim_speed = (speed / 7.0).max(1.0);
animation_player.set_speed(anim_speed);
animation_player.adjust_speeds(anim_speed);
}
}
TnuaAnimatingStateDirective::Alter {
Expand All @@ -86,39 +86,60 @@ fn play_animations(
} => match state {
AnimationState::Airborne | AnimationState::Running(..) => {
animation_player
.play_with_transition(
animations
.named_animations
.play(
*animations.named_indices
.get(&animation_names.aerial)
.unwrap()
.clone_weak(),
Duration::from_secs_f32(0.2),
)
.repeat();
).repeat().set_speed(0.2);
// animation_player
// .play_with_transition(
// animations
// .named_animations
// .get(&animation_names.aerial)
// .unwrap()
// .clone_weak(),
// Duration::from_secs_f32(0.2),
// )
// .repeat();
}
AnimationState::Standing => {
animation_player
.play_with_transition(
animations
.named_animations
.get(&animation_names.idle)
.unwrap()
.clone_weak(),
Duration::from_secs_f32(0.2),
)
.repeat();
.play(
*animations.named_indices
.get(&animation_names.idle)
.unwrap()
).repeat().set_speed(0.2);

// animation_player
// .play_with_transition(
// animations
// .named_animations
// .get(&animation_names.idle)
// .unwrap()
// .clone_weak(),
// Duration::from_secs_f32(0.2),
// )
// .repeat();
}
AnimationState::Walking(_speed) => {

animation_player
.play_with_transition(
animations
.named_animations
.get(&animation_names.walk)
.unwrap()
.clone_weak(),
Duration::from_secs_f32(0.1),
)
.repeat();
.play(
*animations.named_indices
.get(&animation_names.walk)
.unwrap()
).repeat().set_speed(0.1);

// animation_player
// .play_with_transition(
// animations
// .named_animations
// .get(&animation_names.walk)
// .unwrap()
// .clone_weak(),
// Duration::from_secs_f32(0.1),
// )
// .repeat();
}
},
}
Expand Down
Loading