working plant builder but not seeds oupsi
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
extends Node
|
||||
|
||||
@export var n_plants_to_generate: int = 1
|
||||
@export var n_plants_per_row: int = 0
|
||||
@export var n_to_generate: int = 5
|
||||
@export var n_per_row: int = 5
|
||||
@export var n_mutation_per_plant: int
|
||||
@export var space_between_plants: float
|
||||
@export var randomize_pos: bool
|
||||
@export var random_pos_offset: float
|
||||
@export var start_state: PlantData.State = PlantData.State.MATURE
|
||||
@export var random_state := false
|
||||
@export var end_state: PlantData.State = PlantData.State.MATURE
|
||||
|
||||
func _ready():
|
||||
%ZoomLevel.value = %Camera2D.zoom.x
|
||||
%NPlants.value = n_plants_to_generate
|
||||
%N.value = n_to_generate
|
||||
%NPerRow.value = n_per_row
|
||||
%NMutationsPerPlant.value = n_mutation_per_plant
|
||||
%RandomizePos.button_pressed = randomize_pos
|
||||
%RandomizeOffset.value = random_pos_offset
|
||||
@@ -24,28 +28,56 @@ func generate_plants():
|
||||
for child in %Plants.get_children():
|
||||
child.free()
|
||||
|
||||
for i in n_plants_to_generate:
|
||||
for i in n_to_generate:
|
||||
print("Generate plant :")
|
||||
var plant_pos_x = (i % n_plants_per_row) * space_between_plants
|
||||
var plant_pos_x = (i % n_per_row) * space_between_plants
|
||||
@warning_ignore("integer_division")
|
||||
var plant_pos_y = (i / n_plants_per_row) * space_between_plants
|
||||
var plant_pos_y = (i / n_per_row) * space_between_plants
|
||||
var plant_position := Vector2(plant_pos_x, plant_pos_y)
|
||||
if randomize_pos:
|
||||
plant_position += randf_range(0, random_pos_offset) * Vector2.ONE.rotated(randf_range(0, 2 * PI))
|
||||
var plant_data: PlantData = PlantData.new(plant_position)
|
||||
plant_data.day = plant_data.get_growing_time()
|
||||
var plant_state := start_state
|
||||
if random_state:
|
||||
plant_state = randi_range(start_state, end_state) as PlantData.State
|
||||
if plant_state == PlantData.State.PLANTED:
|
||||
plant_data.day = 0
|
||||
elif plant_state == PlantData.State.GROWING:
|
||||
plant_data.day = 1
|
||||
elif plant_state == PlantData.State.MATURE:
|
||||
plant_data.day = plant_data.get_growing_time()
|
||||
elif plant_state == PlantData.State.DEAD:
|
||||
plant_data.day = plant_data.get_lifetime()
|
||||
for j in n_mutation_per_plant:
|
||||
plant_data.mutations.append(plant_data.archetype.available_mutations.pick_random())
|
||||
var plant: Plant = Plant.new(plant_data)
|
||||
print(plant.data.plant_name)
|
||||
%Plants.add_child(plant)
|
||||
plant.set_owner(self )
|
||||
# plant.set_owner(self )
|
||||
plant.global_position = plant_position
|
||||
|
||||
func generate_seeds():
|
||||
for child in %Plants.get_children():
|
||||
child.free()
|
||||
|
||||
for i in n_to_generate:
|
||||
print("Generate seed :")
|
||||
var seed_pos_x = (i % n_per_row) * space_between_plants
|
||||
@warning_ignore("integer_division")
|
||||
var seed_pos_y = (i / n_per_row) * space_between_plants
|
||||
var seed_position := Vector2(seed_pos_x, seed_pos_y)
|
||||
if randomize_pos:
|
||||
seed_position += randf_range(0, random_pos_offset) * Vector2.ONE.rotated(randf_range(0, 2 * PI))
|
||||
var graine := Seed.generate_random()
|
||||
var seedItem := ItemObject.new(graine)
|
||||
%Plants.add_child(seedItem)
|
||||
seedItem.global_position = seed_position
|
||||
|
||||
func _on_generate_plants_pressed() -> void:
|
||||
generate_plants()
|
||||
|
||||
func _on_generate_seeds_pressed() -> void:
|
||||
generate_seeds()
|
||||
|
||||
func _on_zoom_level_value_changed(value: float) -> void:
|
||||
%Camera2D.zoom = Vector2.ONE * value
|
||||
@@ -57,10 +89,10 @@ func _on_reset_zoom_pressed() -> void:
|
||||
|
||||
|
||||
func _on_n_plants_value_changed(value: float) -> void:
|
||||
n_plants_to_generate = int(value)
|
||||
n_to_generate = int(value)
|
||||
|
||||
func _on_n_plants_per_row_value_changed(value: float) -> void:
|
||||
n_plants_per_row = int(value)
|
||||
n_per_row = int(value)
|
||||
|
||||
func _on_n_mutations_per_plant_value_changed(value: float) -> void:
|
||||
n_mutation_per_plant = int(value)
|
||||
@@ -70,3 +102,12 @@ func _on_randomize_pos_toggled(toggled_on: bool) -> void:
|
||||
|
||||
func _on_randomize_offset_value_changed(value: float) -> void:
|
||||
random_pos_offset = value
|
||||
|
||||
func _on_start_age_value_changed(value: float) -> void:
|
||||
start_state = int(value) as PlantData.State
|
||||
|
||||
func _on_random_age_toggled(toggled_on: bool) -> void:
|
||||
random_state = toggled_on
|
||||
|
||||
func _on_end_age_value_changed(value: float) -> void:
|
||||
end_state = int(value) as PlantData.State
|
||||
|
||||
@@ -5,7 +5,7 @@ const IMAGE_HEIGHT := 2048
|
||||
|
||||
const SEED_TEXTURE_SIZE = 150
|
||||
|
||||
const COLOR_PALETTE : Array[Color] = [
|
||||
const COLOR_PALETTE: Array[Color] = [
|
||||
Color("#78AEBA"),
|
||||
Color("#A7B35B"),
|
||||
Color("#DB6B75"),
|
||||
@@ -75,25 +75,21 @@ func shuffle_weighted(array: Array, weights: Array[int]):
|
||||
func build_seed_texture(random_seed: int) -> Texture:
|
||||
rng.seed = random_seed
|
||||
|
||||
var texture_set : SeedTextureSet = pick_random(seed_texture_sets)
|
||||
var sedd_image := Image.create(SEED_TEXTURE_SIZE,SEED_TEXTURE_SIZE, false, Image.FORMAT_RGBA8)
|
||||
var texture_set: SeedTextureSet = pick_random(seed_texture_sets)
|
||||
var seed_image := Image.create(SEED_TEXTURE_SIZE, SEED_TEXTURE_SIZE, false, Image.FORMAT_RGBA8)
|
||||
|
||||
for color_texture in texture_set.color_textures:
|
||||
var color_image = color_texture.get_image().duplicate()
|
||||
color_image.resize(SEED_TEXTURE_SIZE,SEED_TEXTURE_SIZE)
|
||||
for color_image in texture_set.color_images:
|
||||
color_image.resize(SEED_TEXTURE_SIZE, SEED_TEXTURE_SIZE)
|
||||
modulate_image(color_image, pick_random(COLOR_PALETTE))
|
||||
sedd_image.blend_rect(
|
||||
color_image,
|
||||
Rect2i(0,0,SEED_TEXTURE_SIZE,SEED_TEXTURE_SIZE),
|
||||
Vector2i.ZERO
|
||||
)
|
||||
if texture_set.outline_texture:
|
||||
var outline_image = texture_set.outline_texture.get_image().duplicate()
|
||||
outline_image.resize(SEED_TEXTURE_SIZE,SEED_TEXTURE_SIZE)
|
||||
sedd_image.blend_rect(outline_image, Rect2i(0,0,SEED_TEXTURE_SIZE,SEED_TEXTURE_SIZE),Vector2i.ZERO)
|
||||
seed_image.blend_rect(color_image, Rect2i(0, 0, SEED_TEXTURE_SIZE, SEED_TEXTURE_SIZE), Vector2i.ZERO)
|
||||
|
||||
if texture_set.outline_image:
|
||||
var outline_image = texture_set.outline_image
|
||||
outline_image.resize(SEED_TEXTURE_SIZE, SEED_TEXTURE_SIZE)
|
||||
seed_image.blend_rect(outline_image, Rect2i(0, 0, SEED_TEXTURE_SIZE, SEED_TEXTURE_SIZE), Vector2i.ZERO)
|
||||
|
||||
if rng.randi()%2 == 0:
|
||||
sedd_image.flip_x()
|
||||
if rng.randi() % 2 == 0:
|
||||
seed_image.flip_x()
|
||||
|
||||
return ImageTexture.create_from_image(image)
|
||||
|
||||
@@ -125,7 +121,7 @@ func build_plant_texture(plant_data: PlantData) -> Texture:
|
||||
parts_to_place[OriginType.MUTATION_ORIGIN].append(parts_mutation_associations[mutation.id].parts)
|
||||
mutation_weights.append(mutation_weight_base)
|
||||
|
||||
var base_image_coord = blend_part(image_center, Vector2.ZERO, base_part)
|
||||
var base_image_coord = blend_part(image_center, -base_part.root.position, base_part)
|
||||
populate_part(parts_to_place, weight_per_origin_type, mutation_weights, base_part, base_image_coord)
|
||||
|
||||
texture = ImageTexture.create_from_image(image)
|
||||
@@ -202,7 +198,7 @@ func blend_part(parent_image_coord: Vector2i, attach_position: Vector2, part_to_
|
||||
image.blend_rect(part_image, Rect2i(Vector2i.ZERO, part_to_blend.image.get_size()), part_image_coord - part_image_center)
|
||||
return part_image_coord
|
||||
|
||||
func modulate_image(i : Image, color : Color):
|
||||
func modulate_image(i: Image, color: Color):
|
||||
for x in i.get_size().x:
|
||||
for y in i.get_size().y:
|
||||
i.set_pixel(x,y, i.get_pixel(x,y)*color)
|
||||
i.set_pixel(x, y, i.get_pixel(x, y) * color)
|
||||
|
||||
@@ -1,5 +1,20 @@
|
||||
extends Resource
|
||||
class_name SeedTextureSet
|
||||
|
||||
@export var color_textures : Array[Texture]
|
||||
@export var outline_texture : Texture
|
||||
@export var color_textures: Array[Texture]
|
||||
@export var outline_texture: Texture
|
||||
|
||||
var color_images: Array[Image]: get = get_color_images
|
||||
var outline_image: Image: get = get_outline_image
|
||||
|
||||
func get_color_images() -> Array[Image]:
|
||||
if color_images == null:
|
||||
color_images = []
|
||||
for texture in color_textures:
|
||||
color_images.append(texture.get_image())
|
||||
return color_images
|
||||
|
||||
func get_outline_image() -> Image:
|
||||
if outline_image == null:
|
||||
outline_image = outline_texture.get_image()
|
||||
return outline_image
|
||||
|
||||
Reference in New Issue
Block a user