mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-29 09:08:58 +00:00
Refactor entry-point functions (#26)
This PR refactors the `studio` project's entry-point functions for better maintainability and ease of use for local development. ### Overview * `start_internal` refactored to return a `bevy::app::App` instead of calling `App::run`, allowing for finer-grained configuration of unique use cases * Temporary `start` function added for WASM * `init` function removed * `main` standalone entry-point refactored to call `start_internal` ### Fixes * Crash on non-WASM builds due to missing `StudioMode` resource * Warning on non-WASM builds due to an unused variable
This commit is contained in:
@@ -6,7 +6,11 @@ mod wasm;
|
|||||||
pub struct InspectorPlugin;
|
pub struct InspectorPlugin;
|
||||||
|
|
||||||
impl Plugin for InspectorPlugin {
|
impl Plugin for InspectorPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(
|
||||||
|
&self,
|
||||||
|
#[cfg(feature = "wasm")] app: &mut App,
|
||||||
|
#[cfg(not(feature = "wasm"))] _: &mut App,
|
||||||
|
) {
|
||||||
#[cfg(feature = "wasm")]
|
#[cfg(feature = "wasm")]
|
||||||
app.add_systems(
|
app.add_systems(
|
||||||
PostUpdate,
|
PostUpdate,
|
||||||
|
|||||||
+28
-66
@@ -30,10 +30,11 @@ use crate::{
|
|||||||
scene::{LoadSceneEvent, ScenePlugin},
|
scene::{LoadSceneEvent, ScenePlugin},
|
||||||
skybox::{SkyboxId, SkyboxPlugin},
|
skybox::{SkyboxId, SkyboxPlugin},
|
||||||
ui::UiLayerPlugin,
|
ui::UiLayerPlugin,
|
||||||
viewport::ViewportSize,
|
|
||||||
world_grid::WorldGridPlugin,
|
world_grid::WorldGridPlugin,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub use crate::viewport::ViewportSize;
|
||||||
|
|
||||||
#[cfg(feature = "wasm")]
|
#[cfg(feature = "wasm")]
|
||||||
mod wasm;
|
mod wasm;
|
||||||
|
|
||||||
@@ -80,66 +81,6 @@ impl PluginGroup for EditorPlugins {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "wasm", wasm_bindgen)]
|
|
||||||
pub fn init(viewport_size: ViewportSize) {
|
|
||||||
#[cfg(feature = "wasm")]
|
|
||||||
console_error_panic_hook::set_once();
|
|
||||||
|
|
||||||
let mut app = App::new();
|
|
||||||
|
|
||||||
#[cfg(feature = "wasm")]
|
|
||||||
app.add_plugins(viewport::wasm::ViewportPlugin);
|
|
||||||
|
|
||||||
app.add_plugins((
|
|
||||||
DefaultPlugins
|
|
||||||
// TODO: To generate asset .meta files (to prevent 404 errors on the
|
|
||||||
// web), it's currently necessary to uncomment the following
|
|
||||||
// block and run the app with this command:
|
|
||||||
// > cargo run -p studio --features bevy/asset_processor,bevy/tonemapping_luts
|
|
||||||
// .set(AssetPlugin {
|
|
||||||
// mode: AssetMode::Processed,
|
|
||||||
// ..default()
|
|
||||||
// })
|
|
||||||
.set(WindowPlugin {
|
|
||||||
primary_window: Some(Window {
|
|
||||||
resolution: viewport_size.into(),
|
|
||||||
title: "Storyteller Studio".into(),
|
|
||||||
canvas: Some("#studio_canvas".into()),
|
|
||||||
..default()
|
|
||||||
}),
|
|
||||||
..default()
|
|
||||||
}),
|
|
||||||
DefaultPickingPlugins,
|
|
||||||
DebugPlugin,
|
|
||||||
InteractionPlugin,
|
|
||||||
InspectorPlugin,
|
|
||||||
StudioInputPlugin,
|
|
||||||
InterpolationPlugin,
|
|
||||||
CameraControllerPlugin,
|
|
||||||
ScenePlugin,
|
|
||||||
SkyboxPlugin,
|
|
||||||
UiLayerPlugin,
|
|
||||||
WorldGridPlugin,
|
|
||||||
UndoPlugin,
|
|
||||||
))
|
|
||||||
.add_systems(
|
|
||||||
Startup,
|
|
||||||
move |mut cmd: Commands, mut ew: EventWriter<LoadSceneEvent>| {
|
|
||||||
cmd.insert_resource(SkyboxId("gum_trees_4k".to_string()));
|
|
||||||
ew.send(LoadSceneEvent("bookcase".to_string()));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// Only for registering components for undo
|
|
||||||
use space_editor::prelude::space_undo::AppAutoUndo;
|
|
||||||
app.auto_reflected_undo::<Transform>();
|
|
||||||
|
|
||||||
#[cfg(feature = "wasm")]
|
|
||||||
wasm::initialize();
|
|
||||||
|
|
||||||
app.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg_attr(feature = "wasm", wasm_bindgen(js_name = startViewer))]
|
#[cfg_attr(feature = "wasm", wasm_bindgen(js_name = startViewer))]
|
||||||
/// Start the application as a read-only viewer for a single library object.
|
/// Start the application as a read-only viewer for a single library object.
|
||||||
///
|
///
|
||||||
@@ -164,7 +105,8 @@ pub fn start_viewer(
|
|||||||
canvas_alt,
|
canvas_alt,
|
||||||
viewport_size,
|
viewport_size,
|
||||||
StudioMode::Viewer,
|
StudioMode::Viewer,
|
||||||
);
|
)
|
||||||
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "wasm", wasm_bindgen(js_name = startEditor))]
|
#[cfg_attr(feature = "wasm", wasm_bindgen(js_name = startEditor))]
|
||||||
@@ -182,14 +124,15 @@ pub fn start_editor(
|
|||||||
canvas_alt,
|
canvas_alt,
|
||||||
viewport_size,
|
viewport_size,
|
||||||
StudioMode::Editor,
|
StudioMode::Editor,
|
||||||
);
|
)
|
||||||
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: These `start_` functiions should be refactored to better support the
|
// TODO: These `start_` functiions should be refactored to better support the
|
||||||
// needs of the "reaodnly viewer" vs "full studio editor" use cases. See
|
// needs of the "reaodnly viewer" vs "full studio editor" use cases. See
|
||||||
// notes in `studio-web/src/lib/viewer.element.ts` for more info.
|
// notes in `studio-web/src/lib/viewer.element.ts` for more info.
|
||||||
#[cfg_attr(feature = "wasm", wasm_bindgen(js_name = start))]
|
#[cfg_attr(feature = "wasm", wasm_bindgen)]
|
||||||
pub fn start_internal(
|
pub fn start(
|
||||||
object_id: &str,
|
object_id: &str,
|
||||||
skybox_id: &str,
|
skybox_id: &str,
|
||||||
canvas_selector: &str,
|
canvas_selector: &str,
|
||||||
@@ -197,6 +140,25 @@ pub fn start_internal(
|
|||||||
viewport_size: ViewportSize,
|
viewport_size: ViewportSize,
|
||||||
studio_mode: StudioMode,
|
studio_mode: StudioMode,
|
||||||
) {
|
) {
|
||||||
|
start_internal(
|
||||||
|
object_id,
|
||||||
|
skybox_id,
|
||||||
|
canvas_selector,
|
||||||
|
canvas_alt,
|
||||||
|
viewport_size,
|
||||||
|
studio_mode,
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn start_internal(
|
||||||
|
object_id: &str,
|
||||||
|
skybox_id: &str,
|
||||||
|
canvas_selector: &str,
|
||||||
|
canvas_alt: &str,
|
||||||
|
viewport_size: ViewportSize,
|
||||||
|
studio_mode: StudioMode,
|
||||||
|
) -> App {
|
||||||
#[cfg(feature = "wasm")]
|
#[cfg(feature = "wasm")]
|
||||||
console_error_panic_hook::set_once();
|
console_error_panic_hook::set_once();
|
||||||
|
|
||||||
@@ -241,5 +203,5 @@ pub fn start_internal(
|
|||||||
#[cfg(feature = "wasm")]
|
#[cfg(feature = "wasm")]
|
||||||
wasm::initialize();
|
wasm::initialize();
|
||||||
|
|
||||||
app.run();
|
app
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-1
@@ -1,3 +1,19 @@
|
|||||||
|
use bevy::{app::Update, window::close_on_esc};
|
||||||
|
use studio::{StudioMode, ViewportSize};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
studio::init(Default::default());
|
// Edit the arguments here to change the default startup scene or skybox
|
||||||
|
let mut app = studio::start_internal(
|
||||||
|
"sample-room",
|
||||||
|
"gum_trees_4k",
|
||||||
|
"", // ignored for non-WASM
|
||||||
|
"Storyteller Studio",
|
||||||
|
ViewportSize::default(),
|
||||||
|
StudioMode::Editor,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add any additional systems, resources, etc. for local debugging
|
||||||
|
app.add_systems(Update, close_on_esc);
|
||||||
|
|
||||||
|
app.run();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user