forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
speed_description.cpp
68 lines (58 loc) · 1.76 KB
/
speed_description.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "speed_description.h"
#include "generic_factory.h"
#include "json.h"
#include "make_static.h"
namespace
{
generic_factory<speed_description> speed_description_factory( "speed_description" );
} // namespace
template<>
const speed_description &speed_description_id::obj() const
{
return speed_description_factory.obj( *this );
}
/** @relates string_id */
template<>
bool speed_description_id::is_valid() const
{
return speed_description_factory.is_valid( *this );
}
void speed_description::load_speed_descriptions( const JsonObject &jo, const std::string &src )
{
speed_description_factory.load( jo, src );
}
void speed_description::reset()
{
speed_description_factory.reset();
}
void speed_description::load( const JsonObject &jo, const std::string & )
{
optional( jo, was_loaded, "values", values_ );
std::sort( values_.begin(), values_.end(),
[]( const speed_description_value & valueA, const speed_description_value & valueB ) {
return valueA.value() > valueB.value();
} );
}
const std::vector<speed_description> &speed_description::get_all()
{
return speed_description_factory.get_all();
}
void speed_description_value::load( const JsonObject &jo )
{
mandatory( jo, was_loaded, "value", value_ );
if( value_ < 0.00 ) {
jo.throw_error( "value outside supported range", "value" );
}
if( jo.has_array( "descriptions" ) ) {
optional( jo, was_loaded, "descriptions", descriptions_ );
} else if( jo.has_string( "descriptions" ) ) {
translation description;
optional( jo, was_loaded, "descriptions", description );
descriptions_.emplace_back( description );
}
}
void speed_description_value::deserialize( JsonIn &jsin )
{
JsonObject data = jsin.get_object();
load( data );
}