From d26100734623f37063206b9b144c2a29fd71d414 Mon Sep 17 00:00:00 2001 From: quou Date: Wed, 1 Jan 2025 18:43:31 +1100 Subject: material system --- cfg/cfgparse.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) (limited to 'cfg/cfgparse.c') diff --git a/cfg/cfgparse.c b/cfg/cfgparse.c index 4dc6dbb..9ac8ec7 100644 --- a/cfg/cfgparse.c +++ b/cfg/cfgparse.c @@ -74,9 +74,18 @@ static void fill_prop_number( const char* start, int len ) { - (void)len; - p->type = cfg_type_int; - p->as.num = (int)strtol(start, 0, 10); + int is_f = 0; + int i; + for (i = 0; i < len; i++) + if (start[i] == '.') + is_f = 1; + if (is_f) { + p->type = cfg_type_float; + p->as.num = (float)strtod(start, 0); + } else { + p->type = cfg_type_int; + p->as.num = (int)strtol(start, 0, 10); + } } static void fill_prop_data( @@ -222,6 +231,36 @@ int find_int_default( return def; } +float find_float_default( + const cfg_Object* obj, + const char* name, + float def +) { + const cfg_Prop* prop; + prop = find_prop_of(obj, name, cfg_type_float); + if (prop) { + return prop->as.flt; + } + return def; +} + +float find_num_default( + const cfg_Object* obj, + const char* name, + float def +) { + const cfg_Prop* prop; + prop = find_prop_of(obj, name, cfg_type_float); + if (prop) { + return prop->as.flt; + } + prop = find_prop_of(obj, name, cfg_type_int); + if (prop) { + return prop->as.num; + } + return def; +} + const char* find_string_default( const cfg_Object* obj, const char* name, @@ -234,3 +273,12 @@ const char* find_string_default( } return def; } + +unsigned find_colour_default( + const cfg_Object* obj, + const char* name, + const char* def +) { + const char* s = find_string_default(obj, name, def); + return (unsigned)strtol(s, 0, 16); +} -- cgit v1.2.3-54-g00ecf