mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-14 09:53:47 +00:00
Event System
This commit is contained in:
parent
797e24d766
commit
f379eac5c3
10 changed files with 336 additions and 10 deletions
56
Scripts/Resources/Events/ActivateEvent.cs
Normal file
56
Scripts/Resources/Events/ActivateEvent.cs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Resources.Events;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class ActivateEvent : EventResource
|
||||
{
|
||||
[Export] public ActivationType ActivationType = ActivationType.Toggle;
|
||||
|
||||
[Export] public Array<NodePath> Targets;
|
||||
|
||||
private Node2D _parent;
|
||||
|
||||
private bool _isComplete = false;
|
||||
|
||||
protected void ActivateTargets()
|
||||
{
|
||||
foreach (var activationTarget in Targets)
|
||||
{
|
||||
ActivateTarget(_parent.GetNode<Node2D>(activationTarget));
|
||||
}
|
||||
}
|
||||
|
||||
private bool ActivateTarget(Node2D activationTarget)
|
||||
{
|
||||
if (activationTarget is not IActivable target)
|
||||
{
|
||||
GD.PrintErr($"Target {activationTarget.Name} is not activable");
|
||||
return false;
|
||||
}
|
||||
|
||||
target?.Activate(ActivationType);
|
||||
|
||||
GD.Print($"{activationTarget.Name} activated");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Start(Node2D parent)
|
||||
{
|
||||
_parent = parent;
|
||||
ActivateTargets();
|
||||
_isComplete = true;
|
||||
}
|
||||
|
||||
public override void UpdateEvent(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool IsComplete()
|
||||
{
|
||||
return _isComplete;
|
||||
}
|
||||
}
|
||||
52
Scripts/Resources/Events/DialogueStartEvent.cs
Normal file
52
Scripts/Resources/Events/DialogueStartEvent.cs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources.Events;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class DialogueStartEvent : EventResource
|
||||
{
|
||||
[Export] public string TimelineName = "timeline";
|
||||
private Node _dialogic;
|
||||
private GameManager _gameManager;
|
||||
private bool _isComplete = false;
|
||||
|
||||
public override void Start(Node2D parent)
|
||||
{
|
||||
_gameManager = parent.GetGameManager();
|
||||
|
||||
_dialogic = parent.GetNode("/root/Dialogic");
|
||||
|
||||
_gameManager.ChangeState(GameState.Dialogue);
|
||||
|
||||
_dialogic.Connect("timeline_ended", Callable.From(OnTimelineEnded));
|
||||
|
||||
_dialogic.Call("start", TimelineName);
|
||||
}
|
||||
|
||||
private void OnTimelineEnded()
|
||||
{
|
||||
|
||||
if (_dialogic.IsConnected("timeline_ended", Callable.From(OnTimelineEnded)))
|
||||
{
|
||||
_dialogic.Disconnect("timeline_ended", Callable.From(OnTimelineEnded));
|
||||
}
|
||||
|
||||
DialogueEndAction();
|
||||
}
|
||||
|
||||
private void DialogueEndAction()
|
||||
{
|
||||
_gameManager.ChangeState(GameState.Playing);
|
||||
_isComplete = true;
|
||||
}
|
||||
|
||||
public override void UpdateEvent(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool IsComplete()
|
||||
{
|
||||
return _isComplete;
|
||||
}
|
||||
}
|
||||
12
Scripts/Resources/Events/EventResource.cs
Normal file
12
Scripts/Resources/Events/EventResource.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources.Events;
|
||||
|
||||
[GlobalClass]
|
||||
public abstract partial class EventResource : Resource
|
||||
{
|
||||
[Export] public bool WaitForCompletion = true;
|
||||
public abstract void Start(Node2D parent);
|
||||
public abstract void UpdateEvent(double delta);
|
||||
public abstract bool IsComplete();
|
||||
}
|
||||
56
Scripts/Resources/Events/MovePlayerEvent.cs
Normal file
56
Scripts/Resources/Events/MovePlayerEvent.cs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
using System.Threading.Tasks;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources.Events;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class MovePlayerEvent : EventResource
|
||||
{
|
||||
[Export]
|
||||
public Vector2 RelativeTargetPosition = Vector2.Zero;
|
||||
|
||||
[Export]
|
||||
public float MovementTime = 1f;
|
||||
|
||||
[Export]
|
||||
public Tween.EaseType EaseType = Tween.EaseType.InOut;
|
||||
|
||||
[Export]
|
||||
public Tween.TransitionType TransitionType = Tween.TransitionType.Linear;
|
||||
|
||||
private bool _isComplete = false;
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
public override void Start(Node2D parentNode)
|
||||
{
|
||||
_gameManager = parentNode.GetGameManager();
|
||||
_isComplete = false;
|
||||
|
||||
_ = MovePlayer();
|
||||
}
|
||||
|
||||
protected async Task MovePlayer()
|
||||
{
|
||||
_gameManager.Player.RequestMovementDisable(true);
|
||||
|
||||
Tween tween = _gameManager.GetTree().CreateTween();
|
||||
tween.SetEase(EaseType);
|
||||
tween.SetTrans(TransitionType);
|
||||
tween.TweenProperty(_gameManager.Player, "global_position", _gameManager.Player.GlobalPosition + RelativeTargetPosition, MovementTime);
|
||||
|
||||
// Wait for the tween to finish
|
||||
await ToSignal(tween, "finished");
|
||||
|
||||
_gameManager.Player.RequestMovementDisable(false);
|
||||
|
||||
_isComplete = true;
|
||||
}
|
||||
|
||||
public override void UpdateEvent(double delta) { }
|
||||
|
||||
public override bool IsComplete()
|
||||
{
|
||||
return _isComplete;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue