46 lines
1.1 KiB
GDScript
46 lines
1.1 KiB
GDScript
extends StaticBody2D
|
|
|
|
class_name GameObjectDoor
|
|
|
|
export(NodePath) var interlockTargetPath
|
|
var interlockTarget: GameObjectDoor = null
|
|
|
|
onready var activationRange = $ActivationRange as ActivationRange
|
|
|
|
signal changed(open)
|
|
|
|
func _ready():
|
|
if interlockTargetPath != null:
|
|
interlockTarget = get_node_or_null(interlockTargetPath)
|
|
if not Engine.editor_hint:
|
|
activationRange.visible = true
|
|
|
|
func set_open(open: bool):
|
|
if open:
|
|
$Sprite.play("open")
|
|
if interlockTarget != null:
|
|
interlockTarget.set_open(false)
|
|
else:
|
|
$Sprite.play("close")
|
|
|
|
func _animation_finished():
|
|
if $Sprite.animation == "open":
|
|
# Disable collider
|
|
collision_layer = 16
|
|
collision_mask = 16
|
|
# Start timer for auto-close
|
|
$Timer.start()
|
|
else:
|
|
# Enable collider
|
|
collision_mask = 1
|
|
collision_layer = 1
|
|
|
|
func _input_event(viewport, event, shape_idx):
|
|
# Check if we clicked the item
|
|
if event is InputEventMouseButton and event.pressed:
|
|
# Must be in activation range
|
|
if activationRange.in_range():
|
|
set_open($Sprite.animation == "close")
|
|
|
|
func _close_timer_triggered():
|
|
$Sprite.play("close")
|