51 lines
1.1 KiB
GDScript
51 lines
1.1 KiB
GDScript
extends Node3D
|
|
|
|
var load_place = preload("res://places/base_place/base_place.tscn")
|
|
var place = load_place.instantiate()
|
|
|
|
var build_enabled = false
|
|
var is_building = false
|
|
|
|
var build_start_pos = null
|
|
|
|
signal room_built
|
|
|
|
func _ready():
|
|
add_child(place)
|
|
|
|
func _input(event):
|
|
pass
|
|
|
|
func _on_build_toggle(toggled_on):
|
|
build_enabled = toggled_on
|
|
if not toggled_on:
|
|
place.clear_selection()
|
|
|
|
func start_build(event):
|
|
is_building = event.button_mask
|
|
|
|
func _on_area_3d_input_event(_camera, event, event_position, _normal, _shade_id):
|
|
#Checks input events from the mouse planex
|
|
|
|
if event.is_action_pressed("select") && build_enabled:
|
|
build_start_pos = event_position
|
|
start_build(event)
|
|
place.draw_tile_click(build_start_pos)
|
|
|
|
if is_building:
|
|
if event.button_mask:
|
|
var build_mouse_pos = event_position
|
|
place.init_select_drag(build_start_pos, build_mouse_pos)
|
|
|
|
if not event.button_mask:
|
|
start_build(event)
|
|
place.end_select_drag()
|
|
|
|
func _on_confirm_button_pressed() -> void:
|
|
if place.build_allowed:
|
|
place.build_selection()
|
|
is_building = false
|
|
emit_signal("room_built")
|
|
else:
|
|
pass
|