mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 01:15:12 +03:00
Add an explicit version number to the edits schema
This commit is contained in:
parent
8a05a88f0c
commit
ca8af784c7
@ -1,6 +1,7 @@
|
||||
{
|
||||
"map_name": "downtown",
|
||||
"edits_name": "cap hill superblock",
|
||||
"version": 0,
|
||||
"commands": [
|
||||
{
|
||||
"ChangeLaneType": {
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"map_name": "west_seattle",
|
||||
"edits_name": "repair west seattle bridge",
|
||||
"version": 0,
|
||||
"commands": [
|
||||
{
|
||||
"ChangeLaneType": {
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"map_name": "udistrict",
|
||||
"edits_name": "simplify where Corliss, Pacific, and the Burke cross",
|
||||
"version": 0,
|
||||
"commands": [
|
||||
{
|
||||
"ChangeLaneType": {
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"map_name": "lakeslice",
|
||||
"edits_name": "stay healthy lake wash blvd",
|
||||
"version": 0,
|
||||
"commands": [
|
||||
{
|
||||
"ChangeLaneType": {
|
||||
|
@ -31,7 +31,7 @@ use ezgui::{
|
||||
Widget,
|
||||
};
|
||||
use geom::Speed;
|
||||
use map_model::{EditCmd, IntersectionID, LaneID, LaneType, MapEdits, PermanentMapEdits};
|
||||
use map_model::{EditCmd, IntersectionID, LaneID, LaneType, MapEdits};
|
||||
use maplit::btreeset;
|
||||
use sim::DontDrawAgents;
|
||||
use std::collections::BTreeSet;
|
||||
@ -414,15 +414,10 @@ impl LoadEdits {
|
||||
// common use case.
|
||||
let mut proposals = vec![Line("Community proposals").small_heading().draw(ctx)];
|
||||
// Up-front filter out proposals that definitely don't fit the current map
|
||||
for (name, perma) in
|
||||
abstutil::load_all_objects::<PermanentMapEdits>(abstutil::path("system/proposals"))
|
||||
{
|
||||
if PermanentMapEdits::from_permanent(perma, &app.primary.map).is_ok() {
|
||||
proposals.push(Btn::text_fg(&name).build(
|
||||
ctx,
|
||||
abstutil::path(format!("system/proposals/{}.json", name)),
|
||||
None,
|
||||
));
|
||||
for name in abstutil::list_all_objects(abstutil::path("system/proposals")) {
|
||||
let path = abstutil::path(format!("system/proposals/{}.json", name));
|
||||
if MapEdits::load(&app.primary.map, path.clone(), &mut Timer::throwaway()).is_ok() {
|
||||
proposals.push(Btn::text_fg(&name).build(ctx, path, None));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,10 +9,19 @@ use serde_json::Value;
|
||||
// example, protobufs wouldn't have helped with the fix_intersection_ids problem. Explicit
|
||||
// transformation is easier!
|
||||
pub fn upgrade(mut value: Value) -> Result<PermanentMapEdits, String> {
|
||||
// I don't remember the previous schema change before this. If someone files a bug and has an
|
||||
// older file, can add support for it then.
|
||||
fix_offset(&mut value);
|
||||
fix_intersection_ids(&mut value);
|
||||
// c46a74f10f4f1976a48aa8642ac11717d74b262c added an explicit version field. There are a few
|
||||
// changes before that.
|
||||
if value.get("version").is_none() {
|
||||
// I don't remember the previous schema change before this. If someone files a bug and has
|
||||
// an older file, can add support for it then.
|
||||
fix_offset(&mut value);
|
||||
fix_intersection_ids(&mut value);
|
||||
|
||||
value
|
||||
.as_object_mut()
|
||||
.unwrap()
|
||||
.insert("version".to_string(), Value::Number(0.into()));
|
||||
}
|
||||
|
||||
abstutil::from_json(&value.to_string().into_bytes()).map_err(|x| x.to_string())
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ use std::collections::{BTreeMap, BTreeSet};
|
||||
pub struct PermanentMapEdits {
|
||||
pub map_name: String,
|
||||
pub edits_name: String,
|
||||
pub version: usize,
|
||||
commands: Vec<PermanentEditCmd>,
|
||||
|
||||
// Edits without these are player generated.
|
||||
@ -82,6 +83,8 @@ impl PermanentMapEdits {
|
||||
PermanentMapEdits {
|
||||
map_name: map.get_name().to_string(),
|
||||
edits_name: edits.edits_name.clone(),
|
||||
// Increase this every time there's a schema change
|
||||
version: 0,
|
||||
proposal_description: edits.proposal_description.clone(),
|
||||
proposal_link: edits.proposal_link.clone(),
|
||||
commands: edits
|
||||
|
Loading…
Reference in New Issue
Block a user