From 414e713be988b9e00a22842861317500fccabfb3 Mon Sep 17 00:00:00 2001 From: newfrenchy83 Date: Fri, 29 Sep 2023 17:32:42 +0200 Subject: [PATCH] add 'has_default_value' option for if 'value' or other is empty, considered like null by default. this option is false by default in filter. --- data/schema/filters/abilities.cfg | 1 + src/utils/config_filters.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/data/schema/filters/abilities.cfg b/data/schema/filters/abilities.cfg index b6071b5711abe..7ee0f00dbcd34 100644 --- a/data/schema/filters/abilities.cfg +++ b/data/schema/filters/abilities.cfg @@ -10,6 +10,7 @@ {SIMPLE_KEY value s_int_range_list} {SIMPLE_KEY add s_int_range_list} {SIMPLE_KEY sub s_int_range_list} + {SIMPLE_KEY has_default_value s_bool} {SIMPLE_KEY multiply s_real_range_list} {SIMPLE_KEY divide s_real_range_list} {SIMPLE_KEY affect_adjacent s_bool} diff --git a/src/utils/config_filters.cpp b/src/utils/config_filters.cpp index c24ee384e1b06..0fd1ace05a608 100644 --- a/src/utils/config_filters.cpp +++ b/src/utils/config_filters.cpp @@ -47,7 +47,7 @@ bool utils::config_filters::unsigned_matches_if_present(const config& filter, co return true; } - if(cfg[attribute].empty()) { + if(cfg[attribute].empty() && filter["has_default_value"].to_bool(false)) { return false; } return in_ranges(cfg[attribute].to_int(0), utils::parse_ranges_unsigned(filter[attribute].str())); @@ -59,7 +59,7 @@ bool utils::config_filters::int_matches_if_present(const config& filter, const c return true; } - if(cfg[attribute].empty()) { + if(cfg[attribute].empty() && filter["has_default_value"].to_bool(false)) { return false; } @@ -76,7 +76,7 @@ bool utils::config_filters::int_matches_if_present_or_negative( // don't check for !cfg[opposite].empty(), as this assumes a default value of zero (similarly to // int_matches_if_present) if(cfg[attribute].empty()) { - if(cfg[opposite].empty()) { + if(cfg[opposite].empty() && filter["has_default_value"].to_bool(false)) { return false; } return in_ranges(-cfg[opposite].to_int(0), utils::parse_ranges_int(filter[attribute].str())); @@ -91,7 +91,7 @@ bool utils::config_filters::double_matches_if_present(const config& filter, cons return true; } - if(cfg[attribute].empty()) { + if(cfg[attribute].empty() && filter["has_default_value"].to_bool(false)) { return false; }