2020-07-06 16:41:30 +00:00
|
|
|
extends StaticBody2D
|
|
|
|
|
2020-07-07 11:01:12 +00:00
|
|
|
class_name GameObjectDoor
|
|
|
|
|
2020-09-15 23:23:45 +00:00
|
|
|
export var object_name := ""
|
2020-07-07 12:20:04 +00:00
|
|
|
export(NodePath) var interlockTargetPath
|
|
|
|
var interlockTarget: GameObjectDoor = null
|
|
|
|
|
2020-09-15 23:23:45 +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
|
|
|
|
2020-09-15 23:23:45 +00:00
|
|
|
export var idle_usage := 2
|
|
|
|
export var active_usage := 10
|
2020-07-10 08:20:15 +00:00
|
|
|
|
2020-09-15 23:23:45 +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-09-24 10:56:53 +00:00
|
|
|
static func editor_info():
|
|
|
|
var editor_icon = AtlasTexture.new()
|
|
|
|
editor_icon.atlas = preload("res://Graphics/tgstation/opening-sheet.png")
|
|
|
|
editor_icon.region = Rect2(0, 0, 32, 32)
|
|
|
|
return {
|
|
|
|
"name": "Door",
|
|
|
|
"scene": load("res://Actors/Objects/Door/Door.tscn"),
|
|
|
|
"icon": editor_icon
|
|
|
|
}
|
|
|
|
|
2020-07-07 07:40:20 +00:00
|
|
|
func _ready():
|
2020-07-13 19:01:36 +00:00
|
|
|
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
|
|
|
|
2020-07-13 19:01:36 +00:00
|
|
|
master 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:
|
|
|
|
if interlockTarget != null:
|
|
|
|
interlockTarget.set_open(false)
|
2020-07-13 19:01:36 +00:00
|
|
|
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()
|
2020-07-13 19:01:36 +00:00
|
|
|
$Sprite.play("open")
|
|
|
|
else:
|
2020-07-21 08:51:15 +00:00
|
|
|
if $Sprite.animation != "close":
|
|
|
|
$AudioStreamPlayer2D.stream = close_sound
|
|
|
|
$AudioStreamPlayer2D.play()
|
2020-07-13 19:01:36 +00:00
|
|
|
$Sprite.play("close")
|
2020-07-06 16:41:30 +00:00
|
|
|
|
|
|
|
func _animation_finished():
|
2020-07-13 19:01:36 +00:00
|
|
|
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
|
2020-07-07 16:08:56 +00:00
|
|
|
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
|
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():
|
2020-07-13 19:01:36 +00:00
|
|
|
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):
|
2020-07-13 19:01:36 +00:00
|
|
|
pass
|
2020-07-16 12:36:08 +00:00
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2020-07-16 12:36:08 +00:00
|
|
|
func _open_sensor_triggered():
|
2020-07-16 12:44:18 +00:00
|
|
|
rpc("set_open", true)
|