95 lines
1.9 KiB
C#
95 lines
1.9 KiB
C#
|
|
using Godot;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Rokojori
|
|
{
|
|
|
|
public class SequenceActionFinishedEvent
|
|
{
|
|
public int id;
|
|
public bool success;
|
|
}
|
|
|
|
[Tool]
|
|
[GlobalClass, Icon("res://addons/rokojori_action_library/Icons/SequenceAction.svg")]
|
|
public abstract partial class SequenceAction : Action
|
|
{
|
|
|
|
[ExportGroup("Debugging")]
|
|
[ExportToolButton("Clear Listeners")]
|
|
public Callable clearListeners => Callable.From(
|
|
()=>
|
|
{
|
|
onSequenceDone.ResetAndClearAll();
|
|
}
|
|
);
|
|
|
|
[Export]
|
|
public bool showRunningSequences = false;
|
|
|
|
[Export]
|
|
public int[] runningSequences = [];
|
|
|
|
|
|
int _dispatchCounter = 0;
|
|
|
|
public int GetLastSequenceActionID()
|
|
{
|
|
return _dispatchCounter;
|
|
}
|
|
|
|
public readonly EventSlot<SequenceActionFinishedEvent> onSequenceDone = new EventSlot<SequenceActionFinishedEvent>();
|
|
|
|
public int DispatchStart()
|
|
{
|
|
_dispatchCounter ++;
|
|
|
|
if ( showRunningSequences )
|
|
{
|
|
runningSequences = runningSequences.Add( _dispatchCounter );
|
|
}
|
|
|
|
return _dispatchCounter;
|
|
}
|
|
|
|
public void DispatchEnd( int id )
|
|
{
|
|
var ev = new SequenceActionFinishedEvent{ id = id, success = true };
|
|
onSequenceDone.DispatchEvent( ev );
|
|
|
|
if ( showRunningSequences )
|
|
{
|
|
runningSequences = runningSequences.Remove( _dispatchCounter );
|
|
}
|
|
}
|
|
|
|
public void DispatchCancelled( int id )
|
|
{
|
|
var ev = new SequenceActionFinishedEvent{ id = id, success = true };
|
|
onSequenceDone.DispatchEvent( ev );
|
|
|
|
if ( showRunningSequences )
|
|
{
|
|
runningSequences = runningSequences.Remove( _dispatchCounter );
|
|
}
|
|
}
|
|
|
|
public virtual void CancelAction( int id )
|
|
{
|
|
|
|
}
|
|
|
|
public int TriggerSequenceAndGetID()
|
|
{
|
|
var nextID = GetLastSequenceActionID() + 1;
|
|
|
|
Trigger();
|
|
|
|
return GetLastSequenceActionID() < nextID ? -1 : nextID;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
} |