Densité de partie de plantes en fonction du niveau de mutation

This commit is contained in:
Altaezio
2026-04-12 20:10:40 +02:00
parent a432d30c8b
commit e5dea5bb50
7 changed files with 121 additions and 30 deletions

View File

@@ -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])

View File

@@ -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"]

View File

@@ -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")])

View File

@@ -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)

View File

@@ -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()):

View File

@@ -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"]