193 lines
6.8 KiB
Text
193 lines
6.8 KiB
Text
__stateMachineTable = nil
|
|
|
|
__globalStateListData = {}
|
|
__globalStateListImplement = {}
|
|
__globalStateLists = {}
|
|
__indepStateDeclaration = 0
|
|
|
|
function independentStateSTART()
|
|
__indepStateDeclaration = 1
|
|
table.insert( __globalStateLists, {} )
|
|
end
|
|
function independentStateSTOP()
|
|
__indepStateDeclaration = 0
|
|
destTable = __globalStateLists[#__globalStateLists][1]
|
|
__globalStateLists = {}
|
|
return destTable
|
|
end
|
|
|
|
function stateListSTART()
|
|
table.insert( __globalStateLists, {} )
|
|
end
|
|
function stateListSTOP()
|
|
|
|
local listCount = #__globalStateLists
|
|
|
|
if listCount > 1 then
|
|
local idx = #__globalStateListData
|
|
__globalStateListData[ idx ]["implementTempate"] = {}
|
|
__globalStateListData[ idx ]["implementTempate"]["StateImplement_Template"] = {}
|
|
__globalStateListData[ idx ]["implementTempate"]["StateImplement_Template"]["stateList"] = __globalStateLists[listCount]
|
|
table.remove( __globalStateLists, #__globalStateLists )
|
|
|
|
elseif listCount == 1 then
|
|
if __indepStateDeclaration == 0 then
|
|
__stateMachineTable = { WithAnimStateMachine_Template = { stateList = __globalStateLists[1] }, }
|
|
__globalStateLists = {}
|
|
end
|
|
end
|
|
|
|
end
|
|
--------------------------------------------------------------------------------
|
|
function __createState__( _name, _implementTemplate, _defaultNextState, _animName )
|
|
|
|
local data = {}
|
|
data["stateName"] = _name
|
|
table.insert( __globalStateListData, data )
|
|
|
|
if _defaultNextState ~= nil then addDefaultNextState( _defaultNextState ) end
|
|
if _animName ~= nil then addDefaultAnim( _animName ) end
|
|
|
|
local implementName = "ERROR"
|
|
|
|
if _implementTemplate ~= nil then
|
|
implementName = _implementTemplate
|
|
end
|
|
table.insert( __globalStateListImplement, implementName )
|
|
end
|
|
|
|
--------------------------------------------------------------------------------
|
|
function createStateImp( _name, _implementTemplate, _defaultNextState, _animName )
|
|
|
|
local implementName = "ERROR"
|
|
|
|
if _implementTemplate ~= nil then
|
|
implementName = _implementTemplate
|
|
elseif _animName ~= nil then
|
|
implementName = "WithAnimStateImplement_Tempate"
|
|
else
|
|
implementName = "BasicStateImplement_Tempate"
|
|
end
|
|
__createState__( _name, implementName, _defaultNextState, _animName )
|
|
end
|
|
--------------------------------------------------------------------------------
|
|
-- use dest table if you don't want state auto add in state tree
|
|
function endStateImp()
|
|
|
|
local implementName = __globalStateListImplement[#__globalStateListImplement]
|
|
|
|
local stateTable = { NAME = implementName, }
|
|
stateTable[implementName] = __globalStateListData[#__globalStateListData]
|
|
|
|
-- if _destTable ~= nil then
|
|
-- _destTable = stateTable
|
|
-- else
|
|
table.insert( __globalStateLists[#__globalStateLists], stateTable )
|
|
-- end
|
|
table.remove( __globalStateListData, #__globalStateListData )
|
|
table.remove( __globalStateListImplement, #__globalStateListImplement )
|
|
|
|
--return stateTable
|
|
end
|
|
|
|
--------------------------------------------------------------------------------
|
|
function addStateTable( _stateTable )
|
|
table.insert( __globalStateLists[#__globalStateLists], _stateTable )
|
|
end
|
|
--------------------------------------------------------------------------------
|
|
function addStateStart( _stateName, _defaultNextState, _animName, _endCheckByEvt, _endCheckByAnimEnd )
|
|
|
|
if _animName ~= nil then
|
|
__createState__( _stateName, "WithAnimState_Template", _defaultNextState, _animName )
|
|
addAnimEndCheckFlags( _endCheckByEvt, _endCheckByAnimEnd )
|
|
else
|
|
__createState__( _stateName, "BasicState_Template", _defaultNextState )
|
|
end
|
|
end
|
|
--------------------------------------------------------------------------------
|
|
function addStateEnd()
|
|
endStateImp()
|
|
end
|
|
--------------------------------------------------------------------------------
|
|
function addState( _stateName, _defaultNextState, _animName, _endCheckByEvt, _endCheckByAnimEnd )
|
|
addStateStart( _stateName, _defaultNextState, _animName, _endCheckByEvt, _endCheckByAnimEnd )
|
|
addStateEnd()
|
|
end
|
|
--------------------------------------------------------------------------------
|
|
function addParam( _paramName, _paramVal )
|
|
__globalStateListData[ #__globalStateListData ][ _paramName ] = _paramVal
|
|
end
|
|
--------------------------------------------------------------------------------
|
|
function addDefaultNextState( _nextStateName )
|
|
addParam( "defaultNextState", _nextStateName )
|
|
end
|
|
--------------------------------------------------------------------------------
|
|
function addDefaultAnim( _anim )
|
|
addParam( "defaultAnim", _anim )
|
|
end
|
|
--------------------------------------------------------------------------------
|
|
function addAnimEndCheckFlags( _endCheckByEvt, _endCheckByAnimEnd )
|
|
if _endCheckByEvt ~= nil then
|
|
addParam( "endCheckByAnimEvent", _endCheckByEvt )
|
|
if _endCheckByAnimEnd == nil then
|
|
addParam( "endCheckByAnimEnd", 0 )
|
|
end
|
|
end
|
|
if _endCheckByAnimEnd ~= nil then addParam( "endCheckByAnimEnd", _endCheckByAnimEnd ) end
|
|
end
|
|
--------------------------------------------------------------------------------
|
|
function addAnimRestartFlags( _restartAnimIfSame )
|
|
addParam( "restartAnimIfSame", _restartAnimIfSame )
|
|
end
|
|
--------------------------------------------------------------------------------
|
|
function addOverrideParam( _paramName, _valType, _paramVal )
|
|
local idx = #__globalStateListData
|
|
if __globalStateListData[ idx ][ "implementParamHandler" ] == nil then
|
|
__globalStateListData[ idx ][ "implementParamHandler" ] = { NAME = "ImpParamHandler_Template", ImpParamHandler_Template = { list = {} } }
|
|
end
|
|
param = { ImpParamData = { name = _paramName, type = _valType, value = tostring(_paramVal) } }
|
|
|
|
table.insert( __globalStateListData[ idx ][ "implementParamHandler" ]["ImpParamHandler_Template"]["list"], param )
|
|
end
|
|
|
|
--------------------------------------------------------------------------------
|
|
function addOverrideIParam( _paramName, _paramVal )
|
|
addOverrideParam( _paramName, 0, _paramVal )
|
|
end
|
|
--------------------------------------------------------------------------------
|
|
function addOverrideFParam( _paramName, _paramVal )
|
|
addOverrideParam( _paramName, 1, _paramVal )
|
|
end
|
|
--------------------------------------------------------------------------------
|
|
function addOverrideVParam( _paramName, _paramVal )
|
|
addOverrideParam( _paramName, 2, _paramVal )
|
|
end
|
|
--------------------------------------------------------------------------------
|
|
function setStartState( _startStateName )
|
|
__globalStateListData[ #__globalStateListData ]["implementTempate"]["StateImplement_Template"]["startState"] = _startStateName
|
|
end
|
|
|
|
|
|
-- stateListSTART()
|
|
|
|
-- createState( "toto", "IMP_template" )
|
|
|
|
----addParam( "airControl", 100.0 )
|
|
|
|
-- addOverrideFParam( "airControl", 100.5 )
|
|
-- addOverrideFParam( "test", 1.0 )
|
|
|
|
-- stateListSTART()
|
|
-- addBasicState( "TATA" )
|
|
-- addAnimState( "TITI", "Idle" )
|
|
-- stateListSTOP()
|
|
|
|
-- endState()
|
|
|
|
-- addBasicState( "TEST" )
|
|
|
|
-- stateListSTOP()
|
|
|
|
|
|
-- display(__stateMachineTable)
|
|
|