extends Area2D

onready var s = \
	[$Switches/s1, $Switches/s2, $Switches/s3, $Switches/s4, \
	$Switches/s5, $Switches/s6, $Switches/s7]

var mouse_pos: Vector2 = Vector2.ZERO

func _on_TheWordPart_input_event(_viewport, event, _shape_idx) -> void:
	if event is InputEventMouse:
		mouse_pos = event.position
	
	if !event is InputEventMouseButton:
		return
	if !event.pressed:
		return
	if event.button_index == BUTTON_LEFT:
		var pos = mouse_pos - position
		
		if pos.y < 0:
			if pos.x < -1:
				s[1].visible = !s[1].visible
			elif pos.x > 2:
				s[2].visible = !s[2].visible
			else:
				s[0].visible = !s[0].visible
		elif pos.y > 1:
			if pos.x < -1:
				s[4].visible = !s[4].visible
			elif pos.x > 2:
				s[5].visible = !s[5].visible
			else:
				s[6].visible = !s[6].visible
		else:
			s[3].visible = !s[3].visible
	
	print(get_answer())

func get_answer() -> int:
	var final: int = 0
	var multiplier: int = 1
	for i in range(s.size()):
		final += int(s[i].visible) * multiplier
		multiplier *= 2
	
	return final
