Fix [animate_unit][facing] not working.
This also tweaks the animator:add() API, replacing the facing key with a target key and requiring it to be an adjacent location.
This commit is contained in:
parent
e1a579da51
commit
7835e05d93
2 changed files with 8 additions and 3 deletions
|
@ -78,6 +78,7 @@ local function add_animation(anim, cfg)
|
||||||
local facing_loc = wesnoth.get_locations(facing)[1]
|
local facing_loc = wesnoth.get_locations(facing)[1]
|
||||||
if facing_loc then
|
if facing_loc then
|
||||||
local dir = wesnoth.map_location.get_relative_dir(unit.x, unit.y, facing_loc[1], facing_loc[2])
|
local dir = wesnoth.map_location.get_relative_dir(unit.x, unit.y, facing_loc[1], facing_loc[2])
|
||||||
|
unit.facing = dir
|
||||||
facing = wesnoth.map_location.get_direction(unit.x, unit.y, dir)
|
facing = wesnoth.map_location.get_direction(unit.x, unit.y, dir)
|
||||||
else
|
else
|
||||||
facing = nil
|
facing = nil
|
||||||
|
@ -92,7 +93,7 @@ local function add_animation(anim, cfg)
|
||||||
end
|
end
|
||||||
|
|
||||||
anim:add(unit, cfg.flag, hits, {
|
anim:add(unit, cfg.flag, hits, {
|
||||||
facing = facing,
|
target = facing,
|
||||||
value = {tonumber(cfg.value) or 0, tonumber(cfg.value_second) or 0},
|
value = {tonumber(cfg.value) or 0, tonumber(cfg.value_second) or 0},
|
||||||
with_bars = not not cfg.with_bars,
|
with_bars = not not cfg.with_bars,
|
||||||
text = text,
|
text = text,
|
||||||
|
|
|
@ -359,8 +359,12 @@ static int impl_add_animation(lua_State* L)
|
||||||
const_attack_ptr primary, secondary;
|
const_attack_ptr primary, secondary;
|
||||||
|
|
||||||
if(lua_istable(L, 5)) {
|
if(lua_istable(L, 5)) {
|
||||||
lua_getfield(L, 5, "facing");
|
lua_getfield(L, 5, "target");
|
||||||
if(!luaW_tolocation(L, -1, dest)) {
|
if(luaW_tolocation(L, -1, dest)) {
|
||||||
|
if(!tiles_adjacent(dest, u.get_location())) {
|
||||||
|
return luaL_argerror(L, -1, "target must be adjacent to the animated unit");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
// luaW_tolocation may set the location to (0,0) if it fails
|
// luaW_tolocation may set the location to (0,0) if it fails
|
||||||
dest = map_location();
|
dest = map_location();
|
||||||
if(!lua_isnoneornil(L, -1)) {
|
if(!lua_isnoneornil(L, -1)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue