Show unit portraits in battle HUD

This commit is contained in:
2026-06-18 13:07:08 +09:00
parent 68342c1b0b
commit 7ad34697f9
9 changed files with 111 additions and 14 deletions

View File

@@ -469,6 +469,7 @@ func _prepare_unit(source_unit: Dictionary) -> Dictionary:
unit["min_range"] = clampi(int(unit.get("min_range", min(1, int(unit["range"])))), 1, int(unit["range"]))
unit["level"] = int(unit.get("level", 1))
unit["exp"] = int(unit.get("exp", 0))
unit["portrait"] = _portrait_for_unit(unit)
if not unit.has("growth") or typeof(unit["growth"]) != TYPE_DICTIONARY:
unit["growth"] = {}
if not unit.has("growth_bonus") or typeof(unit["growth_bonus"]) != TYPE_DICTIONARY:
@@ -513,6 +514,13 @@ func _apply_roster_overlay(unit: Dictionary, roster_overrides) -> void:
unit["loaded_from_roster"] = true
func _portrait_for_unit(unit: Dictionary) -> String:
var portrait := str(unit.get("portrait", ""))
if not portrait.is_empty():
return portrait
return data_catalog.get_portrait_for_officer(str(unit.get("officer_id", "")))
func _find_roster_overlay(unit: Dictionary, roster_overrides: Dictionary) -> Dictionary:
var unit_id := str(unit.get("id", ""))
if roster_overrides.has(unit_id) and typeof(roster_overrides[unit_id]) == TYPE_DICTIONARY:

View File

@@ -40,6 +40,7 @@ func hydrate_deployment(deployment: Dictionary) -> Dictionary:
unit["id"] = str(deployment.get("unit_id", deployment.get("id", deployment.get("officer_id", ""))))
unit["officer_id"] = str(deployment.get("officer_id", ""))
unit["name"] = str(deployment.get("name", officer.get("name", unit["id"])))
unit["portrait"] = str(deployment.get("portrait", officer.get("portrait", "")))
unit["class_id"] = class_id
unit["class"] = str(class_def.get("name", class_id.capitalize()))
unit["team"] = str(deployment.get("team", "enemy"))
@@ -121,6 +122,13 @@ func get_portrait_for_speaker(speaker_name: String) -> String:
return ""
func get_portrait_for_officer(officer_id: String) -> String:
if officer_id.is_empty():
return ""
var officer := _get_dict(officers, officer_id)
return str(officer.get("portrait", ""))
func _load_json_object(path: String) -> Dictionary:
if not FileAccess.file_exists(path):
push_error("Missing data file: %s" % path)