grunk/src/props/bulkhead/bulkhead.gd

66 lines
1.3 KiB
GDScript3
Raw Normal View History

2025-03-10 17:00:30 -06:00
extends Node3D
2025-04-22 12:08:09 -06:00
@export var start_open := false
@export_category("Editor Tools")
2025-04-17 17:06:07 -06:00
@export var debug_open: bool:
set(value):
open()
@export var debug_close: bool:
set(value):
close()
2025-03-10 17:00:30 -06:00
@onready var animation: AnimationPlayer = $AnimationPlayer
2025-03-12 12:56:03 -06:00
@onready var dust_animation: AnimationPlayer = %DustAnimation
2025-03-29 19:32:24 -06:00
@onready var open_sfx: AudioStreamPlayer3D = %OpenSFX
@onready var bulkhead_game_sound_emitter: GameSoundEmitter = %BulkheadGameSoundEmitter
2025-04-16 17:20:33 -06:00
@onready var nav_link: NavigationLink3D = %NavLink
2025-03-10 17:00:30 -06:00
2025-04-22 12:08:09 -06:00
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
2025-03-10 17:00:30 -06:00
func open() -> void:
2025-04-16 17:20:33 -06:00
nav_link.enabled = true
2025-03-10 17:00:30 -06:00
animation.play("open")
2025-03-12 12:56:03 -06:00
dust_animation.play("spray")
2025-03-29 19:32:24 -06:00
open_sfx.play()
bulkhead_game_sound_emitter.emit_sound_here()
2025-03-13 12:25:04 -06:00
func close() -> void:
# TODO bespoke close anim?
animation.play_backwards("open")
2025-04-16 17:20:33 -06:00
nav_link.enabled = false
2025-04-22 12:08:09 -06:00
func serialize() -> Dictionary:
return {"open": is_open()}
func deserialize(state: Dictionary) -> void:
if state["open"]:
_instant_open()
else:
_instant_close() # unneccessary?