diff --git a/editor/src/plugins/sim/controls.rs b/editor/src/plugins/sim/controls.rs index e0538b00d6..e136fd4c96 100644 --- a/editor/src/plugins/sim/controls.rs +++ b/editor/src/plugins/sim/controls.rs @@ -31,6 +31,14 @@ impl SimControls { primary_events: None, } } + + pub fn run_sim(&mut self, primary_sim: &mut Sim) { + self.state = State::Running { + last_step: Instant::now(), + benchmark: primary_sim.start_benchmark(), + speed: "running".to_string(), + }; + } } impl Plugin for SimControls { @@ -118,11 +126,7 @@ impl Plugin for SimControls { } if ctx.input.action_chosen("run/pause sim") { - self.state = State::Running { - last_step: Instant::now(), - benchmark: ctx.primary.sim.start_benchmark(), - speed: "running".to_string(), - }; + self.run_sim(&mut ctx.primary.sim); } else if ctx.input.action_chosen("run one step of sim") { let tick = ctx.primary.sim.time; let events = ctx.primary.sim.step(&ctx.primary.map); diff --git a/editor/src/plugins/sim/mod.rs b/editor/src/plugins/sim/mod.rs index ace7fe4f66..ae1d3491ee 100644 --- a/editor/src/plugins/sim/mod.rs +++ b/editor/src/plugins/sim/mod.rs @@ -6,7 +6,7 @@ mod show_score; use crate::objects::Ctx; use crate::plugins::{Plugin, PluginCtx}; use ezgui::GfxCtx; -use sim::{Event, Tick}; +use sim::{Event, Sim, Tick}; // TODO This is per UI, so it's never reloaded. Make sure to detect new loads, even when the // initial time is 0? But we probably have no state then, so... @@ -44,6 +44,13 @@ impl SimMode { None } } + + pub fn run_sim(&mut self, primary_sim: &mut Sim) { + self.ambient_plugins[1] + .downcast_mut::() + .unwrap() + .run_sim(primary_sim); + } } impl Plugin for SimMode { diff --git a/editor/src/tutorial.rs b/editor/src/tutorial.rs index f61a80a32b..b53d4191f0 100644 --- a/editor/src/tutorial.rs +++ b/editor/src/tutorial.rs @@ -62,6 +62,9 @@ impl UIState for TutorialState { State::GiveInstructions(ref mut scroller) => { if scroller.event(input) { setup_scenario(&mut self.main.primary); + // TODO Levels of indirection now feel bad. I almost want dependency injection + // -- just give me the SimControls. + self.main.sim_mode.run_sim(&mut self.main.primary.sim); self.state = State::Play { last_tick_observed: None, spawned_from_north: 0,