Skip to content

Commit 0c8c384

Browse files
committed
time duration reader for recipes
1 parent fb40abe commit 0c8c384

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/recipe.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ bool recipe::has_flag( const std::string &flag_name ) const
155155
return flags.count( flag_name );
156156
}
157157

158+
struct time_duration_as_moves_reader : public generic_typed_reader<time_duration_as_moves_reader> {
159+
int64_t get_next( const JsonValue &jv ) const {
160+
time_duration ret;
161+
jv.read( ret );
162+
return to_moves<int64_t>( ret );
163+
}
164+
};
165+
158166
void recipe::load( const JsonObject &jo, const std::string &src )
159167
{
160168
bool strict = src == "dda";
@@ -226,10 +234,8 @@ void recipe::load( const JsonObject &jo, const std::string &src )
226234
return;
227235
}
228236

229-
if( jo.has_string( "time" ) ) {
230-
time = to_moves<int>( read_from_json_string<time_duration>( jo.get_member( "time" ),
231-
time_duration::units ) );
232-
}
237+
optional( jo, was_loaded, "time", time, time_duration_as_moves_reader{}, 0 );
238+
233239
assign( jo, "difficulty", difficulty, strict, 0, MAX_SKILL );
234240
assign( jo, "flags", flags );
235241

0 commit comments

Comments
 (0)