Table of Contents

Class MultiActionHandler

Namespace
TinyLife.Actions.Handlers
Assembly
Tiny Life.dll

A multi action handler is a handler that is used by MultiAction, which handles a set of underlying actions that should be executed in a row. Note that, when using this class, Update(GameTime, TimeSpan, float), Validate(Action, PersonLike, AppliedMigrations) and especially OnCompleted(CompletionType) have to be called in the appropriate places.

[DataContract]
public class MultiActionHandler
Inheritance
MultiActionHandler
Inherited Members
Extension Methods

Constructors

MultiActionHandler(Action)

Creates a new MultiActionHandler with the given containing action.

public MultiActionHandler(Action containingAction)

Parameters

containingAction Action

The action that contains this MultiActionHandler.

Properties

Actions

The actions that still have to be completed. The head of this queue is the Current action. If this collection is empty (which it is by default), IsCompleted() will return Completed. Meanwhile, if this collection is null, IsCompleted() will return Failed.

[DataMember]
public Queue<Action> Actions { get; }

Property Value

Queue<Action>

Current

The action that this multi-action handler is currently executing, which is always the first entry of its Actions queue.

public Action Current { get; }

Property Value

Action

Methods

Initialize(ICollection<Action>)

Initializes this multi action handler with the given set of actions. If actions is empty, the initialization fails and Failed is returned in IsCompleted(). If the collection only contains null items, no first actions will be executed and Completed is returned in IsCompleted().

public CompletionType Initialize(ICollection<Action> actions)

Parameters

actions ICollection<Action>

The actions to initialize

Returns

CompletionType

The completion type that this multi action handler has after initialization

IsCompleted()

Returns a CompletionType that determines whether this multi action handler has completed. If Actions is not (yet) initialized, Failed is returned. Otherwise, the current action's IsCompleted() result is returned. If all Actions are completed, Completed is returned.

public CompletionType IsCompleted()

Returns

CompletionType

This multi action handler's completion state

OnCompleted(CompletionType)

Calls this underlying Actions' currently executing action's OnCompleted(CompletionType) method. This should be called for any completion type that the action that uses this underlying action experiences, even Canceled and Failed. If the underlying Actions are null or already completed, this method has no effect.

public bool OnCompleted(CompletionType type)

Parameters

type CompletionType

The completion type

Returns

bool

Whether the completion type was consumed by this multi action handler

Update(GameTime, TimeSpan, float)

Updates this multi action handler, advancing all of the Actions, if there are any This action should be called at the end of Update(GameTime, TimeSpan, float) or any derived methods.

public CompletionType Update(GameTime time, TimeSpan passedInGame, float speedMultiplier)

Parameters

time GameTime

The game time

passedInGame TimeSpan

The amount of time that has passed in game since the last time this method was called

speedMultiplier float

The game speed multiplier, which represents how fast things should happen, which is usually determined by Speed

Returns

CompletionType

The completion type that this multi action handler has after this update

Validate(Action, PersonLike, AppliedMigrations)

Validates this multi action handler and all of the Actions it hosts This method should be called in Validate(PersonLike, AppliedMigrations).

public bool Validate(Action containingAction, PersonLike person, AppliedMigrations appliedMigrations)

Parameters

containingAction Action

The action that contains this multi action handler.

person PersonLike

The person that is passed to the containingAction's Validate(PersonLike, AppliedMigrations) method.

appliedMigrations AppliedMigrations

The set of migrations that have already been applied on this object.

Returns

bool

Whether this multi action handler is still valid.

Events

OnInitialize

An event that is invoked in Initialize(ICollection<Action>). This event can be used by mods to add or remove actions to or from a MultiAction or other class that uses MultiActionHandler. As this event's second argument, the MultiActionHandler's underlying action (the one that owns or started it) is passed.

public static event Action<MultiActionHandler, Action, ICollection<Action>> OnInitialize

Event Type

Action<MultiActionHandler, Action, ICollection<Action>>