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

108 lines
5.4 KiB
GDScript

#@tool
extends Node3D
@export var CONSTRUCT_TYPE : Constructs:
set(value):
CONSTRUCT_TYPE = value
if Engine.is_editor_hint():
load_construct()
@onready var construct_mesh: MeshInstance3D = $ConstructMesh
@onready var construct_mesh2: MeshInstance3D = $ConstructMesh2
@onready var construct_mesh3: MeshInstance3D = $ConstructMesh2/ConstructMesh3
@onready var construct_mesh4: MeshInstance3D = $ConstructMesh2/ConstructMesh4
@onready var construct_shadow: MeshInstance3D = $ConstructShadow
@onready var animation: AnimationPlayer = $"../../../../ConstructAnimation"
@onready var construct_omni_light: OmniLight3D = $ConstructOmniLight
@onready var construct_direct_light: DirectionalLight3D = $ConstructDirectionalLight
@onready var construct_spot_light: SpotLight3D = $ConstructSpotLight
@onready var labels_time: Node3D = $ConstructMesh/labels_time
@onready var player: Node3D = get_tree().get_first_node_in_group("player")
var con_number: int = 1
@export var constructs = {"nothing": true, "stick": false, "weight": false, "hammer": false, "light": false, "flashlight": false, "time": false, "fishing_rod": false, "shovel": false}
var assigned_slot = {1: null, 2: null, 3: null, 4: null, 5: null, 6: null, 7: null, 8: null, 9: null, 10: null}
func _ready() -> void:
##Start checking the assigned slot at 2 since we want the first construct
##to always be what is initialized by the construct node
var j: int = 2
assigned_slot[1] = CONSTRUCT_TYPE.name.to_lower()
##Slot all constructs the player has into a slot
for i in range(0, constructs.size()):
if constructs.values()[i] == true and constructs.keys()[i] != "nothing" and constructs.keys()[i] != CONSTRUCT_TYPE.name.to_lower():
assigned_slot[j] = constructs.keys()[i]
j += 1
## Show the slots constructs are being assigned to
##print(assigned_slot)
load_construct()
func _process(_delta: float) -> void:
##If the flashlight is the active construct then allow the light to be turned on and off
if Input.is_action_just_pressed("UseConstruct") and CONSTRUCT_TYPE.resource_path.get_file() == "flashlight.tres":
construct_spot_light.visible = !construct_spot_light.visible
func _input(event):
if (event.is_action_pressed("construct1") or (event.is_action_pressed("con_up") and con_number == 2)) and assigned_slot[1]:
set_construct(1, assigned_slot[1])
elif (event.is_action_pressed("construct2") or (event.is_action_pressed("con_up") and con_number == 3) or (event.is_action_pressed("con_down") and con_number == 1)) and assigned_slot[2]:
set_construct(2, assigned_slot[2])
elif (event.is_action_pressed("construct3") or (event.is_action_pressed("con_up") and con_number == 4) or (event.is_action_pressed("con_down") and con_number == 2)) and assigned_slot[3]:
set_construct(3, assigned_slot[3])
elif (event.is_action_pressed("construct4") or (event.is_action_pressed("con_up") and con_number == 5) or (event.is_action_pressed("con_down") and con_number == 3)) and assigned_slot[4]:
set_construct(4, assigned_slot[4])
elif (event.is_action_pressed("construct5") or (event.is_action_pressed("con_up") and con_number == 6) or (event.is_action_pressed("con_down") and con_number == 4)) and assigned_slot[5]:
set_construct(5, assigned_slot[5])
elif (event.is_action_pressed("construct6") or (event.is_action_pressed("con_up") and con_number == 7) or (event.is_action_pressed("con_down") and con_number == 5)) and assigned_slot[6]:
set_construct(6, assigned_slot[6])
elif (event.is_action_pressed("construct7") or (event.is_action_pressed("con_up") and con_number == 8) or (event.is_action_pressed("con_down") and con_number == 6)) and assigned_slot[7]:
set_construct(7, assigned_slot[7])
elif (event.is_action_pressed("construct8") or (event.is_action_pressed("con_up") and con_number == 9) or (event.is_action_pressed("con_down") and con_number == 7)) and assigned_slot[8]:
set_construct(8, assigned_slot[8])
elif (event.is_action_pressed("construct9") or (event.is_action_pressed("con_up") and con_number == 10) or (event.is_action_pressed("con_down") and con_number == 8)) and assigned_slot[9]:
set_construct(9, assigned_slot[9])
elif (event.is_action_pressed("construct10")or (event.is_action_pressed("con_down") and con_number == 9)) and assigned_slot[10]:
set_construct(10, assigned_slot[10])
func set_construct(con_num, con_name):
con_number = con_num
con_param_reset()
if con_name == "light":
construct_omni_light.visible = true
if con_name == "flashlight":
construct_spot_light.position = Vector3(-9,0,5)
if con_name == "time":
labels_time.show()
CONSTRUCT_TYPE = load("res://scenes/constructs/" + con_name + "/" + con_name + ".tres")
load_construct()
func load_construct() -> void:
construct_mesh.mesh = CONSTRUCT_TYPE.mesh #Set construct mesh
position = CONSTRUCT_TYPE.position #Set construct position
rotation_degrees = CONSTRUCT_TYPE.rotation #Set rotation
scale = CONSTRUCT_TYPE.scale #Set scale
construct_shadow.visible = CONSTRUCT_TYPE.shadow #Turn Shadow ON/OFF
if construct_mesh2 != null:
construct_mesh2.mesh = CONSTRUCT_TYPE.mesh2
if construct_mesh3 != null:
construct_mesh3.mesh = CONSTRUCT_TYPE.mesh3
if construct_mesh4 != null:
construct_mesh4.mesh = CONSTRUCT_TYPE.mesh4
#If construct is heavy modify player speed to be slower
if self.CONSTRUCT_TYPE.heavy:
player.con_mod = 0.5
func con_param_reset() -> void:
animation.stop()
labels_time.hide()
player.con_mod = 1
construct_omni_light.visible = false
construct_direct_light.visible = false
construct_spot_light.visible = false