mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 01:15:12 +03:00
Remember the last map loaded, and start the game with that, unless using --dev or some other override
This commit is contained in:
parent
eea136d2ca
commit
d3c035ffb3
@ -140,7 +140,7 @@ fn run(mut settings: Settings) {
|
||||
|
||||
fn setup_app(
|
||||
ctx: &mut EventCtx,
|
||||
flags: Flags,
|
||||
mut flags: Flags,
|
||||
mut opts: Options,
|
||||
start_with_edits: Option<String>,
|
||||
maybe_mode: Option<GameplayMode>,
|
||||
@ -152,6 +152,17 @@ fn setup_app(
|
||||
&& !flags.sim_flags.load.contains("player/save")
|
||||
&& !flags.sim_flags.load.contains("/scenarios/")
|
||||
&& maybe_mode.is_none();
|
||||
|
||||
// Load the map used previously if we're starting on the title screen without any overrides.
|
||||
if title && flags.sim_flags.load == MapName::seattle("montlake").path() {
|
||||
if let Ok(default) = abstio::maybe_read_json::<map_gui::tools::DefaultMap>(
|
||||
abstio::path_player("maps.json"),
|
||||
&mut Timer::throwaway(),
|
||||
) {
|
||||
flags.sim_flags.load = default.last_map.path();
|
||||
}
|
||||
}
|
||||
|
||||
// If we're starting directly in a challenge mode, the tutorial, or by playing a scenario,
|
||||
// usually time is midnight, so save some effort and start with the correct color scheme. If
|
||||
// we're loading a savestate and it's actually daytime, we'll pay a small penalty to switch
|
||||
|
@ -40,6 +40,14 @@ impl<T: 'static> SimpleApp<T> {
|
||||
let map_name = args
|
||||
.optional_free()
|
||||
.map(|path| MapName::from_path(&path).expect(&format!("bad map path: {}", path)))
|
||||
.or_else(|| {
|
||||
abstio::maybe_read_json::<crate::tools::DefaultMap>(
|
||||
abstio::path_player("maps.json"),
|
||||
&mut Timer::throwaway(),
|
||||
)
|
||||
.ok()
|
||||
.map(|x| x.last_map)
|
||||
})
|
||||
.unwrap_or(MapName::seattle("montlake"));
|
||||
let center_camera = args.optional("--cam");
|
||||
args.done();
|
||||
|
@ -3,6 +3,7 @@ use widgetry::{Canvas, EventCtx};
|
||||
|
||||
use abstio::MapName;
|
||||
use abstutil::Timer;
|
||||
use map_model::Map;
|
||||
|
||||
/// Represents the state of a widgetry Canvas.
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
@ -12,15 +13,33 @@ pub struct CameraState {
|
||||
cam_zoom: f64,
|
||||
}
|
||||
|
||||
/// Track the last map used, to resume next session.
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct DefaultMap {
|
||||
pub last_map: MapName,
|
||||
}
|
||||
|
||||
impl CameraState {
|
||||
/// Save the camera's configuration for the specified map.
|
||||
/// Save the camera's configuration for the specified map, and also remember this map was the
|
||||
/// last to be used.
|
||||
pub fn save(canvas: &Canvas, name: &MapName) {
|
||||
if name == Map::blank().get_name() {
|
||||
return;
|
||||
}
|
||||
|
||||
let state = CameraState {
|
||||
cam_x: canvas.cam_x,
|
||||
cam_y: canvas.cam_y,
|
||||
cam_zoom: canvas.cam_zoom,
|
||||
};
|
||||
abstio::write_json(abstio::path_camera_state(name), &state);
|
||||
|
||||
abstio::write_json(
|
||||
abstio::path_player("maps.json"),
|
||||
&DefaultMap {
|
||||
last_map: name.clone(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Load the camera's configuration for the specified map. Returns true if successful, has no
|
||||
|
@ -4,7 +4,7 @@ use abstio::MapName;
|
||||
use geom::Polygon;
|
||||
use widgetry::{GfxCtx, Line, Text};
|
||||
|
||||
pub use self::camera::CameraState;
|
||||
pub use self::camera::{CameraState, DefaultMap};
|
||||
pub use self::city_picker::CityPicker;
|
||||
pub use self::colors::{ColorDiscrete, ColorLegend, ColorNetwork, ColorScale, DivergingScale};
|
||||
pub use self::heatmap::{make_heatmap, Grid, HeatmapOptions};
|
||||
|
Loading…
Reference in New Issue
Block a user