using System.Threading.Tasks; using Cirno.Scripts; using Cirno.Scripts.Components; using Godot; using GTweens.Builders; using GTweens.Tweens; using GTweensGodot.Extensions; public partial class PlayerAnimationProvider : Node2D { [Export] public AnimatedSprite2D _animatedSprite {get; private set;} [Export] private PackedScene _deathParticles; [Export] private GpuParticles2D _shieldParticles; [ExportCategory("Animation Names")] [Export] public StringName WalkRightAnimationName {get; private set;} = "walk_right"; [Export] public StringName WalkLeftAnimationName {get; private set;} = "walk_left"; [Export] public StringName WalkDownAnimationName {get; private set;} = "walk_down"; [Export] public StringName WalkUpAnimationName {get; private set;} = "walk_up"; [ExportCategory("Shaders")] [Export] public ShaderMaterial BlinkMaterial {get; private set;} [Export] public StringName BlinkShaderPropertyName { get; private set; } = new("blink_intensity"); [Export] public StringName TeleportProgressPropertyName { get; private set; } = new("teleport_progress"); [Export] public StringName ScanlineDensityPropertyName { get; private set; } = new("scanline_density"); private GTween _blinkTween; public void ShowSprite() { _animatedSprite.Show(); } public void HideSprite() { _animatedSprite.Hide(); } public void SetAnimation(Vector2 velocity) { if (velocity.X == 0 && velocity.Y == 0) { _animatedSprite.SpeedScale = 0; } else { _animatedSprite.SpeedScale = 1; } if (velocity.X > 0) { _animatedSprite.Play(WalkRightAnimationName); } else if (velocity.X < 0) { _animatedSprite.Play(WalkLeftAnimationName); } else if (velocity.Y > 0) { _animatedSprite.Play(WalkDownAnimationName); } else if (velocity.Y < 0) { _animatedSprite.Play(WalkUpAnimationName); } } public void Blink() { if (BlinkMaterial == null) return; _animatedSprite.Material = BlinkMaterial; var material = ((ShaderMaterial)_animatedSprite.Material); _blinkTween?.Kill(); _blinkTween = GTweenSequenceBuilder.New() .Append(material.TweenPropertyFloat(BlinkShaderPropertyName, 1f, 0f)) .Append(material.TweenPropertyFloat(BlinkShaderPropertyName, 0f, 0.5f)) .Build(); _blinkTween.Play(); } public void PlayTeleportAnimation() { if (BlinkMaterial == null) return; _animatedSprite.Material = BlinkMaterial; var material = ((ShaderMaterial)_animatedSprite.Material); _blinkTween?.Kill(); _blinkTween = GTweenSequenceBuilder.New() .Append(material.TweenPropertyFloat(TeleportProgressPropertyName, 0f, 0f)) .Append(material.TweenPropertyFloat(ScanlineDensityPropertyName, 0f, 0f)) .Append(material.TweenPropertyFloat(ScanlineDensityPropertyName,50f,0.5f)) .Join(material.TweenPropertyFloat(TeleportProgressPropertyName, 1f,0.5f)) .Build(); _blinkTween.Play(); } public void PlayUnteleportAnimation() { if (BlinkMaterial == null) return; _animatedSprite.Material = BlinkMaterial; var material = ((ShaderMaterial)_animatedSprite.Material); _blinkTween?.Kill(); _blinkTween = GTweenSequenceBuilder.New() .Append(material.TweenPropertyFloat(TeleportProgressPropertyName, 1f, 0f)) .Append(material.TweenPropertyFloat(ScanlineDensityPropertyName, 50f, 0f)) .Append(material.TweenPropertyFloat(ScanlineDensityPropertyName,0f,0.5f)) .Join(material.TweenPropertyFloat(TeleportProgressPropertyName, 0f,0.5f)) .Build(); _blinkTween.Play(); } private void SetShaderTeleportProgress(float value) { ((ShaderMaterial)_animatedSprite.Material).SetShaderParameter("teleport_progress", value); } private void SetShaderScanlineDensity(float value) { ((ShaderMaterial)_animatedSprite.Material).SetShaderParameter("scanline_density", value); } private void SetShaderBlinkIntensity(float newValue) { ((ShaderMaterial)_animatedSprite.Material).SetShaderParameter("blink_intensity", newValue); } public void PlayDeathAnimation() { this.CreateSibling(_deathParticles, this.GlobalPosition); _animatedSprite.Visible = false; } public void PlayShieldAnimation() { _shieldParticles.Emitting = true; } }