From b25d7dd6d51f28a203d2870a1b54eb3ff33f1684 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Sat, 15 Jun 2019 19:21:22 +0200 Subject: [PATCH] Running only one condition until it matches. And go for that one --- hugvey/story.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/hugvey/story.py b/hugvey/story.py index b74b082..92754d1 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -1394,24 +1394,35 @@ class Story(object): if self.hugvey.recorder: self.hugvey.recorder.updateTranscription(self.currentReply.getText()) + def _processDirection(self, direction): + """ + return matching condition + """ + for condition in direction.conditions: + if condition.isMet(self): + self.logger.info("Condition is met: {0} ({2}), going to {1}".format( + condition.id, direction.msgTo.id, condition.type)) + self.hugvey.eventLogger.info("condition: {0}".format(condition.id)) + self.hugvey.eventLogger.info("direction: {0}".format(direction.id)) + direction.setMetCondition(condition) + return condition + return None async def _processDirections(self, directions): ':type directions: list(Direction)' chosenDirection = None metCondition = None for direction in directions: - for condition in direction.conditions: - if condition.isMet(self): - self.logger.info("Condition is met: {0} ({2}), going to {1}".format( - condition.id, direction.msgTo.id, condition.type)) - self.hugvey.eventLogger.info("condition: {0}".format(condition.id)) - self.hugvey.eventLogger.info("direction: {0}".format(direction.id)) - metCondition = condition - direction.setMetCondition(condition) - self.addToLog(condition) - self.addToLog(direction) - self.currentMessage.setFinished(self.timer.getElapsed()) - chosenDirection = direction + condition = self._processDirection(direction) + if not condition: + continue + self.addToLog(condition) + self.addToLog(direction) + self.currentMessage.setFinished(self.timer.getElapsed()) + chosenDirection = direction + metCondition = condition + break + isDiverging = await self._processDiversions(chosenDirection)