2020-07-06 16:41:30 +00:00
|
|
|
extends StaticBody2D
|
|
|
|
|
2020-07-07 11:01:12 +00:00
|
|
|
class_name GameObjectDoor
|
|
|
|
|
2020-07-07 12:20:04 +00:00
|
|
|
export(NodePath) var interlockTargetPath
|
|
|
|
var interlockTarget: GameObjectDoor = null
|
|
|
|
|
2020-07-10 08:20:15 +00:00
|
|
|
export var idle_usage = 2
|
|
|
|
export var active_usage = 10
|
|
|
|
|
2020-07-07 07:40:20 +00:00
|
|
|
onready var activationRange = $ActivationRange as ActivationRange
|
2020-07-10 08:20:15 +00:00
|
|
|
onready var manager = $PowerManager as PowerManager
|
2020-07-07 07:40:20 +00:00
|
|
|
|
2020-07-06 16:41:30 +00:00
|
|
|
signal changed(open)
|
|
|
|
|
2020-07-07 07:40:20 +00:00
|
|
|
func _ready():
|
2020-07-07 12:20:04 +00:00
|
|
|
if interlockTargetPath != null:
|
|
|
|
interlockTarget = get_node_or_null(interlockTargetPath)
|
2020-07-07 08:38:32 +00:00
|
|
|
if not Engine.editor_hint:
|
|
|
|
activationRange.visible = true
|
2020-07-07 07:40:20 +00:00
|
|
|
|
2020-07-06 16:41:30 +00:00
|
|
|
func set_open(open: bool):
|
2020-07-10 08:20:15 +00:00
|
|
|
if not manager:
|
|
|
|
return
|
|
|
|
manager.power_usage = active_usage
|
|
|
|
if manager.powered:
|
|
|
|
if open:
|
|
|
|
$Sprite.play("open")
|
|
|
|
if interlockTarget != null:
|
|
|
|
interlockTarget.set_open(false)
|
|
|
|
else:
|
|
|
|
$Sprite.play("close")
|
2020-07-06 16:41:30 +00:00
|
|
|
|
|
|
|
func _animation_finished():
|
2020-07-10 08:20:15 +00:00
|
|
|
if manager:
|
|
|
|
manager.power_usage = idle_usage
|
2020-07-06 16:41:30 +00:00
|
|
|
if $Sprite.animation == "open":
|
|
|
|
# Disable collider
|
2020-07-06 17:23:42 +00:00
|
|
|
collision_layer = 16
|
|
|
|
collision_mask = 16
|
2020-07-07 16:08:56 +00:00
|
|
|
emit_signal("changed", true)
|
2020-07-06 22:09:45 +00:00
|
|
|
# Start timer for auto-close
|
|
|
|
$Timer.start()
|
2020-07-06 16:41:30 +00:00
|
|
|
else:
|
|
|
|
# Enable collider
|
|
|
|
collision_mask = 1
|
|
|
|
collision_layer = 1
|
2020-07-07 16:08:56 +00:00
|
|
|
emit_signal("changed", false)
|
2020-07-06 16:41:30 +00:00
|
|
|
|
2020-07-07 16:08:56 +00:00
|
|
|
func _input_event(_viewport, event, _shape_idx):
|
2020-07-07 07:40:20 +00:00
|
|
|
# Check if we clicked the item
|
2020-07-06 16:41:30 +00:00
|
|
|
if event is InputEventMouseButton and event.pressed:
|
2020-07-07 07:40:20 +00:00
|
|
|
# Must be in activation range
|
|
|
|
if activationRange.in_range():
|
|
|
|
set_open($Sprite.animation == "close")
|
2020-07-06 22:09:45 +00:00
|
|
|
|
|
|
|
func _close_timer_triggered():
|
|
|
|
$Sprite.play("close")
|