Densité de partie de plantes en fonction du niveau de mutation
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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()):
|
||||
|
||||
Reference in New Issue
Block a user