Skip to content

Commit 3e1142b

Browse files
committed
remove assign
1 parent b4627d1 commit 3e1142b

File tree

4 files changed

+31
-23
lines changed

4 files changed

+31
-23
lines changed

src/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ void DynamicDataLoader::initialize()
335335
} );
336336

337337
add( "vehicle_part", &vehicles::parts::load );
338-
add( "vehicle_part_category", &vpart_category::load );
338+
add( "vehicle_part_category", &vpart_category::load_all );
339339
add( "vehicle_part_migration", &vpart_migration::load );
340340
add( "vehicle", &vehicles::load_prototype );
341341
add( "vehicle_group", &VehicleGroup::load );
@@ -779,7 +779,7 @@ void DynamicDataLoader::finalize_loaded_data()
779779
requirement_data::finalize();
780780
}
781781
},
782-
{ _( "Vehicle part categories" ), &vpart_category::finalize },
782+
{ _( "Vehicle part categories" ), &vpart_category::finalize_all },
783783
{ _( "Vehicle parts" ), &vehicles::parts::finalize },
784784
{ _( "Traps" ), &trap::finalize_all },
785785
{ _( "Terrain" ), &set_ter_ids },

src/units.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ void temperature::deserialize( const JsonValue &jv )
7979
*this = from_kelvin( std::stof( jv.get_string() ) );
8080
}
8181

82+
template<>
83+
void temperature_delta::deserialize( const JsonValue &jv )
84+
{
85+
if( jv.test_int() ) {
86+
*this = from_legacy_bodypart_temp_delta( jv.get_int() );
87+
} else {
88+
// super gross
89+
*this = from_kelvin_delta( std::stof( jv.get_string() ) );
90+
}
91+
}
92+
8293
template<>
8394
void energy::serialize( JsonOut &jsout ) const
8495
{

src/veh_type.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <unordered_set>
1313

1414
#include "ammo.h"
15-
#include "assign.h"
1615
#include "cata_assert.h"
1716
#include "catacharset.h"
1817
#include "character.h"
@@ -240,10 +239,8 @@ void vpart_info::handle_inheritance( const vpart_info &copy_from,
240239
}
241240
}
242241

243-
void vpart_info::load( const JsonObject &jo, const std::string &src )
242+
void vpart_info::load( const JsonObject &jo, const std::string_view src )
244243
{
245-
const bool strict = src == "dda";
246-
247244
optional( jo, was_loaded, "name", name_ );
248245
optional( jo, was_loaded, "item", base_item );
249246
optional( jo, was_loaded, "remove_as", removed_item );
@@ -267,12 +264,8 @@ void vpart_info::load( const JsonObject &jo, const std::string &src )
267264
optional( jo, was_loaded, "color", color, nc_color_reader{}, c_light_gray );
268265
optional( jo, was_loaded, "broken_color", color_broken, nc_color_reader{}, c_light_gray );
269266
optional( jo, was_loaded, "comfort", comfort, 0 );
270-
int legacy_floor_bedding_warmth = units::to_legacy_bodypart_temp_delta( floor_bedding_warmth );
271-
assign( jo, "floor_bedding_warmth", legacy_floor_bedding_warmth, strict );
272-
floor_bedding_warmth = units::from_legacy_bodypart_temp_delta( legacy_floor_bedding_warmth );
273-
int legacy_bonus_fire_warmth_feet = units::to_legacy_bodypart_temp_delta( bonus_fire_warmth_feet );
274-
assign( jo, "bonus_fire_warmth_feet", legacy_bonus_fire_warmth_feet, strict );
275-
bonus_fire_warmth_feet = units::from_legacy_bodypart_temp_delta( legacy_bonus_fire_warmth_feet );
267+
optional( jo, was_loaded, "floor_bedding_warmth", floor_bedding_warmth, 0_C_delta );
268+
optional( jo, was_loaded, "bonus_fire_warmth_feet", bonus_fire_warmth_feet, 0.6_C_delta );
276269

277270
int enchant_num = 0;
278271
for( JsonValue jv : jo.get_array( "enchantments" ) ) {
@@ -1687,19 +1680,22 @@ const std::vector<vpart_category> &vpart_category::all()
16871680
return vpart_categories_all;
16881681
}
16891682

1690-
void vpart_category::load( const JsonObject &jo )
1683+
void vpart_category::load_all( const JsonObject &jo )
16911684
{
16921685
vpart_category def;
1693-
1694-
assign( jo, "id", def.id_ );
1695-
assign( jo, "name", def.name_ );
1696-
assign( jo, "short_name", def.short_name_ );
1697-
assign( jo, "priority", def.priority_ );
1698-
1686+
def.load( jo );
16991687
vpart_categories_all.push_back( def );
17001688
}
17011689

1702-
void vpart_category::finalize()
1690+
void vpart_category::load( const JsonObject &jo )
1691+
{
1692+
mandatory( jo, false, "id", id_ );
1693+
mandatory( jo, false, "name", name_ );
1694+
mandatory( jo, false, "short_name", short_name_ );
1695+
mandatory( jo, false, "priority", priority_ );
1696+
}
1697+
1698+
void vpart_category::finalize_all()
17031699
{
17041700
std::sort( vpart_categories_all.begin(), vpart_categories_all.end() );
17051701
}

src/veh_type.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,9 @@ class vpart_category
210210
public:
211211
static const std::vector<vpart_category> &all();
212212

213-
static void load( const JsonObject &jo );
214-
static void finalize();
213+
static void load_all( const JsonObject &jo );
214+
static void finalize_all();
215+
void load( const JsonObject &jo );
215216
static void reset();
216217

217218
std::string get_id() const {
@@ -272,7 +273,7 @@ class vpart_info
272273
public:
273274
vpart_id id;
274275

275-
void load( const JsonObject &jo, const std::string &src );
276+
void load( const JsonObject &jo, std::string_view src );
276277
void check() const;
277278
void finalize();
278279
void handle_inheritance( const vpart_info &copy_from,

0 commit comments

Comments
 (0)