From 87c7db2489ef35f5a2df9a3b4ccc50044ae0910d Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Sun, 9 Jun 2019 11:34:41 +0200 Subject: [PATCH] Reply_contains diversion now can move to next chapter on finish --- hugvey/story.py | 18 ++++++++++-------- www/js/hugvey_console.js | 13 +++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/hugvey/story.py b/hugvey/story.py index b5dddeb..de2537d 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -772,12 +772,7 @@ class Diversion(object): if not direction: # ignore the direction argument, and only check if the current message has a valid default return - - msgTo = direction.msgTo - - if not direction: - return - + waitTime = 1.8 if 'waitTime' not in self.params else float(self.params['waitTime']) timeSince = story.currentReply.getTimeSinceLastUtterance() if timeSince < waitTime: @@ -801,11 +796,18 @@ class Diversion(object): story.logger.critical(f"Not a valid message id for diversion: {self.params['msgId']}") return - # TODO: pick the direction with timeout as next Message. + + if 'nextChapterOnReturn' in self.params and self.params['nextChapterOnReturn']: + msgTo = story.getNextChapterForMsg(story.currentMessage, False) or direction.msgTo + returnInheritTiming = False + else: + msgTo = direction.msgTo + returnInheritTiming = True + self.returnMessage = msgTo if self.params['returnAfterStrand']: - self.createReturnDirectionsTo(story, msg, msgTo, direction) + self.createReturnDirectionsTo(story, msg, msgTo, direction, inheritTiming=returnInheritTiming) await story.setCurrentMessage(msg) story.currentDiversion = self diff --git a/www/js/hugvey_console.js b/www/js/hugvey_console.js index 2695aed..a08dbce 100644 --- a/www/js/hugvey_console.js +++ b/www/js/hugvey_console.js @@ -393,6 +393,7 @@ class Graph { else if(type == 'reply_contains') { div['params']['regex'] = ""; div['params']['returnAfterStrand'] = true; + div['params']['nextChapterOnReturn'] = false; div['params']['msgId'] = ""; div['params']['notForColor'] = ""; div['params']['waitTime'] = 1.8; @@ -540,6 +541,15 @@ class Graph { if(div['params']['returnAfterStrand']) { returnAttrs['checked'] = 'checked'; } + let returnChapterAttrs = { + 'type': 'checkbox', + 'on': { + 'change': (e) => div['params']['nextChapterOnReturn'] = e.target.checked + } + } + if(div['params']['nextChapterOnReturn']) { + returnChapterAttrs['checked'] = 'checked'; + } let msgOptions = [crel('option',"")]; let starts = this.messages.filter( m => m.hasOwnProperty('start') && m['start'] == true); for(let startMsg of starts) { @@ -599,6 +609,9 @@ class Graph { crel('label', 'Return to point of departure afterwards', crel('input', returnAttrs) ), + crel('label', 'On return, skip to next chapter', + crel('input', returnChapterAttrs) + ), crel('label', 'Go to (start message)', crel('select', {'on': { 'change': (e) => div['params']['msgId'] = e.target.value