grunk/src/props/bulkhead/bulkhead.gd

81 lines
1.6 KiB
GDScript3
Raw Normal View History

2025-03-10 17:00:30 -06:00
extends Node3D
2025-06-17 19:05:17 -06:00
signal animation_finished
2025-04-22 12:08:09 -06:00
@export var start_open := false
2025-06-17 19:05:17 -06:00
@export var close_2_probability := 0.03
2025-04-22 12:08:09 -06:00
@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:
_deferred_init.call_deferred()
func _deferred_init() -> void:
2025-04-22 12:08:09 -06:00
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
2025-06-17 19:05:17 -06:00
animation.play("close")
animation.advance(100)
2025-04-22 12:08:09 -06:00
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:
2025-06-17 19:05:17 -06:00
var close_anim := "close" if randf() > close_2_probability else "close2"
animation.play(close_anim)
2025-04-16 17:20:33 -06:00
nav_link.enabled = false
2025-04-22 12:08:09 -06:00
2025-06-17 19:05:17 -06:00
func toggle() -> void:
if is_open():
close()
else:
open()
2025-04-22 12:08:09 -06:00
func serialize() -> Dictionary:
return {"open": is_open()}
func deserialize(state: Dictionary) -> void:
start_open = state["open"]
2025-06-17 19:05:17 -06:00
func _on_animation_player_animation_finished(_anim_name: StringName) -> void:
animation_finished.emit()