diff --git a/editor/src/lib.rs b/editor/src/lib.rs index a1ac1853f..4058ea61c 100644 --- a/editor/src/lib.rs +++ b/editor/src/lib.rs @@ -319,6 +319,15 @@ pub struct GameLoopData { elapsed_time: f32, } +pub struct StartupData { + /// Working directory that should be set when starting the editor. If it is empty, then + /// current working directory won't be changed. + pub working_directory: PathBuf, + + /// A scene to load at the editor start. If it is empty, no scene will be loaded. + pub scene: PathBuf, +} + pub struct Editor { game_loop_data: GameLoopData, engine: Engine, @@ -352,7 +361,7 @@ pub struct Editor { } impl Editor { - pub fn new(event_loop: &EventLoop<()>) -> Self { + pub fn new(event_loop: &EventLoop<()>, startup_data: Option) -> Self { let inner_size = if let Some(primary_monitor) = event_loop.primary_monitor() { let mut monitor_dimensions = primary_monitor.size(); monitor_dimensions.height = (monitor_dimensions.height as f32 * 0.7) as u32; @@ -393,13 +402,6 @@ impl Editor { message_sender.clone(), &mut engine.user_interface.build_ctx(), ); - engine - .user_interface - .send_message(WindowMessage::open_modal( - configurator.window, - MessageDirection::ToWidget, - true, - )); let mut settings = Settings::default(); @@ -617,6 +619,34 @@ impl Editor { editor.set_interaction_mode(Some(InteractionModeKind::Move)); + if let Some(data) = startup_data { + if data.working_directory != PathBuf::default() { + editor + .message_sender + .send(Message::Configure { + working_directory: data.working_directory, + }) + .unwrap(); + } + + if data.scene != PathBuf::default() { + editor + .message_sender + .send(Message::LoadScene(data.scene)) + .unwrap(); + } + } else { + // Open configurator as usual. + editor + .engine + .user_interface + .send_message(WindowMessage::open_modal( + editor.configurator.window, + MessageDirection::ToWidget, + true, + )); + } + editor } diff --git a/examples/scripting/.idea/workspace.xml b/examples/scripting/.idea/workspace.xml index af1cdc063..9f232594d 100644 --- a/examples/scripting/.idea/workspace.xml +++ b/examples/scripting/.idea/workspace.xml @@ -10,12 +10,11 @@ - + + - - diff --git a/examples/scripting/editor/src/main.rs b/examples/scripting/editor/src/main.rs index 10858302c..f16079195 100644 --- a/examples/scripting/editor/src/main.rs +++ b/examples/scripting/editor/src/main.rs @@ -1,10 +1,16 @@ use fyrox::event_loop::EventLoop; -use fyroxed::Editor; +use fyroxed::{Editor, StartupData}; use game::GamePlugin; fn main() { let event_loop = EventLoop::new(); - let mut editor = Editor::new(&event_loop); + let mut editor = Editor::new( + &event_loop, + Some(StartupData { + working_directory: Default::default(), + scene: "unnamed.rgs".into(), + }), + ); editor.add_game_plugin(GamePlugin::new()); editor.run(event_loop) } diff --git a/examples/scripting/game/src/lib.rs b/examples/scripting/game/src/lib.rs index 9ec65ba51..c26b6d7da 100644 --- a/examples/scripting/game/src/lib.rs +++ b/examples/scripting/game/src/lib.rs @@ -33,6 +33,7 @@ use std::{cell::RefCell, rc::Rc, str::FromStr}; pub struct GamePlugin { scene: Handle, ui: Rc>, + debug_draw: bool, } impl Default for GamePlugin { @@ -46,6 +47,7 @@ impl GamePlugin { Self { scene: Default::default(), ui: Rc::new(RefCell::new(UserInterface::new(Vector2::new(100.0, 100.0)))), + debug_draw: false, } } } @@ -149,9 +151,11 @@ impl Plugin for GamePlugin { fn update(&mut self, context: &mut PluginContext) { let scene = &mut context.scenes[self.scene]; - let drawing_context = &mut scene.drawing_context; - drawing_context.clear_lines(); - scene.graph.physics.draw(drawing_context); + if self.debug_draw { + let drawing_context = &mut scene.drawing_context; + drawing_context.clear_lines(); + scene.graph.physics.draw(drawing_context); + } let mut ui = self.ui.borrow_mut(); diff --git a/examples/scripting/unnamed.rgs b/examples/scripting/unnamed.rgs index 8a2db1a06..05db21d52 100644 Binary files a/examples/scripting/unnamed.rgs and b/examples/scripting/unnamed.rgs differ diff --git a/src/script/mod.rs b/src/script/mod.rs index 8d0763342..b87b5ab27 100644 --- a/src/script/mod.rs +++ b/src/script/mod.rs @@ -105,7 +105,7 @@ pub trait ScriptTrait: BaseScript { /// } /// ``` fn on_property_changed(&mut self, #[allow(unused_variables)] args: &PropertyChanged) -> bool { - return false; + false } /// Called on parent scene initialization. It is guaranteed to be called once, and before any