mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-17 00:13:17 +00:00
Update to bevy 0.13 (#87)
Co-authored-by: Lee-Orr <lee-orr@users.noreply.github.com> Co-authored-by: Danny McGee <dannymcgee@gmail.com>
This commit is contained in:
+69
-50
@@ -1,22 +1,23 @@
|
||||
use std::fmt;
|
||||
|
||||
use bevy::{prelude::*, window::PrimaryWindow};
|
||||
use bevy_inspector_egui::{bevy_egui::EguiPlugin, DefaultInspectorConfigPlugin};
|
||||
use bevy_inspector_egui::DefaultInspectorConfigPlugin;
|
||||
use bevy_mod_picking::debug::DebugPickingMode;
|
||||
use space_editor::prelude::space_undo::AppAutoUndo;
|
||||
use space_editor::{
|
||||
prelude::EditorCameraMarker,
|
||||
space_editor_ui::{
|
||||
bottom_menu::BottomMenuPlugin, tools::gizmo::GizmoToolPlugin, EditorDefaultCameraPlugin,
|
||||
EditorGizmoConfigPlugin, EditorPickingPlugin, EditorPluginGroup, EditorUiCore,
|
||||
ShowEditorUi,
|
||||
},
|
||||
prelude::*,
|
||||
space_editor_ui::{tools::gizmo::GizmoToolPlugin, EditorPluginGroup},
|
||||
};
|
||||
|
||||
use crate::StudioMode;
|
||||
use crate::{
|
||||
anim::SkeletalJoint,
|
||||
camera_controller::{CameraController, CameraMotionSystem},
|
||||
input::{Action, InputAction, Lifecycle},
|
||||
is_editor, MainCamera,
|
||||
interaction::Selectable,
|
||||
is_editor,
|
||||
scene::SceneElement,
|
||||
MainCamera,
|
||||
};
|
||||
|
||||
#[derive(Resource, Deref, DerefMut)]
|
||||
@@ -32,13 +33,16 @@ pub struct DebugPlugin;
|
||||
impl Plugin for DebugPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(DebugMode(false))
|
||||
.insert_resource(State::new(DebugPickingMode::Disabled))
|
||||
.insert_resource(GizmoConfig {
|
||||
enabled: true,
|
||||
depth_bias: -0.1,
|
||||
line_perspective: false,
|
||||
line_width: 2.,
|
||||
..default()
|
||||
.insert_resource(DebugPickingMode::Disabled)
|
||||
.add_systems(Startup, |mut config_store: ResMut<GizmoConfigStore>| {
|
||||
let (config, _) = config_store.config_mut::<DefaultGizmoConfigGroup>();
|
||||
*config = GizmoConfig {
|
||||
enabled: true,
|
||||
depth_bias: -0.1,
|
||||
line_perspective: false,
|
||||
line_width: 2.,
|
||||
..default()
|
||||
};
|
||||
})
|
||||
.add_systems(
|
||||
Update,
|
||||
@@ -46,7 +50,7 @@ impl Plugin for DebugPlugin {
|
||||
toggle_debug_mode,
|
||||
update_debug_picking_mode
|
||||
.run_if(is_editor)
|
||||
.run_if(resource_changed::<DebugMode>()),
|
||||
.run_if(resource_changed::<DebugMode>),
|
||||
update_gizmo_line_thickness,
|
||||
(draw_world_axes, draw_debug_points, draw_skeletal_joints)
|
||||
.after(CameraMotionSystem)
|
||||
@@ -54,38 +58,52 @@ impl Plugin for DebugPlugin {
|
||||
),
|
||||
);
|
||||
|
||||
//space_editor stuff
|
||||
// app.add_plugins(UndoPlugin);
|
||||
app.add_plugins(
|
||||
EditorPluginGroup
|
||||
.build()
|
||||
.disable::<EditorUiCore>()
|
||||
.add_before::<EditorDefaultCameraPlugin, _>(EditorUiCore {
|
||||
disable_no_editor_cams: false,
|
||||
})
|
||||
.disable::<EguiPlugin>()
|
||||
.disable::<DefaultInspectorConfigPlugin>()
|
||||
.disable::<EditorPickingPlugin>()
|
||||
.disable::<EditorDefaultCameraPlugin>()
|
||||
.disable::<BottomMenuPlugin>()
|
||||
.disable::<GizmoToolPlugin>()
|
||||
.disable::<EditorGizmoConfigPlugin>()
|
||||
.set(space_editor::prelude::SelectedPlugin {
|
||||
show_selected_wireframe: false,
|
||||
}),
|
||||
);
|
||||
let editor_ui_group = EditorPluginGroup
|
||||
.build()
|
||||
.disable::<EditorUiCore>()
|
||||
.add_before::<GameViewPlugin, _>(EditorUiCore {
|
||||
disable_no_editor_cams: false,
|
||||
})
|
||||
// .disable::<EguiPlugin>()
|
||||
.disable::<DefaultInspectorConfigPlugin>()
|
||||
.disable::<EditorPickingPlugin>()
|
||||
.disable::<EditorDefaultCameraPlugin>()
|
||||
// .disable::<BottomMenuPlugin>()
|
||||
.disable::<GizmoToolPlugin>()
|
||||
// .disable::<EditorGizmoConfigPlugin>()
|
||||
// .disable::<MeshlessVisualizerPlugin>()
|
||||
.disable::<space_editor::prelude::SelectedPlugin>();
|
||||
|
||||
app.add_systems(Update, sync_editor_camera);
|
||||
app.add_systems(
|
||||
Update,
|
||||
update_editor_ui_mode.run_if(resource_changed::<DebugMode>()),
|
||||
);
|
||||
let mut only_core = false;
|
||||
|
||||
#[cfg(feature = "wasm")]
|
||||
{
|
||||
if let Some(state) = app.world.get_resource::<StudioMode>() {
|
||||
if *state == StudioMode::Headless {
|
||||
only_core = true;
|
||||
}
|
||||
}
|
||||
|
||||
if only_core {
|
||||
app.add_plugins(PrefabPlugin).add_plugins(EditorCore);
|
||||
} else {
|
||||
app.add_plugins(editor_ui_group);
|
||||
app.auto_undo::<Handle<StandardMaterial>>();
|
||||
app.auto_undo::<SkeletalJoint>();
|
||||
app.auto_undo::<Handle<Mesh>>();
|
||||
app.auto_undo::<SceneElement>();
|
||||
app.auto_undo::<Selectable>();
|
||||
|
||||
#[cfg(feature = "wasm")]
|
||||
{
|
||||
app.add_systems(
|
||||
PostUpdate,
|
||||
wasm::notify_debug_mode_toggle.map(bevy::utils::error),
|
||||
);
|
||||
}
|
||||
|
||||
app.add_systems(Update, sync_editor_camera);
|
||||
app.add_systems(
|
||||
PostUpdate,
|
||||
wasm::notify_debug_mode_toggle.map(bevy::utils::error),
|
||||
Update,
|
||||
update_editor_ui_mode.run_if(resource_changed::<DebugMode>),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -112,12 +130,12 @@ fn update_editor_ui_mode(
|
||||
|
||||
fn update_debug_picking_mode(
|
||||
r_debug: Res<DebugMode>,
|
||||
mut s_debug_picking: ResMut<NextState<DebugPickingMode>>,
|
||||
mut s_debug_picking: ResMut<DebugPickingMode>,
|
||||
) {
|
||||
s_debug_picking.set(match **r_debug {
|
||||
*s_debug_picking = match **r_debug {
|
||||
true => DebugPickingMode::Normal,
|
||||
false => DebugPickingMode::Disabled,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
pub fn is_debug_mode(r_debug: Res<DebugMode>) -> bool {
|
||||
@@ -125,10 +143,11 @@ pub fn is_debug_mode(r_debug: Res<DebugMode>) -> bool {
|
||||
}
|
||||
|
||||
fn update_gizmo_line_thickness(
|
||||
mut config: ResMut<GizmoConfig>,
|
||||
mut config_store: ResMut<GizmoConfigStore>,
|
||||
q_window: Query<&Window, (Changed<Window>, With<PrimaryWindow>)>,
|
||||
) {
|
||||
if let Ok(scale_factor) = q_window.get_single().map(|win| win.scale_factor() as f32) {
|
||||
if let Ok(scale_factor) = q_window.get_single().map(|win| win.scale_factor()) {
|
||||
let (config, _) = config_store.config_mut::<DefaultGizmoConfigGroup>();
|
||||
config.line_width = 2. * scale_factor;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user