This commit is contained in:
dingo
2026-01-11 09:25:29 -05:00
parent b6ccee723f
commit 469cace11d
23 changed files with 629 additions and 24 deletions
+42 -5
View File
@@ -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)
+2 -2
View File
@@ -149,7 +149,7 @@ func _render_tiles(tiles: Array) -> void:
print("[VisualTileMap] Sheet textures keys: %s" % _sheet_textures.keys())
print("[VisualTileMap] Sheet info keys: %s" % _sheet_info.keys())
first_logged = true
print("[VisualTileMap] other tiles: %s" % tile_data)
if _render_tile(tile_data):
rendered += 1
else:
@@ -161,7 +161,7 @@ func _render_tiles(tiles: Array) -> void:
func _render_tile(tile_data: Dictionary) -> bool:
var x = int(tile_data.get("x", 0))
var y = int(tile_data.get("y", 0))
var tile_def_id = int(tile_data.get("tid", 0))
#var tile_def_id = int(tile_data.get("tid", 0))
var layer = int(tile_data.get("l", 0))
var rotation = int(tile_data.get("r", 0))
var flip_x = tile_data.get("fx", false)