46 lines
1.1 KiB
GDScript
46 lines
1.1 KiB
GDScript
extends Node
|
|
|
|
signal turnedOn
|
|
signal turnedOff
|
|
signal switchUpdated
|
|
|
|
@export var isOn = false
|
|
@export var isLoopingUpdate : bool = false
|
|
@onready var ButtonAnimation = $AnimationPlayer.get_animation("interact")
|
|
|
|
func _ready() -> void:
|
|
ButtonAnimation.loop_mode = Animation.LOOP_NONE
|
|
# FIX: Look at the saved state before forcing the animation closed!
|
|
if isOn:
|
|
$AnimationPlayer.play("interact")
|
|
# Advance to the end immediately so it doesn't play the visual transition on load
|
|
$AnimationPlayer.advance(ButtonAnimation.length)
|
|
else:
|
|
$AnimationPlayer.play_backwards("interact")
|
|
|
|
func _press():
|
|
if not isOn:
|
|
isOn = true
|
|
$AnimationPlayer.play("interact")
|
|
$Sound.play()
|
|
emit_signal("turnedOn")
|
|
emit_signal("switchUpdated")
|
|
|
|
func _release():
|
|
if isOn:
|
|
isOn = false
|
|
$AnimationPlayer.play_backwards("interact")
|
|
$Sound.play()
|
|
emit_signal("turnedOff")
|
|
emit_signal("switchUpdated")
|
|
|
|
func _interact_press(is_alt_click: bool = false) -> void:
|
|
if isOn:
|
|
_release()
|
|
else:
|
|
_press()
|
|
|
|
func _process(delta: float) -> void:
|
|
if isLoopingUpdate:
|
|
emit_signal("switchUpdated")
|