extends Control @export var traits:Array = [ "Courage", "Passion", "Créativité", "Tempérance", "Sensualité", "Énergie", "Responsabilité", "Empathie", "Estime de soi", "Flexibilité", "Espoir", "Volonté" ] @export var amount: int = 3 @export var seed: int = 0 # variables for nodes @onready var traits_list: ItemList = $Trait # Called when the node enters the scene tree for the first time. func _ready() -> void: populate() func generate_traits(traits_list: Array = traits, chosen_seed: int = 0, chosen_amount: int = 3) -> Dictionary: # Return a dictionary, with trait as key and boolean as value # chosen_seed for random seed # chosen_amount for the amount of traits to return var picked_traits: Dictionary = {} var traits_duplicate = traits_list.duplicate() for select in range(chosen_amount): # Pick a trait first and then choose if it is up or down var picked_trait:Dictionary = {} var random = RandomNumberGenerator.new() random.seed = chosen_seed random.randomize() var result: int = random.randi_range(0, traits_duplicate.size() - 1) var random_value = RandomNumberGenerator.new() random_value.seed = chosen_seed random_value.randomize() var value: bool = random_value.randi_range(0, 1) # Add the key and value to the array picked_traits[traits_duplicate[result]] = value # Delete the chosen trait from the possible list traits_duplicate.pop_at(result) return picked_traits func populate(traits: Array = traits, seed: int = 0, amount: int = 3) -> void: # To create an itemlist with traits and values traits_list.clear() var char_traits: Dictionary = generate_traits(traits, seed, amount) for char_trait in char_traits: var value: String = "" if char_traits[char_trait]: value = "↑" else: value = "↓" var full_line: String = char_trait + " " + value traits_list.add_item(full_line)