From e5dea5bb50371f84fb240f3ddf855d9d4e8e2659 Mon Sep 17 00:00:00 2001 From: Altaezio Date: Sun, 12 Apr 2026 20:10:40 +0200 Subject: [PATCH] =?UTF-8?q?Densit=C3=A9=20de=20partie=20de=20plantes=20en?= =?UTF-8?q?=20fonction=20du=20niveau=20de=20mutation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plant_texture_builder.tscn | 35 +++++++++++++++---- entities/plants/plant_part_buider.tscn | 29 +++++++++------ .../plants/resources/plant_parts/LeafA5.tres | 2 +- .../plants/resources/plant_parts/LeafE6.tres | 22 ++++++++---- .../scripts/texture_builder/part_assembler.gd | 21 +++++++++-- .../texture_builder/plant_texture_builder.gd | 11 +++++- entities/plants/test_sprites.tscn | 31 ++++++++++++++-- 7 files changed, 121 insertions(+), 30 deletions(-) diff --git a/common/plant_texture_builder/plant_texture_builder.tscn b/common/plant_texture_builder/plant_texture_builder.tscn index fa3767c..46376e8 100644 --- a/common/plant_texture_builder/plant_texture_builder.tscn +++ b/common/plant_texture_builder/plant_texture_builder.tscn @@ -12,7 +12,6 @@ [ext_resource type="Resource" uid="uid://cyfyodtfxne1w" path="res://entities/plants/resources/plant_parts/Branch5.tres" id="8_qm7aw"] [ext_resource type="Resource" uid="uid://cuvtf4y1dspcp" path="res://entities/plants/resources/plant_parts/Branch6.tres" id="9_3e4c1"] [ext_resource type="Resource" uid="uid://dcjpei6xuiswp" path="res://entities/plants/resources/plant_parts/LeafE5.tres" id="10_5job5"] -[ext_resource type="Resource" uid="uid://cqxmyd07qyj4g" path="res://entities/plants/resources/plant_parts/LeafE6.tres" id="11_cynqk"] [ext_resource type="Resource" uid="uid://85bwx2tdjx0h" path="res://entities/plants/resources/plant_parts/LeafE7.tres" id="12_b21au"] [ext_resource type="Resource" uid="uid://6jnbms553dyd" path="res://entities/plants/resources/plant_parts/Branch7.tres" id="12_yjh7s"] [ext_resource type="Resource" uid="uid://cowkewtw2lg4i" path="res://entities/plants/resources/plant_parts/FlowerA1.tres" id="13_17ac3"] @@ -47,9 +46,11 @@ [ext_resource type="Resource" uid="uid://bkgrwffi7m2i4" path="res://entities/plants/resources/plant_parts/FlowerC4.tres" id="24_rbd7l"] [ext_resource type="Resource" uid="uid://dm7crxxg4kmw5" path="res://entities/plants/resources/plant_parts/LeafB1.tres" id="25_kvmj5"] [ext_resource type="Resource" uid="uid://vlxrq3tw1t6m" path="res://entities/plants/resources/plant_parts/LeafB2.tres" id="26_ocu7e"] +[ext_resource type="Script" path="res://entities/plants/scripts/texture_builder/plant_attach.gd" id="27_80nvf"] [ext_resource type="Resource" uid="uid://bdwhp12xkvscr" path="res://entities/plants/resources/plant_parts/LeafB3.tres" id="27_q771y"] [ext_resource type="Resource" uid="uid://cc8kkqiqdvex6" path="res://entities/plants/resources/plant_parts/LeafE8.tres" id="27_rcays"] [ext_resource type="Resource" uid="uid://dmfiww0l5ha2l" path="res://entities/plants/resources/plant_parts/LeafB4.tres" id="28_5fbyu"] +[ext_resource type="Texture2D" uid="uid://bdwmandgxrjgn" path="res://entities/plants/assets/sprites/asset_plantes.png" id="28_d04mb"] [ext_resource type="Resource" uid="uid://cusd2od1yj0ob" path="res://entities/plants/resources/plant_parts/LeafE9.tres" id="28_qs4je"] [ext_resource type="Resource" uid="uid://kiim46eda050" path="res://entities/plants/resources/plant_parts/LeafB5.tres" id="29_2plsj"] [ext_resource type="Resource" uid="uid://dqroc7h70bgew" path="res://entities/plants/resources/plant_parts/LeafB6.tres" id="30_yjh7s"] @@ -128,9 +129,31 @@ [ext_resource type="Resource" uid="uid://c70ikd1qfmqqs" path="res://entities/plants/resources/plant_parts/LeafK6.tres" id="116_xxckx"] [ext_resource type="Resource" uid="uid://bhgnimmagff30" path="res://entities/plants/resources/plant_parts/LeafK7.tres" id="117_s3ec7"] +[sub_resource type="Resource" id="Resource_us16y"] +script = ExtResource("27_80nvf") +position = Vector2(-36, -37) +attach_types = Array[int]([2]) + +[sub_resource type="Resource" id="Resource_ux8f6"] +script = ExtResource("27_80nvf") +position = Vector2(59, -81) +attach_types = Array[int]([1, 3]) + +[sub_resource type="AtlasTexture" id="AtlasTexture_yh7e0"] +atlas = ExtResource("28_d04mb") +region = Rect2(2804, 1567, 294, 345) + +[sub_resource type="Resource" id="Resource_6htke"] +resource_name = "LeafE6" +script = ExtResource("2_cfiqo") +texture = SubResource("AtlasTexture_yh7e0") +type = 2 +root = SubResource("Resource_ux8f6") +attaches = Array[ExtResource("27_80nvf")]([SubResource("Resource_us16y")]) + [sub_resource type="Resource" id="Resource_rt6tw"] script = ExtResource("16_c3tk3") -parts = Array[ExtResource("2_cfiqo")]([ExtResource("15_p2blu"), ExtResource("16_xt8tm"), ExtResource("17_qm7aw"), ExtResource("42_14c4k"), ExtResource("10_5job5"), ExtResource("11_cynqk"), ExtResource("12_b21au"), ExtResource("27_rcays"), ExtResource("28_qs4je")]) +parts = Array[ExtResource("2_cfiqo")]([ExtResource("15_p2blu"), ExtResource("16_xt8tm"), ExtResource("17_qm7aw"), ExtResource("42_14c4k"), ExtResource("10_5job5"), SubResource("Resource_6htke"), ExtResource("12_b21au"), ExtResource("27_rcays"), ExtResource("28_qs4je")]) metadata/_custom_type_script = "uid://cfjd8jelpm8dt" [sub_resource type="Resource" id="Resource_y02ao"] @@ -246,10 +269,10 @@ parts_mutation_associations = Dictionary[String, ExtResource("16_c3tk3")]({ "TOUGH": SubResource("Resource_jbu3q"), "VIVACIOUS": SubResource("Resource_0wuoa") }) -chance_to_have_part = 0.9 +chance_to_have_part = 1.0 origin_weights_base = Dictionary[int, int]({ -0: 20, -1: 10, -2: 2 +0: 100, +1: 0, +2: 20 }) seed_texture_sets = Array[ExtResource("47_jbu3q")]([SubResource("Resource_cynqk"), SubResource("Resource_17ac3")]) diff --git a/entities/plants/plant_part_buider.tscn b/entities/plants/plant_part_buider.tscn index 16353dd..1b5e1d4 100644 --- a/entities/plants/plant_part_buider.tscn +++ b/entities/plants/plant_part_buider.tscn @@ -4,29 +4,36 @@ [ext_resource type="Script" uid="uid://c360ic1aost1n" path="res://entities/plants/scripts/texture_builder/plant_part_builder.gd" id="2_a5yje"] [ext_resource type="Script" path="res://entities/plants/scripts/texture_builder/plant_attach_builder.gd" id="3_yh7e0"] -[sub_resource type="AtlasTexture" id="AtlasTexture_khbsd"] +[sub_resource type="AtlasTexture" id="AtlasTexture_yh7e0"] atlas = ExtResource("1_yh7e0") -region = Rect2(4497, 2359, 335, 454) +region = Rect2(3118, 1700, 367, 440) [node name="Sprite" type="Sprite2D" unique_id=1642167049 node_paths=PackedStringArray("root", "attaches")] -texture = SubResource("AtlasTexture_khbsd") +texture = SubResource("AtlasTexture_yh7e0") script = ExtResource("2_a5yje") -part_name = "Base3" +part_name = "LeafE6" +type = 2 root = NodePath("Root") attaches = NodePath("Attaches") [node name="Root" type="Node2D" parent="." unique_id=1437082577] -position = Vector2(15, 184) +position = Vector2(40, -66) script = ExtResource("3_yh7e0") +attach_types = Array[int]([1]) [node name="Attaches" type="Node" parent="." unique_id=1834697767] [node name="attach2" type="Node2D" parent="Attaches" unique_id=1063061640] -position = Vector2(-89, 45) -script = ExtResource("3_yh7e0") -attach_types = Array[int]([3]) - -[node name="attach4" type="Node2D" parent="Attaches" unique_id=451232079] -position = Vector2(-7, -161) +position = Vector2(-46, 17) +script = ExtResource("3_yh7e0") +attach_types = Array[int]([2]) + +[node name="attach1" type="Node2D" parent="Attaches" unique_id=539833351] +position = Vector2(116, 72) +script = ExtResource("3_yh7e0") +attach_types = Array[int]([2]) + +[node name="@Node2D@32601" type="Node2D" parent="Attaches" unique_id=2139586007] +position = Vector2(-38, -137) script = ExtResource("3_yh7e0") attach_types = Array[int]([2]) diff --git a/entities/plants/resources/plant_parts/LeafA5.tres b/entities/plants/resources/plant_parts/LeafA5.tres index 8b005aa..1948996 100644 --- a/entities/plants/resources/plant_parts/LeafA5.tres +++ b/entities/plants/resources/plant_parts/LeafA5.tres @@ -1,6 +1,6 @@ [gd_resource type="Resource" script_class="PlantPart" format=3 uid="uid://cewwsxddmw36t"] -[ext_resource type="Script" uid="uid://co46ywm8bgnfh" path="res://entities/plants/scripts/texture_builder/plant_attach.gd" id="1_ef00k"] +[ext_resource type="Script" path="res://entities/plants/scripts/texture_builder/plant_attach.gd" id="1_ef00k"] [ext_resource type="Script" uid="uid://b3jwglylqdqtw" path="res://entities/plants/scripts/texture_builder/plant_part.gd" id="2_0qgsw"] [ext_resource type="Texture2D" uid="uid://bxnm1quxhx40i" path="res://entities/plants/assets/sprites/asset-plante-fin_assemble.png" id="3_snml7"] diff --git a/entities/plants/resources/plant_parts/LeafE6.tres b/entities/plants/resources/plant_parts/LeafE6.tres index 9557c49..ddb2cc9 100644 --- a/entities/plants/resources/plant_parts/LeafE6.tres +++ b/entities/plants/resources/plant_parts/LeafE6.tres @@ -6,22 +6,32 @@ [sub_resource type="Resource" id="Resource_us16y"] script = ExtResource("1_us16y") -position = Vector2(-36, -37) +position = Vector2(-46, 17) attach_types = Array[int]([2]) [sub_resource type="Resource" id="Resource_ux8f6"] script = ExtResource("1_us16y") -position = Vector2(59, -81) -attach_types = Array[int]([1, 3]) +position = Vector2(116, 72) +attach_types = Array[int]([2]) + +[sub_resource type="Resource" id="Resource_qn1v0"] +script = ExtResource("1_us16y") +position = Vector2(-38, -137) +attach_types = Array[int]([2]) + +[sub_resource type="Resource" id="Resource_l0344"] +script = ExtResource("1_us16y") +position = Vector2(40, -66) +attach_types = Array[int]([1]) [sub_resource type="AtlasTexture" id="AtlasTexture_yh7e0"] atlas = ExtResource("3_qn1v0") -region = Rect2(2804, 1567, 294, 345) +region = Rect2(3118, 1700, 367, 440) [resource] resource_name = "LeafE6" script = ExtResource("2_ux8f6") texture = SubResource("AtlasTexture_yh7e0") type = 2 -root = SubResource("Resource_ux8f6") -attaches = Array[ExtResource("1_us16y")]([SubResource("Resource_us16y")]) +root = SubResource("Resource_l0344") +attaches = Array[ExtResource("1_us16y")]([SubResource("Resource_us16y"), SubResource("Resource_ux8f6"), SubResource("Resource_qn1v0")]) diff --git a/entities/plants/scripts/texture_builder/part_assembler.gd b/entities/plants/scripts/texture_builder/part_assembler.gd index ba6e686..32164bb 100644 --- a/entities/plants/scripts/texture_builder/part_assembler.gd +++ b/entities/plants/scripts/texture_builder/part_assembler.gd @@ -9,6 +9,9 @@ extends Node @export var start_state: PlantData.State = PlantData.State.MATURE @export var random_state := false @export var end_state: PlantData.State = PlantData.State.MATURE +@export var min_level := 1 +@export var max_level := 1 + @export var camera_speed := 1000.0 var input_dir := Vector2.ZERO @@ -21,6 +24,10 @@ func _ready(): %NMutationsPerPlant.value = n_mutation_per_plant %RandomizePos.button_pressed = randomize_pos %RandomizeOffset.value = random_pos_offset + %toAgeLabel.visible = random_state + %EndAge.visible = random_state + %MinLvl.value = min_level + %MaxLvl.value = max_level generate_plants(); func _unhandled_key_input(_event) -> void: @@ -54,7 +61,9 @@ func generate_plants(): elif plant_state == PlantData.State.DEAD: plant_data.day = plant_data.get_lifetime() for j in n_mutation_per_plant: - plant_data.mutations.append(GameInfo.game_data.progression_data.available_mutations.pick_random()) + var picked_mutation: PlantMutation = GameInfo.game_data.progression_data.available_mutations.pick_random().duplicate() + picked_mutation.level = randi_range(min_level, max_level) + plant_data.mutations.append(picked_mutation) var plant: Plant = Plant.new(plant_data) print(plant.data.plant_name) %Plants.add_child(plant) @@ -113,14 +122,20 @@ func _on_start_age_value_changed(value: float) -> void: func _on_random_age_toggled(toggled_on: bool) -> void: random_state = toggled_on + %toAgeLabel.visible = toggled_on + %EndAge.visible = toggled_on func _on_end_age_value_changed(value: float) -> void: end_state = int(value) as PlantData.State - func _on_speed_value_changed(value: float) -> void: camera_speed = value - func _on_reset_speed_pressed() -> void: camera_speed = 1000 + +func _on_min_lvl_value_changed(value: float) -> void: + min_level = int(value) + +func _on_max_lvl_value_changed(value: float) -> void: + max_level = int(value) diff --git a/entities/plants/scripts/texture_builder/plant_texture_builder.gd b/entities/plants/scripts/texture_builder/plant_texture_builder.gd index 674de9c..4f6d35c 100644 --- a/entities/plants/scripts/texture_builder/plant_texture_builder.gd +++ b/entities/plants/scripts/texture_builder/plant_texture_builder.gd @@ -36,6 +36,7 @@ enum OriginType {BRANCH_ORIGIN, MUTATION_ORIGIN, BASE_LEAF_ORIGIN} @export var mutation_weight_base := 10 @export var mutation_weight_loss := 3 @export var mutation_weight_gain := 1 + @export var seed_texture_sets: Array[SeedTextureSet] @export var base_y_offset := -50.0 @@ -75,6 +76,9 @@ func shuffle_weighted(array: Array, weights: Array[int]): array[i] = originalArray[indices[i]] weights[i] = originalWeights[indices[i]] +func get_mutation_weight(level: int) -> int: + return 3 * level + func build_seed_texture(random_seed: int) -> Texture: rng.seed = random_seed @@ -129,7 +133,9 @@ func build_plant_texture(plant_data: PlantData) -> Texture: for mutation in plant_data.mutations: if mutation.id in parts_mutation_associations: parts_to_place[OriginType.MUTATION_ORIGIN].append(parts_mutation_associations[mutation.id].parts) - mutation_weights.append(mutation_weight_base) + var mutation_weight := get_mutation_weight(mutation.level) + mutation_weights.append(mutation_weight) + weight_per_origin_type[OriginType.MUTATION_ORIGIN] += mutation_weight var flipped: bool = rng.randi() % 2 == 0 @@ -195,6 +201,9 @@ func get_part(all_parts: Dictionary[OriginType, Array], weight_per_origin_type: weight_per_origin_type[((origin + 2) % 3) as OriginType] += origin_weight_gain return all_parts[origin][ind] else: # find a mutation part to place + if weight_copy[originIndInd] < 0: + break + var parts_per_mutations: Array = all_parts[origin] shuffle_weighted(parts_per_mutations, mutation_weights) for mutation_parts_ind in range(parts_per_mutations.size()): diff --git a/entities/plants/test_sprites.tscn b/entities/plants/test_sprites.tscn index b9fe1a7..9e0b3f6 100644 --- a/entities/plants/test_sprites.tscn +++ b/entities/plants/test_sprites.tscn @@ -136,16 +136,41 @@ layout_mode = 2 [node name="Label2" type="Label" parent="Camera2D/CanvasLayer/VBoxContainer/Folder/VBoxContainer/AgeContainer" unique_id=115359272] layout_mode = 2 -text = "rand" +text = "rand :" [node name="RandomAge" type="CheckBox" parent="Camera2D/CanvasLayer/VBoxContainer/Folder/VBoxContainer/AgeContainer" unique_id=632428890] layout_mode = 2 -[node name="Label3" type="Label" parent="Camera2D/CanvasLayer/VBoxContainer/Folder/VBoxContainer/AgeContainer" unique_id=1871497862] +[node name="toAgeLabel" type="Label" parent="Camera2D/CanvasLayer/VBoxContainer/Folder/VBoxContainer/AgeContainer" unique_id=1871497862] +unique_name_in_owner = true layout_mode = 2 text = "to" [node name="EndAge" type="SpinBox" parent="Camera2D/CanvasLayer/VBoxContainer/Folder/VBoxContainer/AgeContainer" unique_id=155079103] +unique_name_in_owner = true +layout_mode = 2 + +[node name="MutationLvlContainer" type="HBoxContainer" parent="Camera2D/CanvasLayer/VBoxContainer/Folder/VBoxContainer" unique_id=245717208] +layout_mode = 2 + +[node name="Label" type="Label" parent="Camera2D/CanvasLayer/VBoxContainer/Folder/VBoxContainer/MutationLvlContainer" unique_id=1071712301] +layout_mode = 2 +text = "Mutation level : " + +[node name="Label2" type="Label" parent="Camera2D/CanvasLayer/VBoxContainer/Folder/VBoxContainer/MutationLvlContainer" unique_id=1969438517] +layout_mode = 2 +text = "Min" + +[node name="MinLvl" type="SpinBox" parent="Camera2D/CanvasLayer/VBoxContainer/Folder/VBoxContainer/MutationLvlContainer" unique_id=443508962] +unique_name_in_owner = true +layout_mode = 2 + +[node name="Label3" type="Label" parent="Camera2D/CanvasLayer/VBoxContainer/Folder/VBoxContainer/MutationLvlContainer" unique_id=883703881] +layout_mode = 2 +text = "Max" + +[node name="MaxLvl" type="SpinBox" parent="Camera2D/CanvasLayer/VBoxContainer/Folder/VBoxContainer/MutationLvlContainer" unique_id=615247987] +unique_name_in_owner = true layout_mode = 2 [node name="PossibleMutations" type="FoldableContainer" parent="Camera2D/CanvasLayer/VBoxContainer/Folder/VBoxContainer" unique_id=71622472] @@ -179,3 +204,5 @@ tile_set = ExtResource("3_3mb6h") [connection signal="value_changed" from="Camera2D/CanvasLayer/VBoxContainer/Folder/VBoxContainer/AgeContainer/StartAge" to="." method="_on_start_age_value_changed"] [connection signal="toggled" from="Camera2D/CanvasLayer/VBoxContainer/Folder/VBoxContainer/AgeContainer/RandomAge" to="." method="_on_random_age_toggled"] [connection signal="value_changed" from="Camera2D/CanvasLayer/VBoxContainer/Folder/VBoxContainer/AgeContainer/EndAge" to="." method="_on_end_age_value_changed"] +[connection signal="value_changed" from="Camera2D/CanvasLayer/VBoxContainer/Folder/VBoxContainer/MutationLvlContainer/MinLvl" to="." method="_on_min_lvl_value_changed"] +[connection signal="value_changed" from="Camera2D/CanvasLayer/VBoxContainer/Folder/VBoxContainer/MutationLvlContainer/MaxLvl" to="." method="_on_max_lvl_value_changed"]