@@ -81,19 +81,18 @@ int savegame_loading_version = savegame_version;
81
81
/*
82
82
* Save to opened character.sav
83
83
*/
84
- void game::serialize ( std::ostream &fout )
84
+ void game::serialize_json ( std::ostream &fout )
85
85
{
86
86
/*
87
87
* Format version 12: Fully json, save the header. Weather and memorial exist elsewhere.
88
88
* To prevent (or encourage) confusion, there is no version 8. (cata 0.8 uses v7)
89
89
*/
90
90
// Header
91
- fout << " # version " << savegame_version << std::endl;
92
-
93
91
JsonOut json ( fout, true ); // pretty-print
94
92
95
93
json.start_object ();
96
94
// basic game state information.
95
+ json.member ( " savegame_loading_version" , savegame_version );
97
96
json.member ( " turn" , calendar::turn );
98
97
json.member ( " calendar_start" , calendar::start_of_cataclysm );
99
98
json.member ( " game_start" , calendar::start_of_game );
@@ -203,92 +202,112 @@ static size_t chkversion( std::istream &fin )
203
202
/*
204
203
* Parse an open .sav file.
205
204
*/
205
+
206
206
void game::unserialize ( std::istream &fin, const cata_path &path )
207
207
{
208
- size_t json_file_offset = chkversion ( fin );
208
+ try {
209
+ size_t json_file_offset = chkversion ( fin );
210
+ JsonObject data = json_loader::from_path_at_offset ( path, json_file_offset );
211
+ if ( data.has_member ( " savegame_loading_version" ) ) {
212
+ data.read ( " savegame_loading_version" , savegame_loading_version );
213
+ }
214
+ unserialize_impl ( data );
215
+ } catch ( const JsonError &jsonerr ) {
216
+ debugmsg ( " Bad save json\n %s" , jsonerr.c_str () );
217
+ return ;
218
+ }
219
+ }
220
+
221
+ void game::unserialize ( std::string fin )
222
+ {
223
+ try {
224
+ JsonObject data = json_loader::from_string ( std::move ( fin ) );
225
+ savegame_loading_version = data.get_int ( " savegame_loading_version" );
226
+ unserialize_impl ( data );
227
+ } catch ( const JsonError &jsonerr ) {
228
+ debugmsg ( " Bad save json\n %s" , jsonerr.c_str () );
229
+ return ;
230
+ }
231
+ }
232
+
233
+ void game::unserialize_impl ( const JsonObject &data )
234
+ {
209
235
int tmpturn = 0 ;
210
236
int tmpcalstart = 0 ;
211
237
int tmprun = 0 ;
212
238
tripoint_om_sm lev;
213
239
point_abs_om com;
214
- JsonValue jsin = json_loader::from_path_at_offset ( path, json_file_offset );
215
- try {
216
- JsonObject data = jsin.get_object ();
217
240
218
- data.read ( " turn" , tmpturn );
219
- data.read ( " calendar_start" , tmpcalstart );
220
- calendar::initial_season = static_cast <season_type>( data.get_int ( " initial_season" ,
221
- static_cast <int >( SPRING ) ) );
222
-
223
- data.read ( " auto_travel_mode" , auto_travel_mode );
224
- data.read ( " run_mode" , tmprun );
225
- data.read ( " mostseen" , mostseen );
226
- data.read ( " levx" , lev.x () );
227
- data.read ( " levy" , lev.y () );
228
- data.read ( " levz" , lev.z () );
229
- data.read ( " om_x" , com.x () );
230
- data.read ( " om_y" , com.y () );
231
-
232
- data.read ( " view_offset_x" , u.view_offset .x () );
233
- data.read ( " view_offset_y" , u.view_offset .y () );
234
- data.read ( " view_offset_z" , u.view_offset .z () );
235
-
236
- calendar::turn = time_point ( tmpturn );
237
- calendar::start_of_cataclysm = time_point ( tmpcalstart );
238
-
239
- if ( !data.read ( " game_start" , calendar::start_of_game ) ) {
240
- calendar::start_of_game = calendar::start_of_cataclysm;
241
- }
242
-
243
- load_map ( project_combine ( com, lev ), /* pump_events=*/ true );
241
+ data.read ( " turn" , tmpturn );
242
+ data.read ( " calendar_start" , tmpcalstart );
243
+ calendar::initial_season = static_cast <season_type>( data.get_int ( " initial_season" ,
244
+ static_cast <int >( SPRING ) ) );
245
+
246
+ data.read ( " auto_travel_mode" , auto_travel_mode );
247
+ data.read ( " run_mode" , tmprun );
248
+ data.read ( " mostseen" , mostseen );
249
+ data.read ( " levx" , lev.x () );
250
+ data.read ( " levy" , lev.y () );
251
+ data.read ( " levz" , lev.z () );
252
+ data.read ( " om_x" , com.x () );
253
+ data.read ( " om_y" , com.y () );
254
+
255
+ data.read ( " view_offset_x" , u.view_offset .x () );
256
+ data.read ( " view_offset_y" , u.view_offset .y () );
257
+ data.read ( " view_offset_z" , u.view_offset .z () );
258
+
259
+ calendar::turn = time_point ( tmpturn );
260
+ calendar::start_of_cataclysm = time_point ( tmpcalstart );
261
+
262
+ if ( !data.read ( " game_start" , calendar::start_of_game ) ) {
263
+ calendar::start_of_game = calendar::start_of_cataclysm;
264
+ }
244
265
245
- safe_mode = static_cast <safe_mode_type>( tmprun );
246
- if ( get_option<bool >( " SAFEMODE" ) && safe_mode == SAFE_MODE_OFF ) {
247
- safe_mode = SAFE_MODE_ON;
248
- }
266
+ load_map ( project_combine ( com, lev ), /* pump_events=*/ true );
249
267
250
- std::string linebuff;
251
- std::string linebuf;
252
- if ( data.read ( " grscent" , linebuf ) && data.read ( " typescent" , linebuff ) ) {
253
- scent.deserialize ( linebuf );
254
- scent.deserialize ( linebuff, true );
255
- } else {
256
- scent.reset ();
257
- }
258
- data.read ( " active_monsters" , *critter_tracker );
259
-
260
- data.has_null ( " stair_monsters" ); // TEMPORARY until 0.G
261
- data.has_null ( " monstairz" ); // TEMPORARY until 0.G
262
-
263
- data.read ( " driving_view_offset" , driving_view_offset );
264
- data.read ( " turnssincelastmon" , turnssincelastmon );
265
- data.read ( " bVMonsterLookFire" , bVMonsterLookFire );
266
-
267
- data.read ( " kill_tracker" , *kill_tracker_ptr );
268
-
269
- data.read ( " player" , u );
270
- data.read ( " inactive_global_effect_on_condition_vector" ,
271
- inactive_global_effect_on_condition_vector );
272
- // load queued_eocs
273
- for ( JsonObject elem : data.get_array ( " queued_global_effect_on_conditions" ) ) {
274
- queued_eoc temp;
275
- temp.time = time_point ( elem.get_int ( " time" ) );
276
- temp.eoc = effect_on_condition_id ( elem.get_string ( " eoc" ) );
277
- elem.read ( " context" , temp.context );
278
- queued_global_effect_on_conditions.push ( temp );
279
- }
280
- global_variables_instance.unserialize ( data );
281
- data.read ( " unique_npcs" , unique_npcs );
282
- inp_mngr.pump_events ();
283
- data.read ( " stats_tracker" , *stats_tracker_ptr );
284
- data.read ( " achievements_tracker" , *achievements_tracker_ptr );
285
- inp_mngr.pump_events ();
286
- Messages::deserialize ( data );
268
+ safe_mode = static_cast <safe_mode_type>( tmprun );
269
+ if ( get_option<bool >( " SAFEMODE" ) && safe_mode == SAFE_MODE_OFF ) {
270
+ safe_mode = SAFE_MODE_ON;
271
+ }
287
272
288
- } catch ( const JsonError &jsonerr ) {
289
- debugmsg ( " Bad save json\n %s" , jsonerr.c_str () );
290
- return ;
273
+ std::string linebuff;
274
+ std::string linebuf;
275
+ if ( data.read ( " grscent" , linebuf ) && data.read ( " typescent" , linebuff ) ) {
276
+ scent.deserialize ( linebuf );
277
+ scent.deserialize ( linebuff, true );
278
+ } else {
279
+ scent.reset ();
291
280
}
281
+ data.read ( " active_monsters" , *critter_tracker );
282
+
283
+ data.has_null ( " stair_monsters" ); // TEMPORARY until 0.G
284
+ data.has_null ( " monstairz" ); // TEMPORARY until 0.G
285
+
286
+ data.read ( " driving_view_offset" , driving_view_offset );
287
+ data.read ( " turnssincelastmon" , turnssincelastmon );
288
+ data.read ( " bVMonsterLookFire" , bVMonsterLookFire );
289
+
290
+ data.read ( " kill_tracker" , *kill_tracker_ptr );
291
+
292
+ data.read ( " player" , u );
293
+ data.read ( " inactive_global_effect_on_condition_vector" ,
294
+ inactive_global_effect_on_condition_vector );
295
+ // load queued_eocs
296
+ for ( JsonObject elem : data.get_array ( " queued_global_effect_on_conditions" ) ) {
297
+ queued_eoc temp;
298
+ temp.time = time_point ( elem.get_int ( " time" ) );
299
+ temp.eoc = effect_on_condition_id ( elem.get_string ( " eoc" ) );
300
+ elem.read ( " context" , temp.context );
301
+ queued_global_effect_on_conditions.push ( temp );
302
+ }
303
+ global_variables_instance.unserialize ( data );
304
+ data.read ( " unique_npcs" , unique_npcs );
305
+ inp_mngr.pump_events ();
306
+ data.read ( " stats_tracker" , *stats_tracker_ptr );
307
+ data.read ( " achievements_tracker" , *achievements_tracker_ptr );
308
+ inp_mngr.pump_events ();
309
+ Messages::deserialize ( data );
310
+
292
311
}
293
312
294
313
void scent_map::deserialize ( const std::string &data, bool is_type )
@@ -1587,7 +1606,7 @@ void weather_manager::unserialize_all( const JsonObject &w )
1587
1606
}
1588
1607
}
1589
1608
1590
- void global_variables::unserialize ( JsonObject &jo )
1609
+ void global_variables::unserialize ( const JsonObject &jo )
1591
1610
{
1592
1611
// global variables
1593
1612
jo.read ( " global_vals" , global_values );
0 commit comments