extends Control

## Grupa przycisków typu checkbox która umożliwia
## wybór tylko jednej opcji
@export var checkbox_group: ButtonGroup

@onready var solo_cb = get_node("Rola/GridContainer/SoloCB")
@onready var netrunner_cb = get_node("Rola/GridContainer/NetrunnerCB")
@onready var korpo_cb = get_node("Rola/GridContainer/KorpoCB")
@onready var button_roll = $"../../Top/TopMenu/ButtonRoll"

enum Chum { SOLO, NETRUNNER, KORPO }

## Słownik zawierający szablony dla klasy netrunner
var netrunner: Dictionary = {
	1: {
		"INT": 5,
		"REF": 8,
		"ZW": 7,
		"TECH": 7,
		"CHA": 7,
		"SW": 4,
		"SZ": 8,
		"RUCH": 7,
		"BC": 7,
		"EMP": 4,
	},
	2: {
		"INT": 5,
		"REF": 6,
		"ZW": 7,
		"TECH": 5,
		"CHA": 8,
		"SW": 3,
		"SZ": 8,
		"RUCH": 7,
		"BC": 5,
		"EMP": 5,
	},
	3: {
		"INT": 5,
		"REF": 6,
		"ZW": 8,
		"TECH": 6,
		"CHA": 6,
		"SW": 4,
		"SZ": 7,
		"RUCH": 6,
		"BC": 7,
		"EMP": 4,
	},
	4: {
		"INT": 5,
		"REF": 7,
		"ZW": 7,
		"TECH": 7,
		"CHA": 7,
		"SW": 5,
		"SZ": 8,
		"RUCH": 6,
		"BC": 5,
		"EMP": 5,
	},
	5: {
		"INT": 5,
		"REF": 8,
		"ZW": 8,
		"TECH": 5,
		"CHA": 7,
		"SW": 3,
		"SZ": 7,
		"RUCH": 5,
		"BC": 5,
		"EMP": 6,
	},
	6: {
		"INT": 6,
		"REF": 6,
		"ZW": 6,
		"TECH": 7,
		"CHA": 8,
		"SW": 4,
		"SZ": 7,
		"RUCH": 7,
		"BC": 6,
		"EMP": 6,
	},
	7: {
		"INT": 6,
		"REF": 6,
		"ZW": 6,
		"TECH": 7,
		"CHA": 6,
		"SW": 5,
		"SZ": 7,
		"RUCH": 7,
		"BC": 7,
		"EMP": 6,
	},
	8: {
		"INT": 5,
		"REF": 6,
		"ZW": 8,
		"TECH": 6,
		"CHA": 8,
		"SW": 4,
		"SZ": 8,
		"RUCH": 5,
		"BC": 7,
		"EMP": 4,
	},
	9: {
		"INT": 7,
		"REF": 6,
		"ZW": 7,
		"TECH": 7,
		"CHA": 6,
		"SW": 3,
		"SZ": 6,
		"RUCH": 5,
		"BC": 6,
		"EMP": 5,
	},
	10: {
		"INT": 7,
		"REF": 8,
		"ZW": 6,
		"TECH": 6,
		"CHA": 6,
		"SW": 4,
		"SZ": 7,
		"RUCH": 7,
		"BC": 5,
		"EMP": 6,
	},
}


## !! FUNKCJA TESTOWA  !!
func test() -> void:
	pass
	
func _ready() -> void:
	var stats = get_tree().get_nodes_in_group("stats")
	
	button_roll.disabled = true
	netrunner_cb.button_pressed = true
	korpo_cb.disabled = true
	solo_cb.disabled = true
	
	for stat in stats:
		stat.text = "0"


func _draw() -> void:
	var stats_scene = get_node("Stats")
	
	if stats_scene.is_visible_in_tree():
		button_roll.disabled = !button_roll.disabled


func _on_button_roll_pressed() -> void:
	var roll = Global.rolld(10)
	var button_pressed = checkbox_group.get_pressed_button()
	var chum
	
	match button_pressed.name:
		"SoloCB":
			chum = Chum.SOLO
		"NetrunnerCB":
			chum = Chum.NETRUNNER
		"KorpoCB":
			chum = Chum.KORPO
			
	
	print("Rzut wynosi: %d a klasa to %s" % [roll, chum])
	character_template(roll, chum)


func character_template(roll: int, chum: int) -> void:
	var stats_group = get_tree().get_nodes_in_group("stats")
	var template_number
	
	match chum:
		1:
			template_number = netrunner.get(roll)
		_:
			print(":(")
		
	if chum <= 1:
		for i in range(stats_group.size()):
			stats_group[i].text = str(template_number.values()[i])
