generated from krampus/template-godot4
66 lines
1.3 KiB
GDScript
66 lines
1.3 KiB
GDScript
extends Node3D
|
|
|
|
@export var start_open := false
|
|
|
|
@export_category("Editor Tools")
|
|
@export var debug_open: bool:
|
|
set(value):
|
|
open()
|
|
|
|
@export var debug_close: bool:
|
|
set(value):
|
|
close()
|
|
|
|
@onready var animation: AnimationPlayer = $AnimationPlayer
|
|
@onready var dust_animation: AnimationPlayer = %DustAnimation
|
|
@onready var open_sfx: AudioStreamPlayer3D = %OpenSFX
|
|
@onready var bulkhead_game_sound_emitter: GameSoundEmitter = %BulkheadGameSoundEmitter
|
|
@onready var nav_link: NavigationLink3D = %NavLink
|
|
|
|
|
|
func _ready() -> void:
|
|
if start_open:
|
|
_instant_open()
|
|
|
|
|
|
func _instant_open() -> void:
|
|
nav_link.enabled = true
|
|
animation.play("open")
|
|
animation.advance(100)
|
|
|
|
|
|
func _instant_close() -> void:
|
|
nav_link.enabled = false
|
|
animation.play("open")
|
|
animation.advance(0)
|
|
animation.stop()
|
|
|
|
|
|
func is_open() -> bool:
|
|
return nav_link.enabled
|
|
|
|
|
|
func open() -> void:
|
|
nav_link.enabled = true
|
|
animation.play("open")
|
|
dust_animation.play("spray")
|
|
open_sfx.play()
|
|
bulkhead_game_sound_emitter.emit_sound_here()
|
|
|
|
|
|
func close() -> void:
|
|
# TODO bespoke close anim?
|
|
animation.play_backwards("open")
|
|
nav_link.enabled = false
|
|
|
|
|
|
func serialize() -> Dictionary:
|
|
return {"open": is_open()}
|
|
|
|
|
|
func deserialize(state: Dictionary) -> void:
|
|
if state["open"]:
|
|
_instant_open()
|
|
else:
|
|
_instant_close() # unneccessary?
|