UI WIP
This commit is contained in:
@@ -21,6 +21,26 @@ var _last_animation: String = "" # Track animation to avoid spam
|
||||
var _current_state: String = "idle"
|
||||
var _facing_direction: String = "down" # down, up, left, right, front, back
|
||||
|
||||
#Temporary state translation:
|
||||
const STATE_TO_ANIMATION := {
|
||||
"idle": "idle",
|
||||
"walking": "walk",
|
||||
"chasing": "walk",
|
||||
"returning": "walk",
|
||||
"fleeing": "walk",
|
||||
"kiting": "walk",
|
||||
|
||||
"attacking": "attack",
|
||||
"casting": "cast",
|
||||
"summoning": "cast",
|
||||
|
||||
"healing": "heal",
|
||||
|
||||
"damaged": "hurt",
|
||||
|
||||
"dead": "dead"
|
||||
}
|
||||
|
||||
func _ready():
|
||||
# Try to find child nodes (they may not exist in all mob scenes)
|
||||
fallback_sprite = get_node_or_null("Sprite2D")
|
||||
@@ -55,6 +75,10 @@ func _ready():
|
||||
if UpdateManager:
|
||||
UpdateManager.file_downloaded.connect(_on_file_downloaded)
|
||||
|
||||
func _state_to_animation(state: String) -> String:
|
||||
state = state.to_lower()
|
||||
return STATE_TO_ANIMATION.get(state, "idle")
|
||||
|
||||
func update_data(data: Dictionary):
|
||||
mob_data = data
|
||||
|
||||
@@ -91,9 +115,17 @@ func update_data(data: Dictionary):
|
||||
_initialized = true
|
||||
|
||||
# Update visual state
|
||||
var state = data.get("state", data.get("State", "idle")).to_lower()
|
||||
#var state = data.get("state", data.get("State", "idle")).to_lower()
|
||||
#var rotation = data.get("rotation", data.get("Rotation", 0.0))
|
||||
#
|
||||
#_update_animation_state(state, rotation)
|
||||
|
||||
var raw_state = data.get("state", data.get("State", "idle")).to_lower()
|
||||
var animation_state := _state_to_animation(raw_state)
|
||||
var rotation = data.get("rotation", data.get("Rotation", 0.0))
|
||||
_update_animation_state(state, rotation)
|
||||
|
||||
_update_animation_state(animation_state, rotation)
|
||||
|
||||
|
||||
# Apply scale
|
||||
var mob_scale = data.get("scale", data.get("Scale", 1.0))
|
||||
@@ -368,11 +400,11 @@ func _rotation_to_direction(rotation: float) -> String:
|
||||
if angle < PI * 0.25 or angle >= PI * 1.75:
|
||||
return "right"
|
||||
elif angle < PI * 0.75:
|
||||
return "front"
|
||||
return "down"
|
||||
elif angle < PI * 1.25:
|
||||
return "left"
|
||||
else:
|
||||
return "back"
|
||||
return "up"
|
||||
|
||||
func _play_animation(state: String, direction: String):
|
||||
if not _animated_sprite or not _animated_sprite.sprite_frames:
|
||||
@@ -387,7 +419,12 @@ func _play_animation(state: String, direction: String):
|
||||
state,
|
||||
"idle_%s" % direction,
|
||||
"idle_%s" % _alt_direction(direction),
|
||||
"idle"
|
||||
"idle",
|
||||
"walk_%s",
|
||||
"run_%s",
|
||||
"hurt_%s",
|
||||
"death_%s",
|
||||
"attack_%s"
|
||||
]
|
||||
|
||||
# Get flip info from sprite config (new format)
|
||||
|
||||
Reference in New Issue
Block a user