This repository has been archived on 2020-09-30. You can view files and clone it, but cannot push or open issues or pull requests.
odyssey-old/Actors/Objects/Door/Door.gd

59 lines
1.4 KiB
GDScript3
Raw Permalink Normal View History

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
export var idle_usage = 2
export var active_usage = 10
2020-07-07 07:40:20 +00:00
onready var activationRange = $ActivationRange as ActivationRange
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):
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():
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
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
emit_signal("changed", false)
2020-07-06 16:41:30 +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")