Added support for has_flag in [variant]
Works like in [tile]: for the [variant] to match, the tile that the rule is being applied to must have all of the specified flags.
This commit is contained in:
parent
a87e7e16ed
commit
2f910913f3
3 changed files with 27 additions and 3 deletions
|
@ -30,6 +30,7 @@ Version 1.13.1+dev:
|
|||
option previously found in Preferences -> General.
|
||||
* WML engine:
|
||||
* Added support for mod_x,mod_y= in [terrain_graphics].
|
||||
* Added support for has_flag= in terrain graphics [variant].
|
||||
* Miscellaneous and bug fixes:
|
||||
* Fixed Generate Map dialog bug that caused last choice of map
|
||||
generator to not be actually selected (bug #23711).
|
||||
|
|
|
@ -125,6 +125,21 @@ void terrain_builder::tile::rebuild_cache(const std::string& tod, logs* log)
|
|||
imagelist& img_list = is_background ? images_background : images_foreground;
|
||||
|
||||
BOOST_FOREACH(const rule_image_variant& variant, ri->variants){
|
||||
if(!variant.has_flag.empty()) {
|
||||
bool has_flag_match = true;
|
||||
BOOST_FOREACH(const std::string& s, variant.has_flag) {
|
||||
// If a flag listed in "has_flag" is not present, this variant does not match
|
||||
if(flags.find(s) == flags.end()) {
|
||||
has_flag_match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!has_flag_match) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(!variant.tods.empty() && variant.tods.find(tod) == variant.tods.end())
|
||||
continue;
|
||||
|
||||
|
@ -622,13 +637,17 @@ void terrain_builder::rotate_rule(building_rule &ret, int angle,
|
|||
replace_rotate_tokens(ret, angle, rot);
|
||||
}
|
||||
|
||||
terrain_builder::rule_image_variant::rule_image_variant(const std::string &image_string, const std::string& variations, const std::string& tod, bool random_start) :
|
||||
terrain_builder::rule_image_variant::rule_image_variant(const std::string &image_string, const std::string& variations, const std::string& tod, const std::string& has_flag, bool random_start) :
|
||||
image_string(image_string),
|
||||
variations(variations),
|
||||
images(),
|
||||
tods(),
|
||||
has_flag(),
|
||||
random_start(random_start)
|
||||
{
|
||||
if(!has_flag.empty()) {
|
||||
this->has_flag = utils::split(has_flag);
|
||||
}
|
||||
if(!tod.empty()) {
|
||||
const std::vector<std::string> tod_list = utils::split(tod);
|
||||
tods.insert(tod_list.begin(), tod_list.end());
|
||||
|
@ -667,9 +686,10 @@ void terrain_builder::add_images_from_config(rule_imagelist& images, const confi
|
|||
const std::string &name = variant["name"];
|
||||
const std::string &variations = img["variations"];
|
||||
const std::string &tod = variant["tod"];
|
||||
const std::string &has_flag = variant["has_flag"];
|
||||
bool random_start = variant["random_start"].to_bool(true);
|
||||
|
||||
images.back().variants.push_back(rule_image_variant(name, variations, tod, random_start));
|
||||
images.back().variants.push_back(rule_image_variant(name, variations, tod, has_flag, random_start));
|
||||
}
|
||||
|
||||
// Adds the main (default) variant of the image at the end,
|
||||
|
|
|
@ -155,11 +155,12 @@ public:
|
|||
variations(variations),
|
||||
images(),
|
||||
tods(),
|
||||
has_flag(),
|
||||
random_start(random_start)
|
||||
{}
|
||||
|
||||
/** Constructor for true [variant] cases */
|
||||
rule_image_variant(const std::string &image_string, const std::string& variations, const std::string& tod, bool random_start = true);
|
||||
rule_image_variant(const std::string &image_string, const std::string& variations, const std::string& tod, const std::string& has_flag, bool random_start = true);
|
||||
|
||||
/** A string representing either the filename for an image, or
|
||||
* a list of images, with an optional timing for each image.
|
||||
|
@ -194,6 +195,8 @@ public:
|
|||
/** The Time of Day associated to this variant (if any)*/
|
||||
std::set<std::string> tods;
|
||||
|
||||
std::vector<std::string> has_flag;
|
||||
|
||||
/** Indicate if the animation uses a random shift */
|
||||
bool random_start;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue