mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 18:31:55 -04:00
add conditional_request
This commit is contained in:
parent
92330e53eb
commit
9a748df2d5
@ -229,6 +229,45 @@ class FSM(DirectObject):
|
|||||||
aStateName))
|
aStateName))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def conditional_request(self, aStateName, enterArgList=[], exitArgList=[]):
|
||||||
|
"""request(self, string)
|
||||||
|
Attempt transition from currentState to given one, if it exists.
|
||||||
|
Return true is transition exists to given state,
|
||||||
|
false otherwise. It is NOT an error/warning to attempt a cond_request
|
||||||
|
if the transition doesnt exist. This lets people be sloppy about
|
||||||
|
FSM transitions, letting the same fn be used for different states
|
||||||
|
that may not have the same out transitions.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not self.__currentState:
|
||||||
|
# Make this a warning for now
|
||||||
|
FSM.notify.warning("[%s]: request: never entered initial state" %
|
||||||
|
(self.__name))
|
||||||
|
self.__currentState = self.__initialState
|
||||||
|
|
||||||
|
if isinstance(aStateName, types.StringType):
|
||||||
|
aState = self.getStateNamed(aStateName)
|
||||||
|
else:
|
||||||
|
# Allow the caller to pass in a state in itself, not just
|
||||||
|
# the name of a state.
|
||||||
|
aState = aStateName
|
||||||
|
aStateName = aState.getName()
|
||||||
|
|
||||||
|
if aState == None:
|
||||||
|
FSM.notify.error("[%s]: request: %s, no such state" %
|
||||||
|
(self.__name, aStateName))
|
||||||
|
|
||||||
|
fulltransitionnameset = self.__currentState.getTransitions()
|
||||||
|
fulltransitionnameset.extend([self.__currentState.getName(),self.__finalState.getName()])
|
||||||
|
|
||||||
|
if (aStateName in fulltransitionnameset):
|
||||||
|
return self.request(aStateName, enterArgList, exitArgList)
|
||||||
|
else:
|
||||||
|
FSM.notify.debug("[%s]: condition_request: %s, transition doesnt exist" %
|
||||||
|
(self.__name, aStateName))
|
||||||
|
return 0
|
||||||
|
|
||||||
def view(self):
|
def view(self):
|
||||||
import FSMInspector
|
import FSMInspector
|
||||||
FSMInspector.FSMInspector(self)
|
FSMInspector.FSMInspector(self)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user