* les plantes se placent désormais sur une grille * ajouts de curseurs relatifs à l'item * ajout de settings sur la sensibilité à la souris * ajout d'un défi en fin de run
76 lines
2.7 KiB
GDScript
76 lines
2.7 KiB
GDScript
extends Area2D
|
|
class_name PlantSprite
|
|
|
|
const PLANTED_SEED_CROP_WIDTH = 50
|
|
const PLANTED_SEED_POS_Y = 0
|
|
|
|
const PARTICLES_SCENE : PackedScene = preload("res://common/vfx/particles/effect_particles.tscn")
|
|
|
|
signal harvest_animation_finished
|
|
|
|
var last_updated_on_state : PlantData.State = PlantData.State.MATURE
|
|
var stored_seed_image : Texture = null
|
|
|
|
var display_lifetime_sprite : bool = false : set = set_display_lifetime_sprite
|
|
var sprite_modulate : Color = Color.WHITE : set = set_sprite_modulate
|
|
|
|
func setup_plant_sprite(plant_data : PlantData):
|
|
set_display_lifetime_sprite()
|
|
%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:
|
|
%AnimationPlayer.play("bump")
|
|
await %AnimationPlayer.animation_finished
|
|
|
|
%Sprite.flip_h = true if plant_data.random_seed%2 == 0 else false
|
|
%Sprite.texture = PlantTextureBuilder.build_plant_texture(plant_data)
|
|
|
|
%PlantedSeed.visible = plant_data.get_state() == PlantData.State.PLANTED
|
|
|
|
%LifetimeProgressBar.value = 100 * (float(plant_data.day)/plant_data.get_lifetime())
|
|
|
|
# %PlantedSeed.region_rect = Rect2(
|
|
# 0,
|
|
# PLANTED_SEED_POS_Y,
|
|
# %PlantedSeed.texture.get_width(),
|
|
# %PlantedSeed.texture.texture.get_height() - PLANTED_SEED_CROP_WIDTH + -1 * PLANTED_SEED_POS_Y,
|
|
# )
|
|
|
|
func generate_mutation_effects(plant : Plant):
|
|
for m in plant.data.mutations:
|
|
var particles_emitter : EffectParticles = PARTICLES_SCENE.instantiate() as EffectParticles
|
|
particles_emitter.setup_particles(
|
|
EffectParticles.Parameters.new(
|
|
m.get_icon(),
|
|
PlantMutation.get_rarity_color(m.get_rarity())
|
|
)
|
|
)
|
|
add_child(particles_emitter)
|
|
|
|
func start_harvest_animation():
|
|
$AnimationPlayer.play("harvest")
|
|
await $AnimationPlayer.animation_finished
|
|
harvest_animation_finished.emit()
|
|
|
|
func set_display_lifetime_sprite(d := display_lifetime_sprite):
|
|
display_lifetime_sprite = d
|
|
# if is_node_ready():
|
|
# %LifeTimeSprite.visible = d
|
|
|
|
func set_sprite_modulate(c := sprite_modulate):
|
|
sprite_modulate = c
|
|
if is_node_ready():
|
|
%Sprite.modulate = c
|
|
|
|
func affect_preview(is_affected : bool = true):
|
|
sprite_modulate = InspectableEntity.MODULATE_AFFECTED_COLOR if is_affected else Color.WHITE
|
|
|
|
func _on_body_entered(body: Node2D) -> void:
|
|
if body is Player && $AnimationPlayer.current_animation != "player_move":
|
|
$AnimationPlayer.play("player_move");
|
|
|
|
func play_bump_animation():
|
|
%AnimationPlayer.play("bump")
|
|
await %AnimationPlayer.animation_finished |