Inherits from OGWAspect : NSObject
Declared in OGWStateAspect.h

Overview

The state aspect encodes information for entities that can be in only one of multiple states. A simple scenario would be the states of a player: alive, dead, waiting for respawn. The GWState and GWReason values are user-definable, usually you would set up an enum encoding the various states.

The OGWStateDelegate allows another aspect to allow or deny specific state changes. This is useful as a validity check. The delegate also receives the actual state changes, in order to send the corresponding commands. This could include running an animation or playing a sound on the view side, or internal changes like starting to look for a target to fire upon, following a specific entity, and so on.

Tasks

Delegate

State

Changing State

Properties

delegate

The delegate is crucial for the state aspect. You need a delegate aspect to verify the allowable and deny the disallowed state changes, and to react to state changes accordingly.

@property OGWAspect<OGWStateDelegate> *delegate

Return Value

The aspect implementing the OGWStateDelegate protocol.

Declared In

OGWStateAspect.h

state

The values are user-definable. There are no predefined states, there’s no inherent meaning of any value. It’s your task to give meaning to individual state values.

@property (readonly) GWState state

Return Value

The current state.

Declared In

OGWStateAspect.h

Instance Methods

shouldChangeState:

Signal the aspect that it should change its state to the new state value. This triggers the shouldChangeState delegate, and if it returns YES, the state is changed. There’s no guarantee that the state change actually did go through. Check the return value if this is important.

- (BOOL)shouldChangeState:(GWState)state

Parameters

state

The state to change to.

Return Value

YES if the state was changed to the desired state or the state was already set. NO if the state change was denied by the OGWStateDelegate.

Declared In

OGWStateAspect.h

shouldChangeState:reason:

Signal the aspect that it should change its state to the new state value with a reason. This triggers the shouldChangeState delegate, and if it returns YES, the state is changed. There’s no guarantee that the state change actually did go through. Check the return value if this is important.

- (BOOL)shouldChangeState:(GWState)state reason:(GWReason)reason

Parameters

state

The state to change to.

reason

A user-definable reason why the state change should occur.

Return Value

YES if the state was changed to the desired state or the state was already set. NO if the state change was denied by the OGWStateDelegate.

Discussion

The reason is user definable. Use it in cases where the OGWStateDelegate will make a difference whether a state change occured for one reason but not another. For example “force” could be a reason to ensure the state does change.

Declared In

OGWStateAspect.h