2025-05-09 17:06:45 +02:00
|
|
|
|
using Cirno.Scripts.Resources;
|
|
|
|
|
|
using Godot;
|
2025-05-16 17:38:02 +02:00
|
|
|
|
using GTweens.Builders;
|
|
|
|
|
|
using GTweens.Easings;
|
|
|
|
|
|
using GTweens.Tweens;
|
|
|
|
|
|
using GTweensGodot.Extensions;
|
2025-05-09 17:06:45 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Cirno.Scripts.AttackPatterns;
|
|
|
|
|
|
|
|
|
|
|
|
[GlobalClass]
|
2025-06-03 10:11:09 +02:00
|
|
|
|
[Tool]
|
2025-05-09 17:06:45 +02:00
|
|
|
|
public partial class NodeMovementPattern : AttackPattern
|
|
|
|
|
|
{
|
|
|
|
|
|
[Export] private Vector2 relativeTargetPosition;
|
|
|
|
|
|
[Export] private float moveDuration = 2f;
|
2025-05-16 17:38:02 +02:00
|
|
|
|
// [Export] private Tween.TransitionType transitionType = Tween.TransitionType.Linear;
|
|
|
|
|
|
[Export] public GTweens.Easings.Easing EaseType { get; private set; } = Easing.Linear;
|
2025-05-09 17:06:45 +02:00
|
|
|
|
|
2025-06-11 15:28:26 +02:00
|
|
|
|
public override IPatternMachine MakeMachine(Node parent)
|
2025-05-09 17:06:45 +02:00
|
|
|
|
{
|
|
|
|
|
|
return new NodeMovementPatternMachine(this, parent);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-11 15:28:26 +02:00
|
|
|
|
public class NodeMovementPatternMachine(NodeMovementPattern pattern, Node parent) : IPatternMachine
|
2025-05-09 17:06:45 +02:00
|
|
|
|
{
|
2025-06-11 15:28:26 +02:00
|
|
|
|
public Node Parent => parent;
|
2025-05-09 17:06:45 +02:00
|
|
|
|
|
2025-05-16 17:38:02 +02:00
|
|
|
|
private GTween _tween;
|
2025-05-09 17:06:45 +02:00
|
|
|
|
private bool isComplete = false;
|
|
|
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Parent is not IScriptHost scriptHost)
|
|
|
|
|
|
{
|
|
|
|
|
|
GD.PrintErr("Parent was not a script host");
|
|
|
|
|
|
isComplete = true;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-11 15:28:26 +02:00
|
|
|
|
|
2025-05-16 17:38:02 +02:00
|
|
|
|
_tween?.Complete();
|
|
|
|
|
|
|
2025-05-09 17:06:45 +02:00
|
|
|
|
isComplete = false;
|
|
|
|
|
|
|
2025-06-11 15:28:26 +02:00
|
|
|
|
Vector2 targetPosition = (scriptHost?.HomePosition ?? scriptHost.ParentObject.GlobalPosition) + pattern.relativeTargetPosition;
|
2025-05-16 17:38:02 +02:00
|
|
|
|
|
|
|
|
|
|
_tween = GTweenSequenceBuilder.New()
|
|
|
|
|
|
.Append(scriptHost.ParentObject.TweenGlobalPosition(targetPosition, pattern.moveDuration))
|
|
|
|
|
|
.AppendCallback(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
isComplete = true;
|
|
|
|
|
|
})
|
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
|
_tween.SetEasing(pattern.EaseType);
|
2025-05-09 17:06:45 +02:00
|
|
|
|
|
2025-05-16 17:38:02 +02:00
|
|
|
|
_tween.Play();
|
|
|
|
|
|
// tween.TweenProperty(Parent, "global_position", targetPosition, pattern.moveDuration)
|
|
|
|
|
|
// .SetTrans(pattern.transitionType)
|
|
|
|
|
|
// .SetEase(pattern.easeType)
|
|
|
|
|
|
// .Finished += () =>
|
|
|
|
|
|
// {
|
|
|
|
|
|
// isComplete = true;
|
|
|
|
|
|
// };
|
2025-05-09 17:06:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdatePattern(double delta) { }
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsComplete()
|
|
|
|
|
|
{
|
|
|
|
|
|
return isComplete;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|