66 lines
1.7 KiB
GDScript
66 lines
1.7 KiB
GDScript
extends Node3D
|
|
|
|
var load_place = preload("res://places/base_place/base_place.tscn")
|
|
var place = load_place.instantiate()
|
|
|
|
enum ROOM_BUILD_STATE {NONE, ALLOWED, BUILDING, IS_PLACING_DOOR}
|
|
|
|
#Tracks the current build state.
|
|
var room_build_state = 0
|
|
|
|
|
|
var last_room = null
|
|
|
|
#Tracks the position that was first clicked to start a build drag
|
|
var build_drag_start_pos = null
|
|
|
|
signal room_built
|
|
|
|
func _ready():
|
|
#TEMP loads in a workplace.
|
|
add_child(place)
|
|
|
|
func _on_build_toggle(toggled_on):
|
|
#Responds to the 'Build A Room' toggle
|
|
if toggled_on:
|
|
room_build_state = ROOM_BUILD_STATE.ALLOWED
|
|
else:
|
|
place.clear_selection()
|
|
room_build_state = ROOM_BUILD_STATE.NONE
|
|
|
|
func _on_area_3d_input_event(_camera, _event, event_position, _normal, _shade_id):
|
|
#Checks input events from the mouse plane
|
|
|
|
match room_build_state:
|
|
ROOM_BUILD_STATE.ALLOWED:
|
|
if Input.is_action_pressed("select"):
|
|
room_build_state = ROOM_BUILD_STATE.BUILDING
|
|
build_drag_start_pos = event_position
|
|
place.draw_tile_click(build_drag_start_pos)
|
|
|
|
ROOM_BUILD_STATE.BUILDING:
|
|
if Input.is_action_pressed("select"):
|
|
place.init_select_drag(build_drag_start_pos, event_position)
|
|
else:
|
|
room_build_state = ROOM_BUILD_STATE.ALLOWED
|
|
place.end_select_drag()
|
|
|
|
#ROOM_BUILD_STATE.IS_PLACING_DOOR:
|
|
#if Input.is_action_pressed("select"):
|
|
#room_build_state = ROOM_BUILD_STATE.NONE
|
|
#place.confirm_door()
|
|
#emit_signal("room_built")
|
|
#else:
|
|
#place.hover_door(event_position)
|
|
|
|
|
|
func _on_confirm_button_pressed() -> void:
|
|
if place.selection_dict:
|
|
if room_build_state == ROOM_BUILD_STATE.ALLOWED:
|
|
if place.build_confirm_allowed:
|
|
last_room = place.build_selection()
|
|
room_build_state = ROOM_BUILD_STATE.IS_PLACING_DOOR
|
|
|
|
else:
|
|
pass
|