getInteractablesByClassifier's classifier param is now optional

This commit is contained in:
Marcin Kostrzewski 2020-05-16 11:41:51 +02:00
parent 6ec1c0b2d2
commit 5e1e089015

View File

@ -90,16 +90,20 @@ class Map:
print("Failed to load entity " + entity) print("Failed to load entity " + entity)
return actualEntities return actualEntities
def getInteractablesByClassifier(self, classifier: Classifiers): def getInteractablesByClassifier(self, classifier=None):
""" """
Return a list of all Interactable entities by a given classifier. Return a list of all Interactable entities by a given classifier.
If the classifier is None, returns all interactables.
:type classifier: Classifiers :type classifier: Classifiers
:param classifier: Classifier :param classifier: Classifier
""" """
result = [] result = []
for entity in self.entities.sprites(): for entity in self.entities.sprites():
if isinstance(entity, Interactable) and entity.classifier.value == classifier.value: if isinstance(entity, Interactable):
if classifier is None:
result.append(entity)
elif entity.classifier.value == classifier.value:
result.append(entity) result.append(entity)
return result return result