Cleaning and commenting

This commit is contained in:
Yann Kervran 2024-11-28 18:25:46 +01:00
parent 3f817ae4b5
commit 5193aabb41
2 changed files with 8 additions and 39 deletions

View file

@ -35,14 +35,16 @@ func build_traits() -> void:
var list_amount: int = amount var list_amount: int = amount
var pinned: Array = [] var pinned: Array = []
# First, clear the box for non-pinned traits # Keep track of pinned content
for child in traits_list.get_children(): for child in traits_list.get_children():
for sub_child in child.get_children(): for sub_child in child.get_children():
if sub_child is CheckBox: if sub_child is CheckBox:
if sub_child.button_pressed: if sub_child.button_pressed:
list_amount -= 1 list_amount -= 1
pinned.append([child.get_index(), child]) pinned.append([child.get_index(), child])
# Then clear the Hbox for non-pinned traits
for child in traits_list.get_children(): for child in traits_list.get_children():
for sub_child in child.get_children(): for sub_child in child.get_children():
if sub_child is CheckBox: if sub_child is CheckBox:
@ -52,24 +54,22 @@ func build_traits() -> void:
child.queue_free() child.queue_free()
# generate the amount of traits needed # 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, seed, list_amount)
var char_traits_list: Array = [] var char_traits_list: Array = []
for key in char_traits.keys(): for key in char_traits.keys():
char_traits_list.append([key, char_traits[key][0], char_traits[key][1]]) char_traits_list.append([key, char_traits[key][0], char_traits[key][1]])
# Insert pinned in their position
for pin in pinned: for pin in pinned:
char_traits_list.insert(pin[0], pin[1]) char_traits_list.insert(pin[0], pin[1])
# Generate a line for each trait # Generate a line for each trait
for traitline in range(amount): for traitline in range(amount):
print("At index: ", traitline, " found: ", char_traits_list[traitline])
if char_traits_list[traitline] is HBoxContainer: if char_traits_list[traitline] is HBoxContainer:
print("Je confirme") # For pinned content
print("Parent: ", char_traits_list[traitline].get_parent())
traits_list.add_child(char_traits_list[traitline]) traits_list.add_child(char_traits_list[traitline])
#char_traits_list[traitline].reparent(traits_list)
else: else:
# Create horizontal container for elements # Create horizontal container for elements
var container = HBoxContainer.new() var container = HBoxContainer.new()

View file

@ -1,7 +1,6 @@
[gd_scene load_steps=3 format=3 uid="uid://cl5wswke7jxpi"] [gd_scene load_steps=2 format=3 uid="uid://cl5wswke7jxpi"]
[ext_resource type="Script" path="res://traits.gd" id="1_6h04s"] [ext_resource type="Script" path="res://traits.gd" id="1_6h04s"]
[ext_resource type="Texture2D" uid="uid://cafw5ytvxgep4" path="res://textures/arrowDown.png" id="2_iexdr"]
[node name="Traits" type="Control"] [node name="Traits" type="Control"]
layout_mode = 3 layout_mode = 3
@ -18,33 +17,3 @@ script = ExtResource("1_6h04s")
layout_mode = 0 layout_mode = 0
offset_right = 232.0 offset_right = 232.0
offset_bottom = 119.0 offset_bottom = 119.0
[node name="HBoxContainer" type="HBoxContainer" parent="Traits_list"]
layout_mode = 2
[node name="CheckBox" type="CheckBox" parent="Traits_list/HBoxContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="Traits_list/HBoxContainer"]
layout_mode = 2
text = "My text"
[node name="TextureRect" type="TextureRect" parent="Traits_list/HBoxContainer"]
layout_mode = 2
texture = ExtResource("2_iexdr")
expand_mode = 3
[node name="HBoxContainer2" type="HBoxContainer" parent="Traits_list"]
layout_mode = 2
[node name="CheckBox" type="CheckBox" parent="Traits_list/HBoxContainer2"]
layout_mode = 2
[node name="Label" type="Label" parent="Traits_list/HBoxContainer2"]
layout_mode = 2
text = "My text"
[node name="TextureRect" type="TextureRect" parent="Traits_list/HBoxContainer2"]
layout_mode = 2
texture = ExtResource("2_iexdr")
expand_mode = 3