Add an explicit version number to the edits schema

This commit is contained in:
Dustin Carlino 2020-08-22 11:14:13 -07:00
parent 8a05a88f0c
commit ca8af784c7
7 changed files with 25 additions and 14 deletions

View File

@ -1,6 +1,7 @@
{ {
"map_name": "downtown", "map_name": "downtown",
"edits_name": "cap hill superblock", "edits_name": "cap hill superblock",
"version": 0,
"commands": [ "commands": [
{ {
"ChangeLaneType": { "ChangeLaneType": {

View File

@ -1,6 +1,7 @@
{ {
"map_name": "west_seattle", "map_name": "west_seattle",
"edits_name": "repair west seattle bridge", "edits_name": "repair west seattle bridge",
"version": 0,
"commands": [ "commands": [
{ {
"ChangeLaneType": { "ChangeLaneType": {

View File

@ -1,6 +1,7 @@
{ {
"map_name": "udistrict", "map_name": "udistrict",
"edits_name": "simplify where Corliss, Pacific, and the Burke cross", "edits_name": "simplify where Corliss, Pacific, and the Burke cross",
"version": 0,
"commands": [ "commands": [
{ {
"ChangeLaneType": { "ChangeLaneType": {

View File

@ -1,6 +1,7 @@
{ {
"map_name": "lakeslice", "map_name": "lakeslice",
"edits_name": "stay healthy lake wash blvd", "edits_name": "stay healthy lake wash blvd",
"version": 0,
"commands": [ "commands": [
{ {
"ChangeLaneType": { "ChangeLaneType": {

View File

@ -31,7 +31,7 @@ use ezgui::{
Widget, Widget,
}; };
use geom::Speed; use geom::Speed;
use map_model::{EditCmd, IntersectionID, LaneID, LaneType, MapEdits, PermanentMapEdits}; use map_model::{EditCmd, IntersectionID, LaneID, LaneType, MapEdits};
use maplit::btreeset; use maplit::btreeset;
use sim::DontDrawAgents; use sim::DontDrawAgents;
use std::collections::BTreeSet; use std::collections::BTreeSet;
@ -414,15 +414,10 @@ impl LoadEdits {
// common use case. // common use case.
let mut proposals = vec![Line("Community proposals").small_heading().draw(ctx)]; let mut proposals = vec![Line("Community proposals").small_heading().draw(ctx)];
// Up-front filter out proposals that definitely don't fit the current map // Up-front filter out proposals that definitely don't fit the current map
for (name, perma) in for name in abstutil::list_all_objects(abstutil::path("system/proposals")) {
abstutil::load_all_objects::<PermanentMapEdits>(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() {
if PermanentMapEdits::from_permanent(perma, &app.primary.map).is_ok() { proposals.push(Btn::text_fg(&name).build(ctx, path, None));
proposals.push(Btn::text_fg(&name).build(
ctx,
abstutil::path(format!("system/proposals/{}.json", name)),
None,
));
} }
} }

View File

@ -9,11 +9,20 @@ use serde_json::Value;
// example, protobufs wouldn't have helped with the fix_intersection_ids problem. Explicit // example, protobufs wouldn't have helped with the fix_intersection_ids problem. Explicit
// transformation is easier! // transformation is easier!
pub fn upgrade(mut value: Value) -> Result<PermanentMapEdits, String> { 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 // c46a74f10f4f1976a48aa8642ac11717d74b262c added an explicit version field. There are a few
// older file, can add support for it then. // 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_offset(&mut value);
fix_intersection_ids(&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()) abstutil::from_json(&value.to_string().into_bytes()).map_err(|x| x.to_string())
} }

View File

@ -12,6 +12,7 @@ use std::collections::{BTreeMap, BTreeSet};
pub struct PermanentMapEdits { pub struct PermanentMapEdits {
pub map_name: String, pub map_name: String,
pub edits_name: String, pub edits_name: String,
pub version: usize,
commands: Vec<PermanentEditCmd>, commands: Vec<PermanentEditCmd>,
// Edits without these are player generated. // Edits without these are player generated.
@ -82,6 +83,8 @@ impl PermanentMapEdits {
PermanentMapEdits { PermanentMapEdits {
map_name: map.get_name().to_string(), map_name: map.get_name().to_string(),
edits_name: edits.edits_name.clone(), edits_name: edits.edits_name.clone(),
// Increase this every time there's a schema change
version: 0,
proposal_description: edits.proposal_description.clone(), proposal_description: edits.proposal_description.clone(),
proposal_link: edits.proposal_link.clone(), proposal_link: edits.proposal_link.clone(),
commands: edits commands: edits