Lua Units: Add animations key which returns a list of animations defined

Note: It returns only the flags (for use in [animate_unit], not the full animation.)
This commit is contained in:
Celtic Minstrel 2017-05-10 16:52:16 -04:00
parent b04894fbf3
commit 6846506860
5 changed files with 28 additions and 5 deletions

View file

@ -24,6 +24,7 @@
#include "scripting/game_lua_kernel.hpp"
#include "units/unit.hpp"
#include "units/map.hpp"
#include "units/animation_component.hpp"
#include "lua/lauxlib.h"
#include "lua/lua.h" // for lua_State, lua_settop, etc
@ -346,6 +347,7 @@ static int impl_unit_get(lua_State *L)
push_unit_attacks_table(L, 1);
return 1;
}
return_vector_string_attrib("animations", u.anim_comp().get_flags());
return_cfg_attrib("recall_filter", cfg = u.recall_filter());
return_bool_attrib("hidden", u.get_hidden());
return_bool_attrib("petrified", u.incapacitated());

View file

@ -509,11 +509,11 @@ void unit_animation::fill_initial_animations(std::vector<unit_animation>& animat
animations.back().play_offscreen_ = false;
animations.push_back(base);
animations.back().event_ = { "ghosted" };
animations.back().event_ = { "_ghosted_" };
animations.back().unit_anim_.override(0, animations.back().unit_anim_.get_animation_duration(),particle::UNSET,"0.9", "", {0,0,0}, "", "", "~GS()");
animations.push_back(base);
animations.back().event_ = { "disabled_ghosted" };
animations.back().event_ = { "_disabled_ghosted_" };
animations.back().unit_anim_.override(0, 1, particle::UNSET, "0.4", "", {0,0,0}, "", "", "~GS()");
animations.push_back(base);
@ -668,7 +668,7 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
animations.push_back(unit_animation(anim));
}
// Atanding animations are also used as default animations
// Standing animations are also used as default animations
for(const animation_branch& ab : prepare_animation(cfg, "standing_anim")) {
config anim = ab.merge();
anim["apply_to"] = "default";

View file

@ -54,6 +54,11 @@ public:
unit_anim_.add_frame(duration,value,force_change);
}
std::vector<std::string> get_flags() const
{
return event_;
}
bool need_update() const;
bool need_minimal_update() const;
bool animation_finished() const;

View file

@ -21,6 +21,8 @@
#include "units/unit.hpp"
#include "units/types.hpp"
#include <set>
const unit_animation* unit_animation_component::choose_animation(const display& disp, const map_location& loc,const std::string& event,
const map_location& second_loc,const int value,const unit_animation::hit_type hit,
const_attack_ptr attack, const_attack_ptr second_attack, int swing_num)
@ -61,7 +63,7 @@ void unit_animation_component::set_standing(bool with_bars)
void unit_animation_component::set_ghosted(bool with_bars)
{
display *disp = display::get_singleton();
start_animation(INT_MAX, choose_animation(*disp, u_.loc_, "ghosted"),
start_animation(INT_MAX, choose_animation(*disp, u_.loc_, "_ghosted_"),
with_bars);
anim_->pause_animation();
}
@ -69,7 +71,7 @@ void unit_animation_component::set_ghosted(bool with_bars)
void unit_animation_component::set_disabled_ghosted(bool with_bars)
{
display *disp = display::get_singleton();
start_animation(INT_MAX, choose_animation(*disp, u_.loc_, "disabled_ghosted"),
start_animation(INT_MAX, choose_animation(*disp, u_.loc_, "_disabled_ghosted_"),
with_bars);
}
@ -203,3 +205,14 @@ void unit_animation_component::apply_new_animation_effect(const config & effect)
animations_.insert(animations_.end(),built.begin(),built.end());
}
}
std::vector<std::string> unit_animation_component::get_flags() {
std::set<std::string> result;
for(const auto& anim : animations_) {
const std::vector<std::string>& flags = anim.get_flags();
std::copy_if(flags.begin(), flags.end(), std::inserter(result, result.begin()), [](const std::string flag) {
return !(flag.empty() || (flag.front() == '_' && flag.back() == '_'));
});
}
return std::vector<std::string>(result.begin(), result.end());
}

View file

@ -104,6 +104,9 @@ public:
/** Get a pointer to the current animation. */
unit_animation* get_animation() const { return anim_.get(); }
/** Get the flags of all registered animations. */
std::vector<std::string> get_flags();
friend class unit;
friend class unit_drawer;
private: