REM/scripts/constructs/construct_pickup.gd
2026-03-26 20:37:29 -06:00

61 lines
2.0 KiB
GDScript

extends StaticBody3D
@onready var construct: Node3D = get_tree().get_first_node_in_group("Constructs")
@onready var construct_name: StringName = $".".name.to_lower()
@onready var player_ray: RayCast3D = get_tree().get_first_node_in_group("player_ray")
@onready var inventory: Control = get_tree().get_first_node_in_group("inventory")
@onready var player: CharacterBody3D = get_tree().get_first_node_in_group("player")
@onready var label: Label3D = $InteractLabel
var empty_slot: bool = false
var number: int = 1
var con_num = 0
func _process(_delta: float) -> void:
# Checks that the ray is colliding and is colliding with this particular object
if player_ray.is_colliding() and player_ray.get_collider() == $".":
label.show()
else:
label.hide()
func interact():
##Detects which construct was picked up and sets it to TRUE
construct.constructs[construct_name] = true
find_empty_slot()
construct.set_construct(con_num, construct_name)
##Make construct button visible in inventory
##TODO Fix this logic so it's not getting parent twice (It's inconsistent)
player.get_node("Inventory/" + self.name.capitalize() + "Button").visible = true
##Remove the construct
queue_free()
##Working for now but still dodgy NEEDS TESTING
func find_empty_slot():
while number < 11 and empty_slot == false:
if construct.assigned_slot[number] != null and construct.assigned_slot[number] != "nothing":
number += 1
else:
if detect_duplicate_cons(construct_name) == false:
construct.assigned_slot[number] = construct_name
con_num = number
##TODO Fix this logic so it's not getting parent twice (It's inconsistent)
player.get_node("Inventory/" + self.name.capitalize() + "Button/SlotLabel").text = str(number)
empty_slot = true
break
number = 1
empty_slot = false
##This is working fine
func detect_duplicate_cons(con_name):
var i: int = 1
while i < 11:
if construct.assigned_slot[i] == con_name:
con_num = i
return true
i += 1
return false