ajout des graines procédurales et des cinamatiques
This commit is contained in:
@@ -3,7 +3,16 @@ extends Node
|
||||
const IMAGE_WIDTH := 1000
|
||||
const IMAGE_HEIGHT := 2000
|
||||
|
||||
const PLACEHOLDER_SEED_TEXTURE: Texture = preload("res://entities/plants/assets/sprites/default/seed.png")
|
||||
const SEED_TEXTURE_SIZE = 150
|
||||
|
||||
const COLOR_PALETTE : Array[Color] = [
|
||||
Color("#78AEBA"),
|
||||
Color("#A7B35B"),
|
||||
Color("#DB6B75"),
|
||||
Color("#EC8E49"),
|
||||
Color("#F9FFCE"),
|
||||
]
|
||||
|
||||
const PLACEHOLDER_MATURE_TEXTURE: Texture = preload("res://entities/plants/assets/sprites/default/mature.png")
|
||||
const PLACEHOLDER_GROWING_TEXTURE: Texture = preload("res://entities/plants/assets/sprites/default/growing.png")
|
||||
|
||||
@@ -13,11 +22,34 @@ const PLACEHOLDER_GROWING_TEXTURE: Texture = preload("res://entities/plants/asse
|
||||
@export var branches: Array[PlantPart]
|
||||
@export var n_branches: int = 2
|
||||
@export var parts_mutation_associations: Dictionary[String, PartMutationAssociation]
|
||||
@export var seed_texture_sets: Array[SeedTextureSet]
|
||||
|
||||
var rng := RandomNumberGenerator.new()
|
||||
|
||||
func build_seed_texture(_random_seed: int) -> Texture:
|
||||
return PLACEHOLDER_SEED_TEXTURE
|
||||
func build_seed_texture(random_seed: int) -> Texture:
|
||||
rng.seed = random_seed
|
||||
|
||||
var texture_set : SeedTextureSet = pick_random(seed_texture_sets)
|
||||
var 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)
|
||||
modulate_image(color_image, pick_random(COLOR_PALETTE))
|
||||
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)
|
||||
image.blend_rect(outline_image, Rect2i(0,0,SEED_TEXTURE_SIZE,SEED_TEXTURE_SIZE),Vector2i.ZERO)
|
||||
|
||||
if rng.randi()%2 == 0:
|
||||
image.flip_x()
|
||||
|
||||
return ImageTexture.create_from_image(image)
|
||||
|
||||
func build_plant_texture(plant_data: PlantData) -> Texture:
|
||||
rng.seed = plant_data.random_seed
|
||||
@@ -156,3 +188,8 @@ func build_plant_texture(plant_data: PlantData) -> Texture:
|
||||
|
||||
func pick_random(array: Array):
|
||||
return array[rng.randi_range(0, array.size() - 1)]
|
||||
|
||||
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)
|
||||
Reference in New Issue
Block a user