Revert "remove support for legacy-style unit abilities descriptions"
This reverts commit 2656a5d070
.
Removing features or compatibility paths is not allowed in stable
branches unless required to solve a security vulnerability or other
severe issue.
This commit is contained in:
parent
002c00b063
commit
343d05caa2
3 changed files with 56 additions and 6 deletions
|
@ -258,7 +258,7 @@ std::vector<boost::tuple<t_string,t_string,t_string> > unit::ability_tooltips(st
|
|||
res.push_back(boost::make_tuple(
|
||||
ab.cfg["name"].t_str(),
|
||||
name,
|
||||
ab.cfg["description"].t_str() ));
|
||||
legacy::ability_description(ab.cfg["description"].t_str()) ));
|
||||
if ( active_list )
|
||||
active_list->push_back(true);
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ std::vector<boost::tuple<t_string,t_string,t_string> > unit::ability_tooltips(st
|
|||
res.push_back(boost::make_tuple(
|
||||
default_value(ab.cfg, "name_inactive", "name").t_str(),
|
||||
name,
|
||||
default_value(ab.cfg, "description_inactive", "description").t_str() ));
|
||||
legacy::ability_description(default_value(ab.cfg, "description_inactive", "description").t_str()) ));
|
||||
active_list->push_back(false);
|
||||
}
|
||||
}
|
||||
|
@ -595,7 +595,7 @@ std::vector<std::pair<t_string, t_string> > attack_type::special_tooltips(
|
|||
if ( !active_list || special_active(sp.cfg, AFFECT_EITHER) ) {
|
||||
const t_string &name = sp.cfg["name"];
|
||||
if (!name.empty()) {
|
||||
res.push_back(std::make_pair(name, sp.cfg["description"].t_str() ));
|
||||
res.push_back(std::make_pair(name, legacy::ability_description(sp.cfg["description"].t_str()) ));
|
||||
if ( active_list )
|
||||
active_list->push_back(true);
|
||||
}
|
||||
|
@ -603,7 +603,7 @@ std::vector<std::pair<t_string, t_string> > attack_type::special_tooltips(
|
|||
t_string const &name = default_value(sp.cfg, "name_inactive", "name").t_str();
|
||||
if (!name.empty()) {
|
||||
res.push_back(std::make_pair(
|
||||
name, default_value(sp.cfg, "description_inactive", "description").t_str() ));
|
||||
name, legacy::ability_description(default_value(sp.cfg, "description_inactive", "description").t_str()) ));
|
||||
active_list->push_back(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -622,7 +622,7 @@ void unit_type::build_help_index(const movement_type_map &mv_types,
|
|||
const config::attribute_value &name = ab.cfg["name"];
|
||||
if (!name.empty()) {
|
||||
abilities_.push_back(name.t_str());
|
||||
ability_tooltips_.push_back( ab.cfg["description"].t_str() );
|
||||
ability_tooltips_.push_back( legacy::ability_description(ab.cfg["description"].t_str()) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -639,7 +639,7 @@ void unit_type::build_help_index(const movement_type_map &mv_types,
|
|||
const config::attribute_value &name = ab.cfg["name"];
|
||||
if (!name.empty()) {
|
||||
adv_abilities_.push_back(name.t_str());
|
||||
adv_ability_tooltips_.push_back( ab.cfg["description"].t_str() );
|
||||
adv_ability_tooltips_.push_back( legacy::ability_description(ab.cfg["description"].t_str()) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1542,3 +1542,47 @@ void adjust_profile(std::string &small, std::string &big, std::string const &def
|
|||
big = small;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace legacy {
|
||||
/**
|
||||
* Strips the name of an ability/special from its description.
|
||||
* This adapts the pre-1.11.1 style of "<name>:\n<description>" to
|
||||
* the current style of simply "<description>".
|
||||
*/
|
||||
t_string ability_description(const t_string & description)
|
||||
{
|
||||
/// @deprecated This function is legacy support. Remove it post-1.12.
|
||||
|
||||
// We identify the legacy format by a colon ending the first line.
|
||||
std::string desc_str = description.str();
|
||||
const size_t colon_pos = desc_str.find(':');
|
||||
const size_t first_end_line = desc_str.find_first_of("\r\n");
|
||||
if ( colon_pos != std::string::npos && colon_pos + 1 == first_end_line )
|
||||
{
|
||||
// Try to avoid spamming the deprecation message.
|
||||
static std::set< std::string > reported;
|
||||
const std::string name = desc_str.substr(0, colon_pos);
|
||||
if ( reported.count(name) == 0 )
|
||||
{
|
||||
reported.insert(name);
|
||||
// Inform the player.
|
||||
lg::wml_error << '"' << name << '"'
|
||||
<< " follows a deprecated format for its description,"
|
||||
<< " using its name as the first line. Support"
|
||||
<< " for that format will be removed in 1.12.\n";
|
||||
}
|
||||
|
||||
// Strip the name from the description.
|
||||
// This is sort of bad in that it messes with retranslating, if the
|
||||
// player changes the game's language while playing. However, this
|
||||
// is temporary, so I think simplicity trumps in this case.
|
||||
desc_str.erase(0, colon_pos + 2);
|
||||
return t_string(desc_str);
|
||||
}
|
||||
|
||||
// Not legacy, so this function just falls through.
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -415,4 +415,10 @@ extern unit_type_data unit_types;
|
|||
|
||||
void adjust_profile(std::string &small, std::string &big, std::string const &def);
|
||||
|
||||
namespace legacy {
|
||||
/// Strips the name of an ability/special from its description.
|
||||
t_string ability_description(const t_string & description);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue