Add project files.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Nodify.StateMachine
|
||||
{
|
||||
public class DebugBlackboardDecorator : Blackboard
|
||||
{
|
||||
public static BlackboardKey StateDelayKey { get; } = "__state.delay";
|
||||
public static BlackboardKey TransitionDelayKey { get; } = "__transition.delay";
|
||||
|
||||
private Blackboard? _blackboard;
|
||||
|
||||
public event Action<BlackboardKey, object?>? ValueChanged;
|
||||
|
||||
public DebugBlackboardDecorator(Blackboard? blackboard = default)
|
||||
=> Attach(blackboard);
|
||||
|
||||
public override IReadOnlyCollection<BlackboardKey> Keys => _blackboard?.Keys ?? Array.Empty<BlackboardKey>();
|
||||
|
||||
public override void Remove(BlackboardKey key)
|
||||
=> _blackboard?.Remove(key);
|
||||
|
||||
public override void Clear()
|
||||
=> _blackboard?.Clear();
|
||||
|
||||
public override T? GetObject<T>(BlackboardKey key) where T : class
|
||||
=> _blackboard?.GetObject<T>(key);
|
||||
|
||||
public override T? GetValue<T>(BlackboardKey key)
|
||||
=> _blackboard?.GetValue<T>(key);
|
||||
|
||||
public override void Set(BlackboardKey key, object? value)
|
||||
{
|
||||
_blackboard?.Set(key, value);
|
||||
ValueChanged?.Invoke(key, value);
|
||||
}
|
||||
|
||||
public override bool HasKey(BlackboardKey key)
|
||||
=> _blackboard?.HasKey(key) ?? false;
|
||||
|
||||
public override object? GetObject(BlackboardKey key)
|
||||
=> _blackboard?.GetObject(key);
|
||||
|
||||
public virtual void Attach(Blackboard? blackboard)
|
||||
{
|
||||
_blackboard = blackboard;
|
||||
|
||||
Set(StateDelayKey, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Nodify.StateMachine
|
||||
{
|
||||
public class DebugStateDecorator : State
|
||||
{
|
||||
private readonly State _state;
|
||||
|
||||
public DebugStateDecorator(State state) : base(state.Id, state.Transitions)
|
||||
{
|
||||
_state = state;
|
||||
}
|
||||
|
||||
public override async Task Activate(Blackboard blackboard)
|
||||
{
|
||||
int? delay = blackboard.GetValue<int>(DebugBlackboardDecorator.StateDelayKey);
|
||||
|
||||
await Task.Delay(Math.Max(10, delay ?? 10));
|
||||
|
||||
await _state.Activate(blackboard);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Nodify.StateMachine
|
||||
{
|
||||
public class DebugTransitionDecorator : Transition
|
||||
{
|
||||
private readonly Transition _transition;
|
||||
|
||||
public DebugTransitionDecorator(Transition transition) : base(transition.From, transition.To)
|
||||
{
|
||||
_transition = transition;
|
||||
}
|
||||
|
||||
public override async Task<bool> CanActivate(Blackboard blackboard)
|
||||
{
|
||||
int? delay = blackboard.GetValue<int>(DebugBlackboardDecorator.TransitionDelayKey);
|
||||
|
||||
if (delay > 0)
|
||||
{
|
||||
await Task.Delay(delay.Value);
|
||||
}
|
||||
|
||||
return await _transition.CanActivate(blackboard);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user