Skip to content

Commit

Permalink
Fixed bug, added obsolete methods
Browse files Browse the repository at this point in the history
  • Loading branch information
crashkonijn committed Dec 20, 2024
1 parent fb4b7b6 commit 489f9d2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
20 changes: 10 additions & 10 deletions Package/Runtime/CrashKonijn.Agent.Runtime/ActionProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@ namespace CrashKonijn.Agent.Runtime
public abstract class ActionProviderBase : MonoBehaviour, IActionProvider
{
private Dictionary<IAction, IActionDisabler> disablers = new();

public abstract IActionReceiver Receiver { get; set; }
public abstract void ResolveAction();

public bool IsDisabled(IAction action)
{
if (!this.disablers.TryGetValue(action, out var disabler))
return true;
return false;

if (this.Receiver is not IMonoAgent agent)
return true;
return false;

if (disabler.IsDisabled(agent))
return false;
return true;

this.Enable(action);
return true;
return false;
}

public void Enable(IAction action)
{
this.disablers.Remove(action);
}

public void Disable(IAction action, IActionDisabler disabler)
{
this.disablers[action] = disabler;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public bool IsExecutable(IActionReceiver agent, bool conditionsMet)

return true;
}

/// <summary>
/// Determines whether the action is enabled. This is used by the planner.
/// </summary>
Expand All @@ -172,6 +172,12 @@ public virtual bool IsEnabled(IActionReceiver receiver, IComponentReference refe
return !receiver.ActionProvider.IsDisabled(this);
}

[Obsolete("Use Enable(IActionReceiver receiver) instead")]
public void Enable()
{
throw new Exception("Use Enable(IActionReceiver receiver) instead");
}

/// <summary>
/// Enables the action.
/// </summary>
Expand All @@ -180,6 +186,12 @@ public void Enable(IActionReceiver receiver)
receiver.ActionProvider.Enable(this);
}

[Obsolete("Use Disable(IActionReceiver receiver, IActionDisabler disabler) instead")]
public void Disable(IActionDisabler disabler)
{
throw new Exception("Use Disable(IActionReceiver receiver, IActionDisabler disabler) instead");
}

/// <summary>
/// Disables the action.
/// </summary>
Expand Down

0 comments on commit 489f9d2

Please sign in to comment.