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

92 lines
2.2 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-23 12:21:27 +00:00
export var object_name = ""
2020-07-07 12:20:04 +00:00
export(NodePath) var interlockTargetPath
var interlockTarget: GameObjectDoor = null
2020-07-22 13:57:33 +00:00
var open_sound = preload("res://Sounds/SFX/effects/door-open.wav")
var close_sound = preload("res://Sounds/SFX/effects/door-close.wav")
2020-07-20 13:04:56 +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
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():
if is_network_master():
if interlockTargetPath != null:
interlockTarget = get_node_or_null(interlockTargetPath)
if not Engine.editor_hint:
activationRange.visible = true
2020-07-07 07:40:20 +00:00
master func set_open(open: bool):
if not manager:
return
manager.power_usage = active_usage
if manager.powered:
if open:
if interlockTarget != null:
interlockTarget.set_open(false)
rpc("anim_open", open)
remotesync func anim_open(open: bool):
if open:
2020-07-21 08:51:15 +00:00
if $Sprite.animation != "open":
$AudioStreamPlayer2D.stream = open_sound
$AudioStreamPlayer2D.play()
$Sprite.play("open")
else:
2020-07-21 08:51:15 +00:00
if $Sprite.animation != "close":
$AudioStreamPlayer2D.stream = close_sound
$AudioStreamPlayer2D.play()
$Sprite.play("close")
2020-07-06 16:41:30 +00:00
func _animation_finished():
if is_network_master():
if manager:
manager.power_usage = idle_usage
if $Sprite.animation == "open":
# Start timer for auto-close
$Timer.start()
2020-07-06 16:41:30 +00:00
if $Sprite.animation == "open":
# Disable collider
2020-07-23 12:21:27 +00:00
collision_layer &= ~1
collision_mask &= ~1
emit_signal("changed", true)
2020-07-06 16:41:30 +00:00
else:
# Enable collider
2020-07-23 12:21:27 +00:00
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():
rpc("set_open", $Sprite.animation == "close")
master func _close_timer_triggered():
rpc("set_open", false)
func serialize():
return {}
2020-07-06 22:09:45 +00:00
2020-07-22 13:57:33 +00:00
func deserialize(_data):
pass
2020-07-23 12:21:27 +00:00
func inspect():
return {
"type": "Airlock",
"description": "Allows you to move between rooms while keeping rooms air-tight sealed",
"interaction": "Click when close to manually open/close"
}
func _open_sensor_triggered():
2020-07-16 12:44:18 +00:00
rpc("set_open", true)