mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Remade resource script system
This commit is contained in:
parent
4261009c33
commit
029128c8b8
17 changed files with 576 additions and 386 deletions
|
|
@ -7,52 +7,66 @@ namespace Cirno.Scripts.AttackPatterns;
|
|||
[GlobalClass]
|
||||
public partial class MovementPattern : AttackPattern
|
||||
{
|
||||
[Export] private Vector2 relativeTargetPosition;
|
||||
[Export] private float moveDuration = 2f;
|
||||
[Export] private Tween.TransitionType transitionType = Tween.TransitionType.Linear;
|
||||
[Export] private Tween.EaseType easeType = Tween.EaseType.InOut;
|
||||
[Export] private AttackPattern shootingPattern;
|
||||
[Export] public Vector2 relativeTargetPosition;
|
||||
[Export] public float moveDuration = 2f;
|
||||
[Export] public Tween.TransitionType transitionType = Tween.TransitionType.Linear;
|
||||
[Export] public Tween.EaseType easeType = Tween.EaseType.InOut;
|
||||
[Export] public AttackPattern shootingPattern;
|
||||
|
||||
|
||||
private Tween tween;
|
||||
private bool isComplete = false;
|
||||
|
||||
protected IScriptHost Boss;
|
||||
|
||||
public override void Start(Node2D parent)
|
||||
public override IPatternMachine MakeMachine(Node2D parent)
|
||||
{
|
||||
if (parent is not IScriptHost boss)
|
||||
return;
|
||||
|
||||
Boss = boss;
|
||||
tween = parent.CreateTween();
|
||||
isComplete = false;
|
||||
|
||||
Vector2 targetPosition = (Boss?.HomePosition ?? parent.GlobalPosition) + this.relativeTargetPosition;
|
||||
|
||||
tween.TweenProperty(Parent, "position", targetPosition, moveDuration)
|
||||
.SetTrans(transitionType)
|
||||
.SetEase(easeType)
|
||||
.Finished += () => isComplete = true;
|
||||
|
||||
if (shootingPattern != null && !WaitForCompletion)
|
||||
{
|
||||
shootingPattern.Start(Parent);
|
||||
}
|
||||
return new MovementPatternMachine(this, parent);
|
||||
}
|
||||
|
||||
public override void UpdatePattern(double delta)
|
||||
public class MovementPatternMachine(MovementPattern pattern, Node2D parent) : IPatternMachine
|
||||
{
|
||||
if (shootingPattern != null && !WaitForCompletion)
|
||||
{
|
||||
shootingPattern.UpdatePattern(delta);
|
||||
}
|
||||
}
|
||||
public Node2D Parent => parent;
|
||||
public MovementPattern Pattern { get; } = pattern;
|
||||
|
||||
private IPatternMachine _machine;
|
||||
|
||||
public override bool IsComplete()
|
||||
{
|
||||
if (WaitForCompletion && shootingPattern != null)
|
||||
return isComplete && shootingPattern.IsComplete();
|
||||
return isComplete;
|
||||
private Tween tween;
|
||||
private bool isComplete = false;
|
||||
|
||||
protected IScriptHost Boss;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (parent is not IScriptHost boss)
|
||||
return;
|
||||
|
||||
Boss = boss;
|
||||
tween = parent.CreateTween();
|
||||
isComplete = false;
|
||||
|
||||
Vector2 targetPosition = (Boss?.HomePosition ?? parent.GlobalPosition) + Pattern.relativeTargetPosition;
|
||||
|
||||
tween.TweenProperty(Parent, "position", targetPosition, Pattern.moveDuration)
|
||||
.SetTrans(Pattern.transitionType)
|
||||
.SetEase(Pattern.easeType)
|
||||
.Finished += () => isComplete = true;
|
||||
|
||||
if (Pattern.shootingPattern != null && !Pattern.WaitForCompletion)
|
||||
{
|
||||
_machine = Pattern.shootingPattern.MakeMachine(parent);
|
||||
_machine.Start();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdatePattern(double delta)
|
||||
{
|
||||
if (_machine is not null && !Pattern.WaitForCompletion)
|
||||
{
|
||||
_machine.UpdatePattern(delta);
|
||||
//shootingPattern.UpdatePattern(delta);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsComplete()
|
||||
{
|
||||
if (Pattern.WaitForCompletion && _machine is not null)
|
||||
return isComplete && _machine.IsComplete();
|
||||
return isComplete;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue