Refactor brick throwing mechanics; integrate new input handling and projectile initialization components

This commit is contained in:
2025-05-13 00:44:44 +02:00
parent 3d65daf0c5
commit c291f42531
25 changed files with 276 additions and 72 deletions

View File

@@ -1,22 +1,18 @@
extends Node
@export var progress_bar: ProgressBar
@export var charge_throw_component: ChargeThrowComponent
@export var brick_throw_component: BrickThrowComponent
var throw_input: ChargeThrowInputResource
func _ready() -> void:
if not charge_throw_component:
return
owner.child_entered_tree.connect(on_nodes_changed)
if not progress_bar:
return
if progress_bar:
progress_bar.hide()
setup_progress_bar()
progress_bar.hide()
charge_throw_component.charge_started.connect(on_charge_started)
charge_throw_component.charge_updated.connect(on_charge_updated)
charge_throw_component.charge_stopped.connect(on_charge_stopped)
setup_dependencies()
func on_charge_updated(charge_ratio: float) -> void:
@@ -45,8 +41,41 @@ func setup_progress_bar() -> void:
if not progress_bar:
return
progress_bar.min_value = charge_throw_component.min_power
progress_bar.max_value = charge_throw_component.max_power
progress_bar.value = charge_throw_component.min_power
progress_bar.min_value = throw_input.min_power
progress_bar.max_value = throw_input.max_power
progress_bar.value = throw_input.min_power
progress_bar.step = 0.01
progress_bar.show()
progress_bar.hide()
func setup_dependencies() -> void:
if not brick_throw_component:
return
if brick_throw_component.throw_input_behavior is ChargeThrowInputResource:
throw_input = brick_throw_component.throw_input_behavior as ChargeThrowInputResource
else:
throw_input = null
if not throw_input:
return
if not progress_bar:
return
if not throw_input.supports_charging():
progress_bar.hide()
return
setup_progress_bar()
throw_input.charge_started.connect(on_charge_started)
throw_input.charge_updated.connect(on_charge_updated)
throw_input.charge_stopped.connect(on_charge_stopped)
func on_nodes_changed(node: Node) -> void:
if node is BrickThrowComponent and brick_throw_component == null:
brick_throw_component = node as BrickThrowComponent
setup_dependencies()
return