STATEMACHINE_TEMPLATE is added to template statemachines...

It is working now, and NOW SWITCHING SLOTS of PLAYERS ALSO WORKS IN
TASKING!!!
Jippie!!!
The next thing is to debug the DETECTION_DISPATCHER...
And make STATEMACHINE_TEMPLATE now as a parameter to create new
STATEMACHINEs, instead of that ugly table construction.
The, I need to modify the New: Methods of each STATEMACHINE_PROCESS to
be initialized with a TEMPLATE... Maybe I can commit already and just
implement this later ...
This commit is contained in:
FlightControl
2016-11-30 10:40:31 +01:00
parent 54a861cc58
commit 9ab3a2f74d
12 changed files with 215 additions and 78 deletions

View File

@@ -74,6 +74,8 @@ function STATEMACHINE:SetInitialState( State )
self.current = State
end
function STATEMACHINE:AddAction( From, Event, To )
local event = {}
@@ -87,6 +89,8 @@ function STATEMACHINE:AddAction( From, Event, To )
end
--- Set the default @{Process} template with key ProcessName providing the ProcessClass and the process object when it is assigned to a @{Controllable} by the task.
-- @return Process#PROCESS
function STATEMACHINE:AddProcess( From, Event, Process, ReturnEvents )
@@ -164,7 +168,7 @@ function STATEMACHINE._handler( self, EventName, ... )
self:E( { EventName, ... } )
local can, to = self:can( EventName )
self:E( { EventName, can, to } )
self:E( { EventName, self.current, can, to } )
local ReturnValues = nil
@@ -544,3 +548,69 @@ function STATEMACHINE_SET:_call_handler( handler, params )
end
end
--- STATEMACHINE_TEMPLATE class
-- @type STATEMACHINE_TEMPLATE
-- @extends Core.Base#BASE
STATEMACHINE_TEMPLATE = {
ClassName = "STATEMACHINE_TEMPLATE",
}
--- Creates a new STATEMACHINE_TEMPLATE object.
-- @param #STATEMACHINE_TEMPLATE self
-- @return #STATEMACHINE_TEMPLATE
function STATEMACHINE_TEMPLATE:New( options )
-- Inherits from BASE
local self = BASE:Inherit( self, BASE:New() ) -- #STATEMACHINE_TEMPLATE
self._Transitions = self.Transitions or {}
self._Processes = self.Processes or {}
return self
end
function STATEMACHINE_TEMPLATE:AddTransition( From, Event, To )
local Transition = {}
Transition.From = From
Transition.Event = Event
Transition.To = To
self._Transitions[Transition] = Transition
end
function STATEMACHINE_TEMPLATE:GetTransitions()
return self._Transitions
end
--- Set the default @{Process} template with key ProcessName providing the ProcessClass and the process object when it is assigned to a @{Controllable} by the task.
-- @return Process#PROCESS
function STATEMACHINE_TEMPLATE:AddProcess( From, Event, ProcessTemplate, ReturnEvents )
local Process = {}
Process.From = From
Process.Event = Event
Process.Process = ProcessTemplate[1]
Process.Arguments = ProcessTemplate[2]
Process.ReturnEvents = ReturnEvents
-- Make the reference table weak.
-- setmetatable( self.options.subs, { __mode = "v" } )
self._Processes[Process] = Process
return ProcessTemplate
end
function STATEMACHINE_TEMPLATE:GetProcesses()
return self._Processes
end
function STATEMACHINE_TEMPLATE:CopyCallHandler( Fsm, OnAction, Transition )
self:E( { Fsm.ClassName, OnAction, Transition } )
if OnAction and Transition and self[OnAction .. Transition] then
Fsm[OnAction .. Transition] = self[OnAction .. Transition]
end
end