mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-16 12:13:46 +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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue