mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
Make the web CityPicker do all of the same stuff that app.switch_map does
This commit is contained in:
parent
1de7065562
commit
1ae4c6e41f
@ -124,13 +124,29 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Refactor the CityPicker trick as a general loading screen for native or web, and change
|
||||
// all callers of this to organize control flow around a State.
|
||||
pub fn switch_map(&mut self, ctx: &mut EventCtx, load: String) {
|
||||
ctx.canvas.save_camera_state(self.primary.map.get_name());
|
||||
let mut flags = self.primary.current_flags.clone();
|
||||
flags.sim_flags.load = load;
|
||||
let session = std::mem::replace(&mut self.session, SessionState::empty());
|
||||
*self = App::new(flags, self.opts.clone(), ctx, false);
|
||||
self.session = session;
|
||||
|
||||
ctx.loading_screen("load map", |ctx, timer| {
|
||||
let (map, sim, _) = flags.sim_flags.load(timer);
|
||||
self.map_switched(ctx, map, sim, timer);
|
||||
});
|
||||
}
|
||||
pub fn map_switched(&mut self, ctx: &mut EventCtx, map: Map, sim: Sim, timer: &mut Timer) {
|
||||
ctx.canvas.save_camera_state(self.primary.map.get_name());
|
||||
self.primary = PerMap::map_loaded(
|
||||
map,
|
||||
sim,
|
||||
false,
|
||||
self.primary.current_flags.clone(),
|
||||
&self.opts,
|
||||
&self.cs,
|
||||
ctx,
|
||||
timer,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn draw(
|
||||
|
@ -296,19 +296,18 @@ mod loader {
|
||||
impl State for AsyncFileLoader {
|
||||
fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
|
||||
if let Some(resp) = self.response.try_recv().unwrap() {
|
||||
// TODO We stop drawing the timer and start blocking at this point. It can take a
|
||||
// TODO We stop drawing and start blocking at this point. It can take a
|
||||
// while. Any way to make it still be nonblockingish? Maybe put some of the work
|
||||
// inside that spawn_local?
|
||||
let map: Map = abstutil::from_binary(&resp).unwrap();
|
||||
|
||||
// TODO This is a hack, repeating only some parts of app.switch_map. Refactor.
|
||||
let bounds = map.get_bounds();
|
||||
ctx.canvas.map_dims = (bounds.width(), bounds.height());
|
||||
app.primary.map = map;
|
||||
let mut timer = Timer::new("switch maps");
|
||||
app.primary.draw_map =
|
||||
DrawMap::new(&app.primary.map, &app.opts, &app.cs, ctx, &mut timer);
|
||||
app.primary.clear_sim();
|
||||
let mut timer = Timer::new("finish loading map");
|
||||
let map: Map = abstutil::from_binary(&resp).unwrap();
|
||||
let sim = Sim::new(
|
||||
&map,
|
||||
app.primary.current_flags.sim_flags.opts.clone(),
|
||||
&mut timer,
|
||||
);
|
||||
app.map_switched(ctx, map, sim, &mut timer);
|
||||
|
||||
return (self.on_load)(ctx, app);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user