Skip to content

Commit

Permalink
add 'default_'attribute option for if 'value' or other is empty, chec…
Browse files Browse the repository at this point in the history
…k value by defautof abilities.

this option can be used when check value of drain where value by default is 25 and not ever specified
  • Loading branch information
newfrenchy83 committed Sep 29, 2023
1 parent 9698a7e commit 43c5a6a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
5 changes: 5 additions & 0 deletions data/schema/filters/abilities.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
{SIMPLE_KEY apply_to string_list}
{SIMPLE_KEY active_on string_list}
{SIMPLE_KEY value s_int_range_list}
{SIMPLE_KEY default_value s_int}
{SIMPLE_KEY add s_int_range_list}
{SIMPLE_KEY default_add s_int}
{SIMPLE_KEY sub s_int_range_list}
{SIMPLE_KEY default_sub s_int}
{SIMPLE_KEY multiply s_real_range_list}
{SIMPLE_KEY default_multiply s_real}
{SIMPLE_KEY divide s_real_range_list}
{SIMPLE_KEY default_divide s_real}
{SIMPLE_KEY affect_adjacent s_bool}
{SIMPLE_KEY affect_self s_bool}
{SIMPLE_KEY affect_allies s_bool}
Expand Down
24 changes: 15 additions & 9 deletions src/utils/config_filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ bool utils::config_filters::unsigned_matches_if_present(const config& filter, co
return true;
}

if(cfg[attribute].empty()) {
if(cfg[attribute].empty() && filter["default_" + attribute].empty()) {
return false;
}
return in_ranges<int>(cfg[attribute].to_int(0), utils::parse_ranges_unsigned(filter[attribute].str()));
int def = filter["default_" + attribute].to_int(0);

return in_ranges<int>(cfg[attribute].to_int(def), utils::parse_ranges_unsigned(filter[attribute].str()));
}

bool utils::config_filters::int_matches_if_present(const config& filter, const config& cfg, const std::string& attribute)
Expand All @@ -59,27 +61,30 @@ bool utils::config_filters::int_matches_if_present(const config& filter, const c
return true;
}

if(cfg[attribute].empty()) {
if(cfg[attribute].empty() && filter["default_" + attribute].empty()) {
return false;
}
int def = filter["default_" + attribute].to_int(0);

return in_ranges<int>(cfg[attribute].to_int(0), utils::parse_ranges_int(filter[attribute].str()));
return in_ranges<int>(cfg[attribute].to_int(def), utils::parse_ranges_int(filter[attribute].str()));
}

bool utils::config_filters::int_matches_if_present_or_negative(
const config& filter, const config& cfg, const std::string& attribute, const std::string& opposite)
{
if(filter[attribute].empty() || in_ranges<int>(cfg[attribute].to_int(0), utils::parse_ranges_int(filter[attribute].str()))) {
if(int_matches_if_present(filter, cfg, attribute)) {
return true;
}

// 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["default_" + opposite].empty()) {
return false;
}
return in_ranges<int>(-cfg[opposite].to_int(0), utils::parse_ranges_int(filter[attribute].str()));
int def = filter["default_" + opposite].to_int(0);

return in_ranges<int>(-cfg[opposite].to_int(def), utils::parse_ranges_int(filter[attribute].str()));
}

return false;
Expand All @@ -91,9 +96,10 @@ bool utils::config_filters::double_matches_if_present(const config& filter, cons
return true;
}

if(cfg[attribute].empty()) {
if(cfg[attribute].empty() && filter["default_" + attribute].empty()) {
return false;
}
double def = filter["default_" + attribute].to_double(1);

return in_ranges<double>(cfg[attribute].to_double(1), utils::parse_ranges_real(filter[attribute].str()));
return in_ranges<double>(cfg[attribute].to_double(def), utils::parse_ranges_real(filter[attribute].str()));
}

0 comments on commit 43c5a6a

Please sign in to comment.