ajout des graines procédurales et des cinamatiques
This commit is contained in:
@@ -21,6 +21,8 @@ const SPRITE_SCENE : PackedScene = preload("res://entities/plants/plant_sprite.t
|
||||
@onready var collision_shape: CollisionShape2D
|
||||
@onready var influence_zone : PlantInfluenceZone
|
||||
|
||||
var harvested = false
|
||||
|
||||
func _init(
|
||||
_data : PlantData
|
||||
):
|
||||
@@ -31,7 +33,7 @@ func _ready():
|
||||
collision_shape = generate_collision_shape()
|
||||
influence_zone = generate_influence_zone()
|
||||
|
||||
plant_sprite.update_plant_sprite(data, false)
|
||||
plant_sprite.setup_plant_sprite(data)
|
||||
|
||||
func pointer_text() -> String:
|
||||
return data.plant_name
|
||||
@@ -103,6 +105,8 @@ func harvest():
|
||||
for m in data.mutations:
|
||||
m._start_harvested_effect(self)
|
||||
|
||||
harvested = true
|
||||
|
||||
plant_sprite.start_harvest_animation()
|
||||
await plant_sprite.harvest_animation_finished
|
||||
disappear()
|
||||
|
||||
@@ -9,6 +9,11 @@ const PARTICLES_SCENE : PackedScene = preload("res://common/vfx/particles/effect
|
||||
signal harvest_animation_finished
|
||||
|
||||
var last_updated_on_state : PlantData.State = PlantData.State.MATURE
|
||||
var stored_seed_image : Texture = null
|
||||
|
||||
func setup_plant_sprite(plant_data : PlantData):
|
||||
%PlantedSeed.texture = PlantTextureBuilder.build_seed_texture(plant_data.plant_name.hash())
|
||||
update_plant_sprite(plant_data,true)
|
||||
|
||||
func update_plant_sprite(plant_data : PlantData, with_animation = false):
|
||||
if with_animation:
|
||||
@@ -17,8 +22,7 @@ func update_plant_sprite(plant_data : PlantData, with_animation = false):
|
||||
|
||||
%Sprite.flip_h = true if plant_data.random_seed%2 == 0 else false
|
||||
%Sprite.texture = PlantTextureBuilder.build_plant_texture(plant_data)
|
||||
|
||||
%PlantedSeed.texture = PlantTextureBuilder.build_seed_texture(plant_data.random_seed)
|
||||
|
||||
%PlantedSeed.visible = plant_data.get_state() == PlantData.State.PLANTED
|
||||
|
||||
# %PlantedSeed.region_rect = Rect2(
|
||||
|
||||
48
entities/plants/scripts/procedural_seed.gd
Normal file
48
entities/plants/scripts/procedural_seed.gd
Normal file
@@ -0,0 +1,48 @@
|
||||
@tool
|
||||
extends Node2D
|
||||
|
||||
|
||||
@export var color_1_texture : Texture
|
||||
@export var color_2_texture : Texture
|
||||
@export var outline_texture : Texture
|
||||
|
||||
@export_tool_button("Redraw", "Callable") var redraw_action = func(): create_image()
|
||||
|
||||
func _ready():
|
||||
create_image()
|
||||
|
||||
func create_image():
|
||||
|
||||
var image := Image.create(TEXTURE_SIZE,TEXTURE_SIZE, false, Image.FORMAT_RGBA8)
|
||||
|
||||
if color_2_texture:
|
||||
var color_2_image = color_2_texture.get_image()
|
||||
color_2_image.resize(TEXTURE_SIZE,TEXTURE_SIZE)
|
||||
|
||||
image.blend_rect(
|
||||
modulated_image(color_2_image, COLOR_PALETTE.pick_random()),
|
||||
Rect2i(0,0,TEXTURE_SIZE,TEXTURE_SIZE),
|
||||
Vector2i.ZERO
|
||||
)
|
||||
if color_1_texture:
|
||||
var color_1_image = color_1_texture.get_image()
|
||||
color_1_image.resize(TEXTURE_SIZE,TEXTURE_SIZE)
|
||||
image.blend_rect(
|
||||
modulated_image(color_1_image, COLOR_PALETTE.pick_random()),
|
||||
Rect2i(0,0,TEXTURE_SIZE,TEXTURE_SIZE),
|
||||
Vector2i.ZERO
|
||||
)
|
||||
if outline_texture:
|
||||
var outline_image = outline_texture.get_image()
|
||||
outline_image.resize(TEXTURE_SIZE,TEXTURE_SIZE)
|
||||
image.blend_rect(outline_image, Rect2i(0,0,TEXTURE_SIZE,TEXTURE_SIZE),Vector2i.ZERO)
|
||||
|
||||
ImageTexture.create_from_image(image)
|
||||
|
||||
func modulated_image(i : Image, color : Color) -> Image:
|
||||
var ret = i.duplicate()
|
||||
for x in i.get_size().x:
|
||||
for y in i.get_size().y:
|
||||
ret.set_pixel(x,y, i.get_pixel(x,y)*color)
|
||||
return ret
|
||||
|
||||
1
entities/plants/scripts/procedural_seed.gd.uid
Normal file
1
entities/plants/scripts/procedural_seed.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://by1m5q6q53xxp
|
||||
@@ -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)
|
||||
@@ -0,0 +1,5 @@
|
||||
extends Resource
|
||||
class_name SeedTextureSet
|
||||
|
||||
@export var color_textures : Array[Texture]
|
||||
@export var outline_texture : Texture
|
||||
@@ -0,0 +1 @@
|
||||
uid://hs3i48clok85
|
||||
Reference in New Issue
Block a user