mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 23:15:24 +03:00
debug cars and peds
This commit is contained in:
parent
3941621127
commit
aaf2933768
@ -11,6 +11,10 @@ use std::fs::File;
|
||||
use std::hash::Hash;
|
||||
use std::io::{Error, ErrorKind, Read, Write};
|
||||
|
||||
pub fn dump_json<T: Serialize>(obj: &T) {
|
||||
println!("{}", serde_json::to_string_pretty(obj).unwrap());
|
||||
}
|
||||
|
||||
pub fn write_json<T: Serialize>(path: &str, obj: &T) -> Result<(), Error> {
|
||||
let mut file = File::create(path)?;
|
||||
file.write_all(serde_json::to_string_pretty(obj).unwrap().as_bytes())?;
|
||||
|
@ -58,7 +58,7 @@ impl SelectionState {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn event(&mut self, input: &mut UserInput, map: &Map) -> bool {
|
||||
pub fn event(&mut self, input: &mut UserInput, map: &Map, sim: &Sim) -> bool {
|
||||
let mut new_state: Option<SelectionState> = None;
|
||||
let active = match self {
|
||||
SelectionState::SelectedLane(id, current_turn_index) => {
|
||||
@ -92,6 +92,14 @@ impl SelectionState {
|
||||
false
|
||||
}
|
||||
}
|
||||
SelectionState::SelectedPedestrian(id) => {
|
||||
if input.key_pressed(Key::D, "debug") {
|
||||
sim.debug_ped(*id);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
if let Some(s) = new_state {
|
||||
|
@ -485,7 +485,10 @@ impl gui::GUI for UI {
|
||||
}
|
||||
|
||||
// Do this one lastish, since it conflicts with lots of other stuff
|
||||
stop_if_done!(self.current_selection_state.event(input, &self.map));
|
||||
stop_if_done!(
|
||||
self.current_selection_state
|
||||
.event(input, &self.map, &self.sim_ctrl.sim)
|
||||
);
|
||||
|
||||
if input.unimportant_key_pressed(Key::Escape, "quit") {
|
||||
let state = EditorState {
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
use abstutil;
|
||||
use control::ControlMap;
|
||||
use dimensioned::si;
|
||||
use draw_car::DrawCar;
|
||||
@ -313,6 +314,10 @@ impl Sim {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn debug_ped(&self, id: PedestrianID) {
|
||||
self.walking_state.debug_ped(id);
|
||||
}
|
||||
|
||||
pub fn ped_tooltip(&self, p: PedestrianID) -> Vec<String> {
|
||||
vec![format!("Hello to {}", p)]
|
||||
}
|
||||
@ -325,16 +330,20 @@ impl Sim {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn toggle_debug(&mut self, car: CarID) {
|
||||
pub fn toggle_debug(&mut self, id: CarID) {
|
||||
if let Some(c) = self.debug {
|
||||
if c != car {
|
||||
if c != id {
|
||||
self.driving_state.cars.get_mut(&c).unwrap().debug = false;
|
||||
}
|
||||
}
|
||||
|
||||
let c = self.driving_state.cars.get_mut(&car).unwrap();
|
||||
c.debug = !c.debug;
|
||||
self.debug = Some(car);
|
||||
if let Some(car) = self.driving_state.cars.get_mut(&id) {
|
||||
abstutil::dump_json(car);
|
||||
car.debug = !car.debug;
|
||||
self.debug = Some(id);
|
||||
} else {
|
||||
println!("{} is parked somewhere", id);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start_benchmark(&self) -> Benchmark {
|
||||
|
@ -1,3 +1,4 @@
|
||||
use abstutil;
|
||||
use abstutil::{deserialize_multimap, serialize_multimap};
|
||||
use dimensioned::si;
|
||||
use draw_ped::DrawPedestrian;
|
||||
@ -234,6 +235,14 @@ impl WalkingSimState {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn debug_ped(&self, id: PedestrianID) {
|
||||
if let Some(ped) = self.peds.get(&id) {
|
||||
abstutil::dump_json(ped);
|
||||
} else {
|
||||
println!("{} doesn't exist", id);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_draw_ped(&self, id: PedestrianID, map: &Map) -> Option<DrawPedestrian> {
|
||||
let ped = self.peds.get(&id)?;
|
||||
Some(DrawPedestrian::new(
|
||||
|
Loading…
Reference in New Issue
Block a user