Mob fixes.
This commit is contained in:
@@ -153,14 +153,31 @@ func update_data(data: Dictionary):
|
||||
_apply_tint(tint)
|
||||
_initialized = true
|
||||
|
||||
# Resolve animation — prefer server-authoritative currentAnimation, fall back to state
|
||||
# Resolve animation — prefer server-authoritative currentAnimation, fall back to state.
|
||||
# If dungeon_manager already triggered play_death_animation() this tick (setting
|
||||
# _current_state = "dead"), don't let a stale currentAnimation override it — unless
|
||||
# the server explicitly says the mob is alive via a non-dead animation.
|
||||
var current_anim = data.get("currentAnimation", data.get("CurrentAnimation", null))
|
||||
var rotation = data.get("rotation", data.get("Rotation", 0.0))
|
||||
|
||||
if current_anim != null and current_anim is String and not current_anim.is_empty():
|
||||
# Server says exactly what animation to play — always apply, even if currently "dead"
|
||||
var animation_state := _state_to_animation(current_anim)
|
||||
_update_animation_state(animation_state, rotation)
|
||||
var anim_lower = current_anim.to_lower()
|
||||
# Map through STATE_TO_ANIMATION if it's a known state name; otherwise use as-is
|
||||
var animation_state: String
|
||||
if STATE_TO_ANIMATION.has(anim_lower):
|
||||
animation_state = STATE_TO_ANIMATION[anim_lower]
|
||||
else:
|
||||
animation_state = anim_lower
|
||||
|
||||
if animation_state == "dead":
|
||||
# Server confirms death — apply death animation
|
||||
_update_animation_state(animation_state, rotation)
|
||||
elif _current_state == "dead":
|
||||
# Server says non-dead but we're locally dead — server override, mob is alive
|
||||
_update_animation_state(animation_state, rotation)
|
||||
else:
|
||||
# Normal case: apply server animation
|
||||
_update_animation_state(animation_state, rotation)
|
||||
elif _current_state != "dead":
|
||||
# Legacy path: use state field, but still skip if locally dead (no server override)
|
||||
var raw_state = data.get("state", data.get("State", "idle")).to_lower()
|
||||
@@ -480,7 +497,7 @@ func _update_animation_state(state: String, rotation: float):
|
||||
func _rotation_to_direction(rotation: float) -> String:
|
||||
# Convert rotation (radians) to cardinal direction
|
||||
var angle = fmod(rotation + TAU, TAU)
|
||||
|
||||
|
||||
if angle < PI * 0.25 or angle >= PI * 1.75:
|
||||
return "right"
|
||||
elif angle < PI * 0.75:
|
||||
@@ -522,18 +539,19 @@ func _play_animation(state: String, direction: String):
|
||||
var anim_config = _sprite_config["animations"].get(anim_name, {})
|
||||
should_flip_x = anim_config.get("flipX", false)
|
||||
should_flip_y = anim_config.get("flipY", false)
|
||||
|
||||
|
||||
# Only log and play if animation changed
|
||||
if anim_name != _last_animation:
|
||||
#print("[MobVisual] Playing animation: %s (state=%s, dir=%s)" % [anim_name, state, direction])
|
||||
_last_animation = anim_name
|
||||
_animated_sprite.play(anim_name)
|
||||
|
||||
# Handle flipping
|
||||
# For left direction without a dedicated left animation, flip the right one
|
||||
if direction == "left" and not frames.has_animation("%s_left" % state):
|
||||
should_flip_x = not should_flip_x # Toggle flip
|
||||
|
||||
|
||||
# Handle horizontal flipping when playing opposite direction's animation.
|
||||
# If facing right but playing a _left animation (or vice versa), flip.
|
||||
if direction == "right" and anim_name.ends_with("_left"):
|
||||
should_flip_x = not should_flip_x
|
||||
elif direction == "left" and anim_name.ends_with("_right"):
|
||||
should_flip_x = not should_flip_x
|
||||
|
||||
_animated_sprite.flip_h = should_flip_x
|
||||
_animated_sprite.flip_v = should_flip_y
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user