Documentation ¶
Index ¶
- Constants
- type CompareType
- type Condition
- type ConditionGroup
- type ConditionGroupCompareType
- type ICondition
- type Parameter
- type ParameterType
- type State
- type StateMachine
- func (t *StateMachine) AddAutoTransition(trans *Transition, parameter *Parameter) (err error)
- func (t *StateMachine) AddParameter(parameter *Parameter) (err error)
- func (t *StateMachine) AddSubMachine(machine *StateMachine) (err error)
- func (t *StateMachine) AddValidTransition(fromState State, toStates []State)
- func (t *StateMachine) AutoTransit()
- func (t *StateMachine) GetCurrentState() State
- func (t *StateMachine) GetMachine(namepath string) (sm *StateMachine)
- func (t *StateMachine) GetParameter(parameterName string) (parameter *Parameter)
- func (t *StateMachine) RemoveAutoTransition(transitionName string)
- func (t *StateMachine) RemoveParameter(parameterName string)
- func (t *StateMachine) SetParameterValue(parameterName string, value string) (err error)
- func (t *StateMachine) SetState(toState State) (err error)
- func (t *StateMachine) SetStateUpdatedCallback(callback func(from State, to State))
- type Transition
Constants ¶
View Source
const ( CompareTypeEqual = "==" CompareTypeNotEqual = "!=" CompareTypeLess = "<" CompareTypeLessEuqal = "<=" CompareTypeGreater = ">" CompareTypeGreaterEqual = ">=" )
View Source
const ( ConditionGroupCompareTypeAnd = "and" ConditionGroupCompareTypeOr = "or" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompareType ¶
type CompareType = string
type Condition ¶
type Condition struct { CompareType CompareType ParameterName string Value string }
func (*Condition) CompareBool ¶
func (*Condition) CompareFloat ¶
func (*Condition) CompareInt ¶
func (*Condition) CompareString ¶
type ConditionGroup ¶
type ConditionGroup struct { Conditions map[string]ICondition CompareType ConditionGroupCompareType }
ConditionGroup 条件组,组内条件必须都满足才能算是这个条件组满足了
type ConditionGroupCompareType ¶
type ConditionGroupCompareType = string
type ICondition ¶
type Parameter ¶
type Parameter struct { Name string Value string Type ParameterType }
type ParameterType ¶
type ParameterType = string
const ( ParameterTypeBool ParameterType = "bool" ParameterTypeString ParameterType = "string" ParameterTypeFloat ParameterType = "float" ParameterTypeInt ParameterType = "int" )
type StateMachine ¶
type StateMachine struct { // Parameters 参数列表 Parameters map[string]*Parameter // States 所有状态列表 States []State // ValidTransition 针对自动状态转换 Transitions 字段所做的约束 ValidTransition map[State][]State // CurrentState 当前状态 CurrentState State // Transitions 转换器列表 Transitions map[string]*Transition // ParametersLink 用于自动触发转换 ParametersLink map[*Parameter][]*Transition // SubMachines 内部子状态机 SubMachines map[string]*StateMachine // Name 状态机的名称 Name string // contains filtered or unexported fields }
func NewStateMachine ¶
func NewStateMachine(name string) *StateMachine
func (*StateMachine) AddAutoTransition ¶
func (t *StateMachine) AddAutoTransition(trans *Transition, parameter *Parameter) (err error)
AddAutoTransition 添加自动状态切换
func (*StateMachine) AddParameter ¶
func (t *StateMachine) AddParameter(parameter *Parameter) (err error)
AddParameter 添加状态切换参数
func (*StateMachine) AddSubMachine ¶
func (t *StateMachine) AddSubMachine(machine *StateMachine) (err error)
func (*StateMachine) AddValidTransition ¶
func (t *StateMachine) AddValidTransition(fromState State, toStates []State)
AddValidTransition 添加状态切换范围约束,即一个状态可以切换为哪些状态
func (*StateMachine) AutoTransit ¶
func (t *StateMachine) AutoTransit()
Transit 手动检查所有的状态切换是否需要进行一次状态切换
func (*StateMachine) GetCurrentState ¶
func (t *StateMachine) GetCurrentState() State
GetCurrentState 返回状态机的当前状态
func (*StateMachine) GetMachine ¶
func (t *StateMachine) GetMachine(namepath string) (sm *StateMachine)
GetMachine 取得状态机,参数形如 /App/Game/Match,如果不存在则会返回空指针
func (*StateMachine) GetParameter ¶
func (t *StateMachine) GetParameter(parameterName string) (parameter *Parameter)
GetParameter 取得状态切换参数对象
func (*StateMachine) RemoveAutoTransition ¶
func (t *StateMachine) RemoveAutoTransition(transitionName string)
RemoveAutoTransition 移除自动状态转换
func (*StateMachine) RemoveParameter ¶
func (t *StateMachine) RemoveParameter(parameterName string)
func (*StateMachine) SetParameterValue ¶
func (t *StateMachine) SetParameterValue(parameterName string, value string) (err error)
SetParameterValue 设置参数值并自动切换对应的状态
func (*StateMachine) SetState ¶
func (t *StateMachine) SetState(toState State) (err error)
SetState 手动设置状态机状态,但会检查条件是否满足
func (*StateMachine) SetStateUpdatedCallback ¶
func (t *StateMachine) SetStateUpdatedCallback(callback func(from State, to State))
SetStateUpdatedCallback 设置状态发生切换时触发的回调函数
type Transition ¶
type Transition struct { Name string Conditions map[string]ICondition From State To State }
func (*Transition) AddCondition ¶
func (t *Transition) AddCondition(conditionName string, condition ICondition)
func (*Transition) RemoveCondition ¶
func (t *Transition) RemoveCondition(conditionName string)
Click to show internal directories.
Click to hide internal directories.