extends Interactable

@onready var tmp_sprite: Sprite2D = $TmpSprite

func _ready() -> void:
	SignalBus.set_anchor.connect(_save_state)
	SignalBus.reload_anchor.connect(_load_saved_state)
	if get_path() not in Globals.levers:
		Globals.levers[get_path()] = active
	active = Globals.levers[get_path()]
	_update_sprite()

func _save_state():
	saved_state_active = active

func _load_saved_state():
	active = saved_state_active
	_update_sprite() 

func _update_sprite():
	if active:
		tmp_sprite.rotation = 45
	else:
		tmp_sprite.rotation = -0.3

func switch_state():
	# switch state
	active = !active
	Globals.levers[get_path()] = active
	Globals.toggle_boss_access_lever(active)
	# visual change
	_update_sprite()
	# sfx
	AudioManager.create_audio(SoundEffect.SOUND_EFFECT_TYPE.INTERACTABLE_SYSTEM_ACTIVATED)
