From aba117d65c90bff6ac7033fcd959605a4c1222f8 Mon Sep 17 00:00:00 2001 From: Yann Kervran Date: Thu, 28 Nov 2024 18:52:35 +0100 Subject: [PATCH] Adding doubles management for traits --- main.gd | 2 +- traits.gd | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/main.gd b/main.gd index f7a83f8..0344d14 100644 --- a/main.gd +++ b/main.gd @@ -29,7 +29,7 @@ func _ready() -> void: language_choice.get_popup().connect("id_pressed", _on_menu_language_selected) -func _process(delta: float) -> void: +func _process(_delta: float) -> void: # Roll new result" if Input.is_action_just_pressed("roll"): lets_roll(seed) diff --git a/traits.gd b/traits.gd index b042aae..2319118 100644 --- a/traits.gd +++ b/traits.gd @@ -34,16 +34,16 @@ func build_traits() -> void: var list_amount: int = amount var pinned: Array = [] + var pinned_name: Array = [] # Keep track of pinned content - for child in traits_list.get_children(): for sub_child in child.get_children(): if sub_child is CheckBox: if sub_child.button_pressed: list_amount -= 1 pinned.append([child.get_index(), child]) - + pinned_name.append(child.get_child(1).text) # Then clear the Hbox for non-pinned traits for child in traits_list.get_children(): for sub_child in child.get_children(): @@ -55,7 +55,7 @@ func build_traits() -> void: # Generate the amount of traits needed and store in an array - var char_traits: Dictionary = generate_traits(traits, seed, list_amount) + var char_traits: Dictionary = generate_traits(traits, pinned_name, seed, list_amount) var char_traits_list: Array = [] for key in char_traits.keys(): @@ -86,7 +86,6 @@ func build_traits() -> void: label.text = char_traits_list[traitline][0] # Icon for up or down - var icon: Texture2D = icon_down var icon_rect: TextureRect = TextureRect.new() icon_rect.texture = icon_down var value: bool = char_traits_list[traitline][1] @@ -109,18 +108,22 @@ func _on_checkbox_toggled(checked: bool, checkbox: int) -> void: # Manage checkbox signal pass -func generate_traits(traits_list: Array = traits, chosen_seed: int = 0, chosen_amount: int = 3) -> Dictionary: +func generate_traits(traits_list: Array = traits, pinned_traits: Array = [], chosen_seed: int = 0, chosen_amount: int = 3) -> Dictionary: # Return a dictionary, # with trait as key and # an array with index as first value and boolean as second value # Inputs: + # traits_list for list of traits + # pinned_traits for pinned traits (to prevent doubles) # chosen_seed for random seed # chosen_amount for the amount of traits to return var picked_traits: Dictionary = {} - var traits_duplicate = traits_list.duplicate() + var traits_duplicate: Array = traits_list.duplicate() + # Remove the one already used + for item in pinned_traits: + traits_duplicate.erase(item) 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()