Refactored unit
This commit is contained in:
@@ -26,7 +26,7 @@ signal fight_cancelled
|
||||
@onready var atk_tactic_select: OptionButton = %AttackerTacticSelect
|
||||
@onready var def_tactic_select: OptionButton = %DefenderTacticSelect
|
||||
|
||||
var _selected_unit: Unit
|
||||
var _selected_unit: DeployedUnit
|
||||
var _current_proposal: CombatProposal
|
||||
var combat_system: CombatSystem
|
||||
|
||||
@@ -37,29 +37,29 @@ func _ready() -> void:
|
||||
cancel_button.pressed.connect(_on_cancel_pressed)
|
||||
atk_tactic_select.item_selected.connect(_on_atk_tactic_selected)
|
||||
def_tactic_select.item_selected.connect(_on_def_tactic_selected)
|
||||
for unit: Unit in get_tree().get_nodes_in_group("units"):
|
||||
unit.unit_selected_changed.connect(_on_unit_selected_changed)
|
||||
unit.unit_died.connect(_on_unit_died)
|
||||
for deployed: DeployedUnit in get_tree().get_nodes_in_group("deployed_units"):
|
||||
deployed.unit_selected_changed.connect(_on_unit_selected_changed)
|
||||
deployed.unit_died.connect(_on_unit_died)
|
||||
get_tree().node_added.connect(_on_node_added)
|
||||
|
||||
func _on_node_added(node: Node) -> void:
|
||||
if node is Unit and node.is_in_group("units"):
|
||||
if node is DeployedUnit and node.is_in_group("deployed_units"):
|
||||
if not node.unit_selected_changed.is_connected(_on_unit_selected_changed):
|
||||
node.unit_selected_changed.connect(_on_unit_selected_changed)
|
||||
if not node.unit_died.is_connected(_on_unit_died):
|
||||
node.unit_died.connect(_on_unit_died)
|
||||
|
||||
func _on_unit_died(unit: Unit) -> void:
|
||||
if _selected_unit == unit:
|
||||
func _on_unit_died(deployed: DeployedUnit) -> void:
|
||||
if _selected_unit == deployed:
|
||||
_selected_unit = null
|
||||
unit_panel.visible = false
|
||||
if _current_proposal:
|
||||
if _current_proposal.attacker.unit == unit or _current_proposal.defender.unit == unit:
|
||||
if _current_proposal.attacker.deployed == deployed or _current_proposal.defender.deployed == deployed:
|
||||
_hide_proposal()
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if _selected_unit and is_instance_valid(_selected_unit):
|
||||
hp_bar.max_value = _selected_unit.current_stats.max_hp
|
||||
hp_bar.max_value = _selected_unit.unit.stats.max_hp
|
||||
hp_bar.value = _selected_unit.current_stats.current_hp
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
@@ -68,12 +68,12 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
fight_cancelled.emit()
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
func _on_unit_selected_changed(unit: Unit, selected: bool) -> void:
|
||||
func _on_unit_selected_changed(deployed: DeployedUnit, selected: bool) -> void:
|
||||
if selected:
|
||||
_selected_unit = unit
|
||||
name_label.text = unit.current_info.name
|
||||
hp_bar.max_value = unit.current_stats.max_hp
|
||||
hp_bar.value = unit.current_stats.current_hp
|
||||
_selected_unit = deployed
|
||||
name_label.text = deployed.unit.info.name
|
||||
hp_bar.max_value = deployed.unit.stats.max_hp
|
||||
hp_bar.value = deployed.current_stats.current_hp
|
||||
unit_panel.visible = true
|
||||
else:
|
||||
_selected_unit = null
|
||||
@@ -112,21 +112,21 @@ func _populate_tactic_select(button: OptionButton, combatant: CombatProposal.Com
|
||||
if tactic == combatant.selected_tactic:
|
||||
selected_idx = i
|
||||
button.selected = selected_idx
|
||||
var is_player := combatant.unit.current_allegiance.type == UnitAllegiance.AllegianceType.PLAYER
|
||||
var is_player := combatant.deployed.unit.allegiance.type == UnitAllegiance.AllegianceType.PLAYER
|
||||
button.disabled = not is_player
|
||||
|
||||
|
||||
func _refresh_stats() -> void:
|
||||
var atk := _current_proposal.attacker
|
||||
var def := _current_proposal.defender
|
||||
atk_name_label.text = atk.unit.current_info.name
|
||||
atk_name_label.text = atk.deployed.unit.info.name
|
||||
atk_hp_bar.max_value = atk.max_hp
|
||||
atk_hp_bar.value = atk.hp
|
||||
atk_atk_label.text = "ATK: %d" % atk.atk
|
||||
atk_def_label.text = "DEF: %d" % atk.def
|
||||
atk_hit_label.text = "HIT: %d%%" % atk.hit
|
||||
atk_spd_label.text = "SPD: %d" % atk.spd
|
||||
def_name_label.text = def.unit.current_info.name
|
||||
def_name_label.text = def.deployed.unit.info.name
|
||||
def_hp_bar.max_value = def.max_hp
|
||||
def_hp_bar.value = def.hp
|
||||
def_atk_label.text = "ATK: %d" % def.atk
|
||||
|
||||
Reference in New Issue
Block a user