@abstract class_name Interactable
extends StaticBody2D

var active = false
var saved_state_active = false
var boss_saved_state = false

func _ready() -> void:
	# add to global dictionary 
	if get_path() not in Globals.interactable_states:
		Globals.interactable_states[get_path()] = active
	active = Globals.interactable_states[get_path()]
	_update_sprite()
	#print("reade ", Globals.interactable_states[get_path()], get_path())
	
	SignalBus.set_anchor.connect(_save_state)
	SignalBus.reload_anchor.connect(_load_saved_state)
	SignalBus.boss_set_anchor.connect(_boss_save_state)
	SignalBus.boss_reload_anchor.connect(_load_boss_saved_state)

func switch_state():
	# switch state
	active = !active
	# visual change
	_update_sprite()
	# sfx
	AudioManager.create_audio(SoundEffect.SOUND_EFFECT_TYPE.LEVER_CHANGE_STATE)
	# save globally
	Globals.interactable_states[get_path()] = active
	
func _save_state():
	saved_state_active = active

func _load_saved_state():
	active = saved_state_active
	_update_sprite() 
	
func _boss_save_state():
	boss_saved_state = active

func _load_boss_saved_state():
	active = boss_saved_state
	_update_sprite() 

@abstract func _update_sprite()  # update sprite, depending on active
