mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 20:29:04 +03:00
filling out logging in editor crate
This commit is contained in:
parent
e6e1f7cbc5
commit
a53dd51ec4
@ -98,6 +98,7 @@ nice UI features:
|
||||
- remember where the log scroller is, even when hidden
|
||||
- jump to end or beginning quickly
|
||||
- start at the end
|
||||
- show new messages in OSD briefly, then vanish
|
||||
|
||||
log crate is annoying -- cant initialize it, but also have something else hold
|
||||
onto it. probably have to use lazy static. not even sure I'll use this implicit
|
||||
|
@ -98,7 +98,7 @@ impl ColorScheme {
|
||||
|
||||
for color in Colors::iter() {
|
||||
if !scheme.map.contains_key(&color) {
|
||||
println!(
|
||||
warn!(
|
||||
"No color for {:?} defined, initializing with a random one",
|
||||
color
|
||||
);
|
||||
|
@ -28,7 +28,7 @@ pub enum ExtraShapeGeom {
|
||||
}
|
||||
|
||||
pub fn load(path: &String, gps_bounds: &Bounds) -> Result<Vec<ExtraShape>, io::Error> {
|
||||
println!("Opening {}", path);
|
||||
info!("Opening {}", path);
|
||||
let f = File::open(path).unwrap();
|
||||
let mut reader = Reader::from_reader(io::BufReader::new(f));
|
||||
reader.trim_text(true);
|
||||
@ -47,7 +47,7 @@ pub fn load(path: &String, gps_bounds: &Bounds) -> Result<Vec<ExtraShape>, io::E
|
||||
loop {
|
||||
if reader.buffer_position() - last_progress_byte >= 1024 * 1024 * 10 {
|
||||
last_progress_byte = reader.buffer_position();
|
||||
println!(
|
||||
info!(
|
||||
"Processed {} MB of {}",
|
||||
last_progress_byte / (1024 * 1024),
|
||||
path
|
||||
@ -113,7 +113,7 @@ pub fn load(path: &String, gps_bounds: &Bounds) -> Result<Vec<ExtraShape>, io::E
|
||||
buf.clear();
|
||||
}
|
||||
|
||||
println!(
|
||||
info!(
|
||||
"Got {} shapes from {} and skipped {} shapes",
|
||||
shapes.len(),
|
||||
path,
|
||||
|
37
editor/src/macros.rs
Normal file
37
editor/src/macros.rs
Normal file
@ -0,0 +1,37 @@
|
||||
// Call the log crate, but pre-set the target.
|
||||
|
||||
macro_rules! debug {
|
||||
( $( $x:expr ),* ) => {
|
||||
{
|
||||
extern crate log;
|
||||
log!(target: "UI", log::Level::Debug, $( $x, )* );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! info {
|
||||
( $( $x:expr ),* ) => {
|
||||
{
|
||||
extern crate log;
|
||||
log!(target: "UI", log::Level::Info, $( $x, )* );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! warn {
|
||||
( $( $x:expr ),* ) => {
|
||||
{
|
||||
extern crate log;
|
||||
log!(target: "UI", log::Level::Warn, $( $x, )* );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! error {
|
||||
( $( $x:expr ),* ) => {
|
||||
{
|
||||
extern crate log;
|
||||
log!(target: "UI", log::Level::Error, $( $x, )* );
|
||||
}
|
||||
}
|
||||
}
|
@ -30,6 +30,9 @@ extern crate strum;
|
||||
#[macro_use]
|
||||
extern crate strum_macros;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
mod colors;
|
||||
mod kml;
|
||||
mod objects;
|
||||
|
@ -60,7 +60,7 @@ impl ColorPicker {
|
||||
new_state = Some(ColorPicker::Inactive);
|
||||
} else if input.key_pressed(Key::Return, &format!("finalize new color for {:?}", c))
|
||||
{
|
||||
println!("Setting color for {:?}", c);
|
||||
info!("Setting color for {:?}", c);
|
||||
new_state = Some(ColorPicker::Inactive);
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ impl DrawPolygonState {
|
||||
if input.key_pressed(Key::Tab, "list existing polygons") {
|
||||
let polygons = polygons::load_all_polygons(map.get_name());
|
||||
if polygons.is_empty() {
|
||||
println!("Sorry, no existing polygons");
|
||||
warn!("Sorry, no existing polygons");
|
||||
} else {
|
||||
new_state = Some(DrawPolygonState::ListingPolygons(
|
||||
Menu::new("Load which polygon?", polygons.keys().cloned().collect()),
|
||||
@ -106,7 +106,7 @@ impl DrawPolygonState {
|
||||
}
|
||||
DrawPolygonState::NamingPolygon(tb, pts) => match tb.event(input) {
|
||||
InputResult::Canceled => {
|
||||
println!("Never mind!");
|
||||
info!("Never mind!");
|
||||
new_state = Some(DrawPolygonState::Empty);
|
||||
}
|
||||
InputResult::Done(name) => {
|
||||
@ -118,7 +118,7 @@ impl DrawPolygonState {
|
||||
points: pts.clone(),
|
||||
},
|
||||
).expect("Saving polygon selection failed");
|
||||
println!("Saved {}", path);
|
||||
info!("Saved {}", path);
|
||||
new_state = Some(DrawPolygonState::Empty);
|
||||
}
|
||||
InputResult::StillActive => {}
|
||||
|
@ -49,7 +49,7 @@ impl FollowState {
|
||||
canvas.center_on_map_pt(c.front);
|
||||
input.key_pressed(Key::Return, "stop following")
|
||||
} else {
|
||||
println!("{} is gone, no longer following", id);
|
||||
warn!("{} is gone, no longer following", id);
|
||||
true
|
||||
}
|
||||
}
|
||||
@ -58,7 +58,7 @@ impl FollowState {
|
||||
canvas.center_on_map_pt(p.pos);
|
||||
input.key_pressed(Key::Return, "stop following")
|
||||
} else {
|
||||
println!("{} is gone, no longer following", id);
|
||||
warn!("{} is gone, no longer following", id);
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ impl Validator {
|
||||
objects.push((ID::Parcel(p.id), make_polys(&p.fill_polygon)));
|
||||
}
|
||||
|
||||
println!(
|
||||
info!(
|
||||
"{} objects total. About {} possible overlaps",
|
||||
objects.len(),
|
||||
objects.len().pow(2)
|
||||
@ -114,15 +114,14 @@ impl Validator {
|
||||
*current_problem = gen.next();
|
||||
|
||||
if let Some((id1, id2)) = current_problem {
|
||||
println!("{:?} and {:?} intersect", id1, id2);
|
||||
info!("{:?} and {:?} intersect", id1, id2);
|
||||
canvas.center_on_map_pt(get_pt(map, *id1));
|
||||
// TODO also modify selection state to highlight stuff?
|
||||
} else {
|
||||
println!("No more problems!");
|
||||
info!("No more problems!");
|
||||
new_state = Some(Validator::Inactive);
|
||||
}
|
||||
} else if input.key_pressed(Key::Escape, "stop looking at problems") {
|
||||
println!("Quit geometry validator");
|
||||
new_state = Some(Validator::Inactive);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ impl Hider {
|
||||
|
||||
pub fn event(&mut self, input: &mut UserInput, selected: &mut Option<ID>) -> bool {
|
||||
if input.unimportant_key_pressed(Key::K, DEBUG_EXTRA, "unhide everything") {
|
||||
println!("Unhiding {} things", self.items.len());
|
||||
info!("Unhiding {} things", self.items.len());
|
||||
self.items.clear();
|
||||
return true;
|
||||
}
|
||||
@ -39,7 +39,7 @@ impl Hider {
|
||||
};
|
||||
if input.unimportant_key_pressed(Key::H, DEBUG_EXTRA, &format!("hide {:?}", item)) {
|
||||
self.items.insert(item);
|
||||
println!("Hiding {:?}", item);
|
||||
info!("Hiding {:?}", item);
|
||||
*selected = None;
|
||||
return true;
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ impl RoadEditor {
|
||||
}
|
||||
if input.key_pressed(Key::Backspace, "delete this lane") {
|
||||
if edits.delete_lane(road, lane) {
|
||||
println!("Have to reload the map from scratch to pick up this change!");
|
||||
warn!("Have to reload the map from scratch to pick up this change!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ impl SimController {
|
||||
*sim = new_sim;
|
||||
self.benchmark = None;
|
||||
}
|
||||
Err(e) => println!("Couldn't load savestate: {}", e),
|
||||
Err(e) => error!("Couldn't load savestate: {}", e),
|
||||
};
|
||||
}
|
||||
if self.last_step.is_some() {
|
||||
|
@ -73,55 +73,55 @@ fn warp(line: String, map: &Map, sim: &Sim, canvas: &mut Canvas, selected: &mut
|
||||
let id = RoadID(idx);
|
||||
if let Some(r) = map.maybe_get_r(id) {
|
||||
let l = map.get_l(r.children_forwards[0].0);
|
||||
info!(target: "UI", "Warping to {}, which belongs to {}", l.id, id);
|
||||
info!("Warping to {}, which belongs to {}", l.id, id);
|
||||
*selected = Some(ID::Lane(l.id));
|
||||
l.first_pt()
|
||||
} else {
|
||||
warn!(target: "UI", "{} doesn't exist", id);
|
||||
warn!("{} doesn't exist", id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
'l' => {
|
||||
let id = LaneID(idx);
|
||||
if let Some(l) = map.maybe_get_l(id) {
|
||||
info!(target: "UI", "Warping to {}", id);
|
||||
info!("Warping to {}", id);
|
||||
*selected = Some(ID::Lane(id));
|
||||
l.first_pt()
|
||||
} else {
|
||||
warn!(target: "UI", "{} doesn't exist", id);
|
||||
warn!("{} doesn't exist", id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
'i' => {
|
||||
let id = IntersectionID(idx);
|
||||
if let Some(i) = map.maybe_get_i(id) {
|
||||
info!(target: "UI", "Warping to {}", id);
|
||||
info!("Warping to {}", id);
|
||||
*selected = Some(ID::Intersection(id));
|
||||
i.point
|
||||
} else {
|
||||
warn!(target: "UI", "{} doesn't exist", id);
|
||||
warn!("{} doesn't exist", id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
'b' => {
|
||||
let id = BuildingID(idx);
|
||||
if let Some(b) = map.maybe_get_b(id) {
|
||||
info!(target: "UI", "Warping to {}", id);
|
||||
info!("Warping to {}", id);
|
||||
*selected = Some(ID::Building(id));
|
||||
Pt2D::center(&b.points)
|
||||
} else {
|
||||
warn!(target: "UI", "{} doesn't exist", id);
|
||||
warn!("{} doesn't exist", id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
'a' => {
|
||||
let id = AreaID(idx);
|
||||
if let Some(a) = map.maybe_get_a(id) {
|
||||
info!(target: "UI", "Warping to {}", id);
|
||||
info!("Warping to {}", id);
|
||||
*selected = Some(ID::Area(id));
|
||||
Pt2D::center(&a.points)
|
||||
} else {
|
||||
warn!(target: "UI", "{} doesn't exist", id);
|
||||
warn!("{} doesn't exist", id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -129,37 +129,37 @@ fn warp(line: String, map: &Map, sim: &Sim, canvas: &mut Canvas, selected: &mut
|
||||
'e' => {
|
||||
let id = ParcelID(idx);
|
||||
if let Some(p) = map.maybe_get_p(id) {
|
||||
info!(target: "UI", "Warping to {}", id);
|
||||
info!("Warping to {}", id);
|
||||
Pt2D::center(&p.points)
|
||||
} else {
|
||||
warn!(target: "UI", "{} doesn't exist", id);
|
||||
warn!("{} doesn't exist", id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
'p' => {
|
||||
let id = PedestrianID(idx);
|
||||
if let Some(p) = sim.get_draw_ped(id, map) {
|
||||
info!(target: "UI", "Warping to {}", id);
|
||||
info!("Warping to {}", id);
|
||||
*selected = Some(ID::Pedestrian(id));
|
||||
p.pos
|
||||
} else {
|
||||
warn!(target: "UI", "{} doesn't exist", id);
|
||||
warn!("{} doesn't exist", id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
'c' => {
|
||||
let id = CarID(idx);
|
||||
if let Some(c) = sim.get_draw_car(id, map) {
|
||||
info!(target: "UI", "Warping to {}", id);
|
||||
info!("Warping to {}", id);
|
||||
*selected = Some(ID::Car(id));
|
||||
c.front
|
||||
} else {
|
||||
warn!(target: "UI", "{} doesn't exist", id);
|
||||
warn!("{} doesn't exist", id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
warn!(target: "UI", "{} isn't a valid ID; Should be [libepc][0-9]+", line);
|
||||
warn!("{} isn't a valid ID; Should be [libepc][0-9]+", line);
|
||||
return;
|
||||
}
|
||||
},
|
||||
|
@ -47,10 +47,10 @@ impl WizardSample {
|
||||
}
|
||||
WizardSample::Active(ref mut wizard) => {
|
||||
if let Some(spec) = workflow(wizard.wrap(input, map)) {
|
||||
println!("Got answer: {:?}", spec);
|
||||
info!("Got answer: {:?}", spec);
|
||||
new_state = Some(WizardSample::Inactive);
|
||||
} else if wizard.aborted() {
|
||||
println!("User aborted the workflow");
|
||||
info!("User aborted the workflow");
|
||||
new_state = Some(WizardSample::Inactive);
|
||||
}
|
||||
}
|
||||
@ -206,7 +206,7 @@ impl Wizard {
|
||||
if let Some(result) = parser(line.clone()) {
|
||||
Some(result)
|
||||
} else {
|
||||
println!("Invalid input {}", line);
|
||||
warn!("Invalid input {}", line);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ impl UIWrapper {
|
||||
|
||||
match abstutil::read_json::<EditorState>("editor_state") {
|
||||
Ok(ref state) if *ui.map.get_name() == state.map_name => {
|
||||
info!(target: "UI", "Loaded previous editor_state");
|
||||
info!("Loaded previous editor_state");
|
||||
ui.canvas.cam_x = state.cam_x;
|
||||
ui.canvas.cam_y = state.cam_y;
|
||||
ui.canvas.cam_zoom = state.cam_zoom;
|
||||
@ -144,7 +144,7 @@ impl UIWrapper {
|
||||
.load_savestate(&state.traffic_signals, &state.stop_signs);
|
||||
}
|
||||
_ => {
|
||||
warn!(target: "UI", "Couldn't load editor_state or it's for a different map, so just centering initial view");
|
||||
warn!("Couldn't load editor_state or it's for a different map, so just centering initial view");
|
||||
ui.canvas.center_on_map_pt(center_pt);
|
||||
}
|
||||
}
|
||||
@ -387,7 +387,7 @@ impl UI {
|
||||
abstutil::write_json("color_scheme", &self.cs).expect("Saving color_scheme failed");
|
||||
abstutil::write_json("road_edits.json", self.road_editor.get_edits())
|
||||
.expect("Saving road_edits.json failed");
|
||||
println!("Saved editor_state, color_scheme, and road_edits.json");
|
||||
info!("Saved editor_state, color_scheme, and road_edits.json");
|
||||
process::exit(0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user