Rework player state system to use an event subscription system to avoid directly calling methods on individual state and having to worry about validity

This commit is contained in:
2026-04-01 11:11:02 -05:00
parent 7cd34cb07e
commit eabfeab91a
35 changed files with 882 additions and 2288 deletions

View File

@@ -1,22 +1,21 @@
extends Node
# Exports
@export var player: PlayerCharacter
@export var arrow_parent: Node2D
# Preloads
const wooden_arrow_scene: PackedScene = preload("uid://b2wq5m01b68rx")
# Private Methods
func _ready() -> void:
var firing_arrow_state: FiringArrowState = player.get_node("State Machine/States/Firing Arrow State")
firing_arrow_state.ArrowFired.connect(_on_arrow_fired)
func _on_arrow_fired(fire_position: Vector2, direction: Vector2) -> void:
var wooden_arrow := wooden_arrow_scene.instantiate() as BaseProjectile
wooden_arrow.SetProjectileStartAndDirection(fire_position, direction)
if arrow_parent == null:
return
arrow_parent.add_child(wooden_arrow)
#extends Node
#
## Exports
#@export var arrow_parent: Node2D
#
## Preloads
#const wooden_arrow_scene: PackedScene = preload("uid://b2wq5m01b68rx")
#
## Private Methods
#func _ready() -> void:
#firing_arrow_state.ArrowFired.connect(_on_arrow_fired)
#
#
#func _on_arrow_fired(fire_position: Vector2, direction: Vector2) -> void:
#var wooden_arrow := wooden_arrow_scene.instantiate() as BaseProjectile
#wooden_arrow.SetProjectileStartAndDirection(fire_position, direction)
#
#if arrow_parent == null:
#return
#arrow_parent.add_child(wooden_arrow)