extends Area2D class_name PlantSprite const PLANTED_SEED_CROP_WIDTH = 50 const PLANTED_SEED_POS_Y = 0 const MODULATE_PLANT_INFLUENCED_COLOR = Color("c599ffff") const ABOUT_TO_DYE_COLOR := Color("#fca67e") const ABOUT_TO_DYE_PERIOD := 1.0 signal harvest_animation_finished var last_updated_on_state: PlantData.State = PlantData.State.MATURE var stored_seed_image: Texture = null var is_action_affected : bool = false var is_inspected : bool = false var is_plant_influenced : bool = false var is_about_to_die : bool = false var about_to_dye_tween: Tween var target_modulate_color := Color.WHITE var elapsed_time := 0. 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: %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 func start_harvest_animation(): $AnimationPlayer.play("harvest") await $AnimationPlayer.animation_finished harvest_animation_finished.emit() func affect_preview(is_affected: bool = true): is_action_affected = is_affected 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 func _process(delta): elapsed_time += delta var target_modulate = Color.WHITE if is_action_affected: target_modulate = InspectableEntity.MODULATE_AFFECTED_COLOR elif is_inspected: target_modulate = InspectableEntity.MODULATE_INSPECTED_COLOR elif is_plant_influenced: target_modulate = MODULATE_PLANT_INFLUENCED_COLOR elif is_about_to_die: var blink_value = (cos((elapsed_time * (2 * PI)) * ABOUT_TO_DYE_PERIOD) + 1)/2 target_modulate = target_modulate.lerp(ABOUT_TO_DYE_COLOR, blink_value) modulate = modulate.lerp(target_modulate, 0.8)