Adding doubles management for traits
This commit is contained in:
parent
0abc34655a
commit
aba117d65c
2 changed files with 11 additions and 8 deletions
2
main.gd
2
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)
|
||||
|
|
17
traits.gd
17
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()
|
||||
|
|
Loading…
Reference in a new issue