Skip to content

Commit

Permalink
bug fix on order of remove behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedark committed Apr 25, 2023
1 parent 92d4351 commit c04d5b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion NetworkCore/Base_Attachable_Modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def remove_behavior(self, key_tag_behavior_or_type):
remove_keys.append(key)
for key in remove_keys:
b=self.behavior.pop(key)
self.network._remove_behavior_from_sorted_execution_list(self, b)
self.network._remove_behavior_from_sorted_execution_list(key, self, b)

def set_behaviors(self, tag, enabeled):
if enabeled:
Expand Down
15 changes: 7 additions & 8 deletions NetworkCore/Network.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@ def _add_behavior_to_sorted_execution_list(self, key, beh_parent, behavior):
self.sorted_behavior_execution_list.insert(insert_indx, (key, beh_parent, behavior))
#print([k for k,_,_ in self.sorted_behavior_execution_list])

def _remove_behavior_from_sorted_execution_list(self, behavior, beh_parent=None): # removes SINGLE behavior if beh_parent is not None and only one key has behavior!
rm_indices = []
def _remove_behavior_from_sorted_execution_list(self, key, beh_parent, behavior):
rm_indx = -1
for i,kpb in enumerate(self.sorted_behavior_execution_list):
k, p, b = kpb
if behavior==b:
if beh_parent is None or beh_parent==p:
rm_indices.append(i)
if rm_indices:
for rm_indx in rm_indices[::-1]:
self.sorted_behavior_execution_list.pop(rm_indx)
if key==k and beh_parent==p and behavior==b:
rm_indx = i
break
if rm_indx>-1:
self.sorted_behavior_execution_list.pop(rm_indx)
else:
raise Exception('behavior not found')

Expand Down

0 comments on commit c04d5b3

Please sign in to comment.