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

54 lines
1.4 KiB
GDScript

extends StaticBody3D
@onready var construct: Node3D = get_tree().get_first_node_in_group("Constructs")
@onready var player_ray: RayCast3D = get_tree().get_first_node_in_group("player_ray")
@onready var label: Label3D = $InteractLabel
var empty_slot: bool = false
var number: int = 1
var con_num: int = 0
func _physics_process(_delta: float) -> void:
if construct.CONSTRUCT_TYPE.name == "Time" and Input.is_action_just_pressed("UseConstruct"):
#$Clock/HourHand.rotation += Vector3(0,deg_to_rad(-30),0)
$".".get_child(1).rotation += Vector3(0,deg_to_rad(-30),0)
if player_ray.is_colliding() and player_ray.get_collider() == $"." and !construct.constructs["time"]:
label.show()
else:
label.hide()
func interact():
construct.constructs["time"] = true
find_empty_slot()
construct.set_construct(con_num, "time")
##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:
number += 1
else:
if detect_duplicate_cons("time") == false:
construct.assigned_slot[number] = "time"
con_num = number
empty_slot = true
break
number = 1
empty_slot = false
print(construct.assigned_slot)
##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