extends Node3D


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass # Replace with function body.
@onready var bullet_trace_distance: Node3D = $BulletTraceDistance
@onready var bullet_trail_end: Node3D = $BulletTrailEnd
func shoot() -> Error:
	var bullet_start_node: Node3D = bullet_trace_distance.find_child("Start")
	var bullet_end_node: Node3D = bullet_trace_distance.find_child("End")
	if bullet_start_node and bullet_end_node:
		var path := "res://scenes/weapon/misc/bullet_trail_generic.tscn"
		if not ResourceLoader.exists(path):
			return ERR_DOES_NOT_EXIST
		var scene: PackedScene = ResourceLoader.load(path)
		if not scene.can_instantiate():
			return ERR_CANT_OPEN
		
		var node: MeshInstance3D = scene.instantiate()
		node.init(bullet_start_node.position, bullet_end_node.position)
		#var root := get_tree().get_root()
		bullet_start_node.add_child(node)
		return OK
	else:
		push_warning("Couldn't generate a bullet trace, no distance node found")
		return ERR_BUG
	# -- TODO: It should not be hardcoded
	
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	pass
