mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-18 07:35:19 +00:00
Add StudioMode enum to toggle edit functionality
This commit is contained in:
+4
-2
@@ -7,7 +7,7 @@ use bevy_mod_picking::debug::DebugPickingMode;
|
|||||||
use crate::{
|
use crate::{
|
||||||
camera_controller::{CameraController, CameraMotionSystem},
|
camera_controller::{CameraController, CameraMotionSystem},
|
||||||
input::{Action, InputAction, Lifecycle},
|
input::{Action, InputAction, Lifecycle},
|
||||||
MainCamera,
|
is_editor, MainCamera,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Resource, Deref, DerefMut)]
|
#[derive(Resource, Deref, DerefMut)]
|
||||||
@@ -36,7 +36,9 @@ impl Plugin for DebugPlugin {
|
|||||||
Update,
|
Update,
|
||||||
(
|
(
|
||||||
toggle_debug_mode,
|
toggle_debug_mode,
|
||||||
update_debug_picking_mode.run_if(resource_changed::<DebugMode>()),
|
update_debug_picking_mode
|
||||||
|
.run_if(is_editor)
|
||||||
|
.run_if(resource_changed::<DebugMode>()),
|
||||||
update_gizmo_line_thickness,
|
update_gizmo_line_thickness,
|
||||||
(draw_world_axes, draw_debug_points)
|
(draw_world_axes, draw_debug_points)
|
||||||
.after(CameraMotionSystem)
|
.after(CameraMotionSystem)
|
||||||
|
|||||||
+3
-1
@@ -5,6 +5,8 @@ use bevy::{
|
|||||||
};
|
};
|
||||||
use space_editor::prelude::space_undo::UndoRedo;
|
use space_editor::prelude::space_undo::UndoRedo;
|
||||||
|
|
||||||
|
use crate::is_editor;
|
||||||
|
|
||||||
#[derive(SystemSet, Hash, Debug, PartialEq, Eq, Clone)]
|
#[derive(SystemSet, Hash, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct StudioInputSystem;
|
pub struct StudioInputSystem;
|
||||||
|
|
||||||
@@ -31,7 +33,7 @@ impl Plugin for StudioInputPlugin {
|
|||||||
translate_debug_toggle,
|
translate_debug_toggle,
|
||||||
translate_dcc_camera_events,
|
translate_dcc_camera_events,
|
||||||
translate_fps_camera_events,
|
translate_fps_camera_events,
|
||||||
send_undo_event,
|
send_undo_event.run_if(is_editor),
|
||||||
)
|
)
|
||||||
.in_set(StudioInputSystem)
|
.in_set(StudioInputSystem)
|
||||||
.after(bevy::input::InputSystem)
|
.after(bevy::input::InputSystem)
|
||||||
|
|||||||
+99
-19
@@ -1,6 +1,6 @@
|
|||||||
#![allow(clippy::type_complexity, clippy::too_many_arguments)]
|
#![allow(clippy::type_complexity, clippy::too_many_arguments)]
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::{app::PluginGroupBuilder, prelude::*};
|
||||||
use bevy_mod_picking::DefaultPickingPlugins;
|
use bevy_mod_picking::DefaultPickingPlugins;
|
||||||
|
|
||||||
use space_editor::prelude::space_undo::UndoPlugin;
|
use space_editor::prelude::space_undo::UndoPlugin;
|
||||||
@@ -40,6 +40,46 @@ mod wasm;
|
|||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub(crate) struct MainCamera;
|
pub(crate) struct MainCamera;
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "wasm", wasm_bindgen)]
|
||||||
|
#[derive(Resource, Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
|
pub enum StudioMode {
|
||||||
|
Editor,
|
||||||
|
Viewer,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn is_editor(r_studio_mode: Res<StudioMode>) -> bool {
|
||||||
|
matches!(*r_studio_mode, StudioMode::Editor)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The collection of plugins that should be loaded for both viewer-mode and
|
||||||
|
/// editor-mode instances of the app.
|
||||||
|
struct CommonPlugins;
|
||||||
|
impl PluginGroup for CommonPlugins {
|
||||||
|
fn build(self) -> PluginGroupBuilder {
|
||||||
|
PluginGroupBuilder::start::<Self>()
|
||||||
|
.add(CameraControllerPlugin)
|
||||||
|
.add(DebugPlugin)
|
||||||
|
.add(InspectorPlugin)
|
||||||
|
.add(InterpolationPlugin)
|
||||||
|
.add(ScenePlugin)
|
||||||
|
.add(SkyboxPlugin)
|
||||||
|
.add(StudioInputPlugin)
|
||||||
|
.add(UiLayerPlugin)
|
||||||
|
.add(WorldGridPlugin)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The collection of plugins that should be loaded only for editor-mode
|
||||||
|
/// instances of the app.
|
||||||
|
struct EditorPlugins;
|
||||||
|
impl PluginGroup for EditorPlugins {
|
||||||
|
fn build(self) -> PluginGroupBuilder {
|
||||||
|
PluginGroupBuilder::start::<Self>()
|
||||||
|
.add(InteractionPlugin)
|
||||||
|
.add(UndoPlugin)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "wasm", wasm_bindgen)]
|
#[cfg_attr(feature = "wasm", wasm_bindgen)]
|
||||||
pub fn init(viewport_size: ViewportSize) {
|
pub fn init(viewport_size: ViewportSize) {
|
||||||
#[cfg(feature = "wasm")]
|
#[cfg(feature = "wasm")]
|
||||||
@@ -116,6 +156,49 @@ pub fn start_viewer(
|
|||||||
canvas_selector: &str,
|
canvas_selector: &str,
|
||||||
canvas_alt: &str,
|
canvas_alt: &str,
|
||||||
viewport_size: ViewportSize,
|
viewport_size: ViewportSize,
|
||||||
|
) {
|
||||||
|
info!("start_viewer");
|
||||||
|
|
||||||
|
start_internal(
|
||||||
|
object_id,
|
||||||
|
skybox_id,
|
||||||
|
canvas_selector,
|
||||||
|
canvas_alt,
|
||||||
|
viewport_size,
|
||||||
|
StudioMode::Viewer,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "wasm", wasm_bindgen(js_name = startEditor))]
|
||||||
|
pub fn start_editor(
|
||||||
|
object_id: &str,
|
||||||
|
skybox_id: &str,
|
||||||
|
canvas_selector: &str,
|
||||||
|
canvas_alt: &str,
|
||||||
|
viewport_size: ViewportSize,
|
||||||
|
) {
|
||||||
|
info!("start_editor");
|
||||||
|
|
||||||
|
start_internal(
|
||||||
|
object_id,
|
||||||
|
skybox_id,
|
||||||
|
canvas_selector,
|
||||||
|
canvas_alt,
|
||||||
|
viewport_size,
|
||||||
|
StudioMode::Editor,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: These `start_` functiions should be refactored to better support the
|
||||||
|
// needs of the "reaodnly viewer" vs "full studio editor" use cases.
|
||||||
|
#[cfg_attr(feature = "wasm", wasm_bindgen(js_name = start))]
|
||||||
|
pub fn start_internal(
|
||||||
|
object_id: &str,
|
||||||
|
skybox_id: &str,
|
||||||
|
canvas_selector: &str,
|
||||||
|
canvas_alt: &str,
|
||||||
|
viewport_size: ViewportSize,
|
||||||
|
studio_mode: StudioMode,
|
||||||
) {
|
) {
|
||||||
#[cfg(feature = "wasm")]
|
#[cfg(feature = "wasm")]
|
||||||
console_error_panic_hook::set_once();
|
console_error_panic_hook::set_once();
|
||||||
@@ -124,6 +207,9 @@ pub fn start_viewer(
|
|||||||
let skybox_id = skybox_id.to_string();
|
let skybox_id = skybox_id.to_string();
|
||||||
|
|
||||||
let mut app = App::new();
|
let mut app = App::new();
|
||||||
|
|
||||||
|
app.insert_resource(studio_mode);
|
||||||
|
|
||||||
app.add_plugins((
|
app.add_plugins((
|
||||||
#[cfg(feature = "wasm")]
|
#[cfg(feature = "wasm")]
|
||||||
viewport::wasm::ViewportPlugin,
|
viewport::wasm::ViewportPlugin,
|
||||||
@@ -136,20 +222,18 @@ pub fn start_viewer(
|
|||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
DefaultPickingPlugins,
|
CommonPlugins,
|
||||||
DebugPlugin,
|
));
|
||||||
InteractionPlugin,
|
|
||||||
InspectorPlugin,
|
if matches!(studio_mode, StudioMode::Editor) {
|
||||||
StudioInputPlugin,
|
app.add_plugins((DefaultPickingPlugins, EditorPlugins));
|
||||||
InterpolationPlugin,
|
|
||||||
CameraControllerPlugin,
|
// Only for registering components for undo
|
||||||
ScenePlugin,
|
use space_editor::prelude::space_undo::AppAutoUndo;
|
||||||
SkyboxPlugin,
|
app.auto_reflected_undo::<Transform>();
|
||||||
UiLayerPlugin,
|
}
|
||||||
WorldGridPlugin,
|
|
||||||
UndoPlugin,
|
app.add_systems(
|
||||||
))
|
|
||||||
.add_systems(
|
|
||||||
Startup,
|
Startup,
|
||||||
move |mut cmd: Commands, mut ew: EventWriter<LoadSceneEvent>| {
|
move |mut cmd: Commands, mut ew: EventWriter<LoadSceneEvent>| {
|
||||||
cmd.insert_resource(SkyboxId(skybox_id.clone()));
|
cmd.insert_resource(SkyboxId(skybox_id.clone()));
|
||||||
@@ -157,10 +241,6 @@ pub fn start_viewer(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// Only for registering components for undo
|
|
||||||
use space_editor::prelude::space_undo::AppAutoUndo;
|
|
||||||
app.auto_reflected_undo::<Transform>();
|
|
||||||
|
|
||||||
#[cfg(feature = "wasm")]
|
#[cfg(feature = "wasm")]
|
||||||
wasm::initialize();
|
wasm::initialize();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user