Skip to content

Commit

Permalink
Migrate existing convertibles to generic foldables
Browse files Browse the repository at this point in the history
  • Loading branch information
irwiss committed Jul 24, 2022
1 parent 4abdbc8 commit c7c50d0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
12 changes: 12 additions & 0 deletions data/json/vehicles/bikes.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@
{ "x": -1, "y": 0, "parts": [ "small_storage_battery", "engine_electric_tiny" ] }
]
},
{
"id": "bicycle_folding",
"type": "vehicle",
"name": "Folding Bicycle",
"blueprint": [ "o#o" ],
"parts": [
{ "x": 0, "y": 0, "parts": [ "folding_frame", "saddle_pedal", "horn_bicycle", "foot_pedals" ] },
{ "x": 1, "y": 0, "parts": [ "folding_frame", "wheel_mount_light_steerable", "wheel_bicycle" ] },
{ "x": -1, "y": 0, "parts": [ "folding_frame", "wheel_mount_light" ] },
{ "x": -1, "y": 0, "parts": [ "wheel_bicycle_rear", "basketsm_bike_rear" ] }
]
},
{
"id": "motorcycle_cross",
"type": "vehicle",
Expand Down
25 changes: 23 additions & 2 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3476,13 +3476,34 @@ void vehicle::deserialize( const JsonObject &data )
}
}

refresh();

data.read( "tags", tags );
data.read( "fuel_remainder", fuel_remainder );
data.read( "fuel_used_last_turn", fuel_used_last_turn );
data.read( "labels", labels );

// TODO: Remove after 0.G
// migrate old "convertible" vehicles to new generic "folding" ones
if( has_tag( "convertible" ) ) {
// remove tags starting from "convertible"
for( auto it = tags.begin(); it != tags.end(); ) {
if( it->rfind( "convertible", 0 ) == 0 ) {
it = tags.erase( it );
} else {
++it;
}
}

// only convertible bicycles need to have parts replaced with folding ones, other
// in-tree "convertibles" (wheelchair, inflatable boat) can just have their tags
// removed as their parts are foldable already
if( type == vproto_id( "bicycle" ) ) {
type = vproto_id( "bicycle_folding" );
parts = type.obj().blueprint->parts;
}
}

refresh();

point p;
zone_data zd;
for( JsonObject sdata : data.get_array( "zones" ) ) {
Expand Down

0 comments on commit c7c50d0

Please sign in to comment.