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,27 +167,25 @@ 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 = [FSM]
else:
self.__FSMList.append(FSM) 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)
print str(self)
# Check to see if the child fsm is already in a state # Check to see if the child fsm is already in a state
# if it is, politely request the initial state # if it is, politely request the initial state
if fsm.getCurrentState(): if fsm.getCurrentState():
@ -201,7 +199,6 @@ class State(DirectObject):
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())