deprecating properly image_short and image_long (code part)

This commit is contained in:
Jérémy Rosen 2007-10-05 19:57:55 +00:00
parent 67bca1a8f6
commit 94a2b19d4a
5 changed files with 26 additions and 30 deletions

View file

@ -1237,7 +1237,7 @@ void unit::read(const config& cfg, bool use_traits)
t_atks.merge_with(u_atks);
for(range = t_atks.child_range("attack");
range.first != range.second; ++range.first) {
attacks_.push_back(attack_type(**range.first,id(),image_fighting((**range.first)["range"] == "ranged" ? attack_type::LONG_RANGE : attack_type::SHORT_RANGE)));
attacks_.push_back(attack_type(**range.first,id()));
}
std::vector<attack_type>::iterator at;
for(at = attacks_.begin(); at != attacks_.end(); ++at) {
@ -1249,7 +1249,7 @@ void unit::read(const config& cfg, bool use_traits)
} else {
for(config::const_child_itors range = cfg.child_range("attack");
range.first != range.second; ++range.first) {
attacks_.push_back(attack_type(**range.first,id(),image_fighting((**range.first)["range"] == "ranged" ? attack_type::LONG_RANGE : attack_type::SHORT_RANGE)));
attacks_.push_back(attack_type(**range.first,id()));
}
}
} else {
@ -1679,7 +1679,6 @@ void unit::set_defending(const game_display &disp,const gamemap::location& loc,
void unit::set_extra_anim(const game_display &disp,const gamemap::location& loc, std::string flag)
{
state_ = STATE_EXTRA;
printf("aaaaa %s\n",flag.c_str());
start_animation(disp,loc,choose_animation(disp,loc,flag),false);
}
@ -2541,7 +2540,7 @@ void unit::add_modification(const std::string& type, const config& mod, bool no_
if(!description.empty()) cfg_["unit_description"] = description;
//help::unit_topic_generator(*this, (**i.first)["help_topic"]);
} else if(apply_to == "new_attack") {
attacks_.push_back(attack_type(**i.first,id(),image_fighting((**i.first)["range"]=="ranged" ? attack_type::LONG_RANGE : attack_type::SHORT_RANGE)));
attacks_.push_back(attack_type(**i.first,id()));
// TODO backward compat code, to be removed in 1.3.10, support for old attack format ([animation] in [attack] )
animations_.insert(animations_.end(),attacks_.back().animation_.begin(),attacks_.back().animation_.end());
} else if(apply_to == "remove_attacks") {

View file

@ -267,10 +267,16 @@ int unit_animation::matches(const game_display &disp,const gamemap::location& lo
}
void unit_animation::back_compat_add_name(const std::string name)
void unit_animation::back_compat_add_name(const std::string name,const std::string range)
{
config tmp;
tmp["name"] = name;
event_.push_back("attack");
primary_attack_filter_.push_back(tmp);
if(!name.empty()) {
tmp["name"] = name;
primary_attack_filter_.push_back(tmp);
}
if(!range.empty()) {
tmp["range"] = range;
primary_attack_filter_.push_back(tmp);
}
}

View file

@ -42,7 +42,7 @@ class unit_animation:public animated<unit_frame>
int matches(const game_display &disp,const gamemap::location& loc,const unit* my_unit,const std::string & event="",const int value=0,hit_type hit=INVALID,const attack_type* attack=NULL,const attack_type* second_attack = NULL, int swing_num =0) const;
// only to support all [attack_anim] format, to remove at 1.3.10 time
void back_compat_add_name(const std::string name);
void back_compat_add_name(const std::string name="",const std::string range ="");
const animated<unit_frame> &get_missile_anim() const {return missile_anim_;}
private:
t_translation::t_list terrain_types_;

View file

@ -53,7 +53,7 @@ std::string unit_id_test(const std::string& id)
return id;
}
attack_type::attack_type(const config& cfg,const std::string& id, const std::string& image_fighting, bool with_animations)
attack_type::attack_type(const config& cfg,const std::string& id, bool with_animations)
{
cfg_ = cfg;
if(cfg["range"] == "long" || cfg["range"] == "ranged") {
@ -77,8 +77,6 @@ attack_type::attack_type(const config& cfg,const std::string& id, const std::str
animation_.back().back_compat_add_name(cfg["name"]);
}
}
animation_.push_back(unit_animation(-150,unit_frame(image_fighting,300),"attack",unit_animation::DEFAULT_ANIM));
animation_.back().back_compat_add_name(cfg["name"]);
}
id_ = unit_id_test(cfg["name"]);
@ -780,6 +778,16 @@ unit_type::unit_type(const config& cfg, const movement_type_map& mv_types,
// this has been detected elsewhere, no deprecation message needed here
}
animations_.push_back(unit_animation(-150,unit_frame(image(),300),"attack",unit_animation::DEFAULT_ANIM));
if(!cfg_["image_short"].empty()) {
animations_.push_back(unit_animation(-150,unit_frame(image::locator(cfg_["image_short"]),300),"attack",unit_animation::DEFAULT_ANIM));
animations_.back().back_compat_add_name("","melee");
lg::wml_error<<"image_short is deprecated, support will be removed in 1.3.10 (in unit "<<id()<<")\n";
}
if(!cfg_["image_long"].empty()) {
animations_.push_back(unit_animation(-150,unit_frame(image::locator(cfg_["image_long"]),300),"attack",unit_animation::DEFAULT_ANIM));
animations_.back().back_compat_add_name("","ranged");
lg::wml_error<<"image_long is deprecated, support will be removed in 1.3.10 (in unit "<<id()<<")\n";
}
// always have an attack animation
expanded_cfg = unit_animation::prepare_animation(cfg,"death");
const config::child_list& deaths = expanded_cfg.get_children("death");
@ -882,22 +890,6 @@ const std::string& unit_type::name() const
#endif
const std::string& unit_type::image_fighting(attack_type::RANGE range) const
{
static const std::string short_range("image_short");
static const std::string long_range("image_long");
const std::string& str = range == attack_type::LONG_RANGE ?
long_range : short_range;
const std::string& val = cfg_[str];
if(!val.empty())
//lg::wml_error<<"image_short and image_long are deprecated, support will be removed in 1.3.8 (in unit "<<id()<<")\n";
return val;
else
return image();
}
const std::string& unit_type::image_profile() const
{
@ -925,7 +917,7 @@ std::vector<attack_type> unit_type::attacks(bool with_animations) const
std::vector<attack_type> res;
for(config::const_child_itors range = cfg_.child_range("attack");
range.first != range.second; ++range.first) {
res.push_back(attack_type(**range.first,id(),image_fighting((**range.first)["range"] == "ranged" ? attack_type::LONG_RANGE : attack_type::SHORT_RANGE), with_animations));
res.push_back(attack_type(**range.first,id(), with_animations));
}
return res;

View file

@ -40,7 +40,7 @@ class attack_type
public:
enum RANGE { SHORT_RANGE, LONG_RANGE };
attack_type(const config& cfg, const std::string& id, const std::string& image_fighting, bool with_animations=true);
attack_type(const config& cfg, const std::string& id, bool with_animations=true);
const t_string& name() const { return description_; }
const std::string& id() const { return id_; }
const std::string& type() const { return type_; }
@ -240,7 +240,6 @@ public:
private:
void operator=(const unit_type& o);
const std::string& image_fighting(attack_type::RANGE range) const;
unit_type* gender_types_[2];