mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-01 01:50:03 +00:00
Variadic config methods to combine remove_attribute or clear_children calls
This commit is contained in:
parent
38010fd991
commit
ff3e1bf83a
@ -1786,12 +1786,11 @@ recruitment_aspect::recruitment_aspect(readonly_context &context, const config &
|
||||
parsed_cfg["pattern"] = true;
|
||||
parsed_cfg.add_child("recruit", pattern);
|
||||
}
|
||||
parsed_cfg.clear_children("pattern");
|
||||
for (config total : parsed_cfg.child_range("total")) {
|
||||
parsed_cfg["total"] = true;
|
||||
parsed_cfg.add_child("recruit", total);
|
||||
}
|
||||
parsed_cfg.clear_children("total");
|
||||
parsed_cfg.clear_children("pattern", "total");
|
||||
// Then, if there's no [recruit], add one.
|
||||
if (!parsed_cfg.has_child("recruit")) {
|
||||
parsed_cfg.add_child("recruit", config_of("importance", 0));
|
||||
|
@ -34,11 +34,7 @@ carryover::carryover(const config& side)
|
||||
for(const config& u : side.child_range("unit")) {
|
||||
recall_list_.push_back(u);
|
||||
config& u_back = recall_list_.back();
|
||||
u_back.remove_attribute("side");
|
||||
u_back.remove_attribute("goto_x");
|
||||
u_back.remove_attribute("goto_y");
|
||||
u_back.remove_attribute("x");
|
||||
u_back.remove_attribute("y");
|
||||
u_back.remove_attributes("side", "goto_x", "goto_y", "x", "y");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -450,7 +450,9 @@ public:
|
||||
template<int N>
|
||||
config &child(const char(&key)[N], int n = 0)
|
||||
{ return child_impl(key, N - 1, n); }
|
||||
private:
|
||||
config &child_impl(const char* key, int len, int n = 0);
|
||||
public:
|
||||
#endif
|
||||
/**
|
||||
* Returns the nth child with the given @a key, or
|
||||
@ -564,6 +566,12 @@ public:
|
||||
|
||||
void remove_attribute(const std::string &key);
|
||||
void merge_attributes(const config &);
|
||||
template<typename... T>
|
||||
void remove_attributes(T... keys) {
|
||||
for(const std::string& key : {keys...}) {
|
||||
remove_attribute(key);
|
||||
}
|
||||
}
|
||||
|
||||
const_attr_itors attribute_range() const;
|
||||
|
||||
@ -579,6 +587,12 @@ public:
|
||||
{ return const_cast<config *>(this)->find_child(key, name, value); }
|
||||
|
||||
void clear_children(const std::string& key);
|
||||
template<typename... T>
|
||||
void clear_children(T... keys) {
|
||||
for(std::string key : {keys...}) {
|
||||
clear_children(key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves all the children with tag @a key from @a src to this.
|
||||
@ -660,7 +674,7 @@ public:
|
||||
* A function to get the differences between this object,
|
||||
* and 'c', as another config object.
|
||||
* I.e. calling cfg2.apply_diff(cfg1.get_diff(cfg2))
|
||||
* will make cfg1 identical to cfg2.
|
||||
* will make cfg2 identical to cfg1.
|
||||
*/
|
||||
config get_diff(const config& c) const;
|
||||
void get_diff(const config& c, config& res) const;
|
||||
|
@ -988,11 +988,7 @@ config side_engine::new_config() const
|
||||
// Merge the faction data to res.
|
||||
config faction = flg_.current_faction();
|
||||
res["faction_name"] = faction["name"];
|
||||
faction.remove_attribute("id");
|
||||
faction.remove_attribute("name");
|
||||
faction.remove_attribute("image");
|
||||
faction.remove_attribute("gender");
|
||||
faction.remove_attribute("type");
|
||||
faction.remove_attributes("id", "name", "image", "gender", "type");
|
||||
res.append(faction);
|
||||
}
|
||||
|
||||
|
@ -563,8 +563,7 @@ public:
|
||||
config c = resources::teams
|
||||
? resources::teams->at(side_ - 1).to_config()
|
||||
: config();
|
||||
c.clear_children("ai");
|
||||
c.clear_children("village");
|
||||
c.clear_children("ai", "village");
|
||||
model_.set_inspect_window_text(config_to_string(c));
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user