fixed behavior wrt adding and then removing all child states

This commit is contained in:
Darren Ranalli 2002-07-05 20:50:07 +00:00
parent b9ef189d16
commit c5329f3964

View File

@ -84,7 +84,7 @@ class State(DirectObject):
self.setExitFunc(exitFunc) self.setExitFunc(exitFunc)
self.setTransitions(transitions) self.setTransitions(transitions)
self.setInspectorPos(inspectorPos) self.setInspectorPos(inspectorPos)
self.__FSMList = None self.__FSMList = []
# setters and getters # setters and getters
@ -167,43 +167,40 @@ class State(DirectObject):
def addChild(self, FSM): def addChild(self, FSM):
"""addChild(self, FSM) """addChild(self, FSM)
Add the given FSM to list of child FSMs""" Add the given FSM to list of child FSMs"""
if (self.__FSMList == None): self.__FSMList.append(FSM)
self.__FSMList = [FSM]
else:
self.__FSMList.append(FSM)
def removeChild(self, FSM): def removeChild(self, FSM):
"""addChild(self, FSM) """removeChild(self, FSM)
Add the given FSM to list of child FSMs""" Remove the given FSM from list of child FSMs"""
if FSM in self.__FSMList: if FSM in self.__FSMList:
self.__FSMList.remove(FSM) self.__FSMList.remove(FSM)
def hasChildren(self): def hasChildren(self):
"""hasChildren(self) """hasChildren(self)
Return true if state has child FSMs""" Return true if state has child FSMs"""
return(self.__FSMList != None) return len(self.__FSMList) > 0
def __enterChildren(self, argList): def __enterChildren(self, argList):
"""__enterChildren(self, argList) """__enterChildren(self, argList)
Enter all child FSMs""" Enter all child FSMs"""
if self.hasChildren(): for fsm in self.__FSMList:
for fsm in self.__FSMList: print "ENTERING CHILD FSM:" + str(fsm)
# Check to see if the child fsm is already in a state print str(self)
# if it is, politely request the initial state # Check to see if the child fsm is already in a state
if fsm.getCurrentState(): # if it is, politely request the initial state
fsm.request((fsm.getInitialState()).getName()) if fsm.getCurrentState():
# If it has no current state, I assume this means it fsm.request((fsm.getInitialState()).getName())
# has never entered the initial state, so enter it # If it has no current state, I assume this means it
# explicitly # has never entered the initial state, so enter it
else: # explicitly
fsm.enterInitialState() else:
fsm.enterInitialState()
def __exitChildren(self, argList): def __exitChildren(self, argList):
"""__exitChildren(self, argList) """__exitChildren(self, argList)
Exit all child FSMs""" Exit all child FSMs"""
if self.hasChildren(): for fsm in self.__FSMList:
for fsm in self.__FSMList: fsm.request((fsm.getFinalState()).getName())
fsm.request((fsm.getFinalState()).getName())
# basic State functionality # basic State functionality