diff --git a/README.md b/README.md index 5eb5c61..8c6c3c4 100644 --- a/README.md +++ b/README.md @@ -203,7 +203,8 @@ Types of conditions: ## Diversions -TODO +- ReplyContains: Match the contents of speech using regex. + + works only if the current message has one, and only one, direction. times occured/only on n-th instance: determines the order of diversions of the same type (for Timeout and no_response). Starting at 1, as a diversion with value of 0 can occur always diff --git a/hugvey/story.py b/hugvey/story.py index f44bc30..16c4850 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -74,6 +74,9 @@ class Message(object): self.uuid = None # Have a unique id each time the message is played back. self.color = None self.lightChange = None + + # Used by diversions, autogenerated directions should link to next chapter mark instead of the given msgTo + self.generatedDirectionsJumpToChapter = False def __getstate__(self): # Copy the object's state from self.__dict__ which contains @@ -110,6 +113,7 @@ class Message(object): # prevent clipping on some Lyrebird tracks msg.params['vol'] = .8 msg.lightChange = data['light'] if 'light' in data else None + msg.generatedDirectionsJumpToChapter = bool(data['generatedDirectionsJumpToChapter']) if 'generatedDirectionsJumpToChapter' in data else False msg.params['vol'] = float(msg.params['vol']) @@ -765,8 +769,12 @@ class Diversion(object): msg = story.get(msgId) if not msg: continue + + usedReturnMessage = returnMsg + if msg.generatedDirectionsJumpToChapter: + usedReturnMessage = story.getNextChapterForMsg(returnMsg, canIncludeSelf=True) - direction = Direction(f"{self.id}-{i}-{self.counter}", msg, returnMsg) + direction = Direction(f"{self.id}-{i}-{self.counter}", msg, usedReturnMessage) data = json.loads(f""" {{ "@id": "{self.id}-ct{i}-{self.counter}", @@ -802,7 +810,7 @@ class Diversion(object): story.add(condition2) direction.isDiversionReturn = True # will clear the currentDiversion on story - story.logger.info(f"Created direction: {direction.id} ({msg.id} -> {returnMsg.id}) {condition.id} with timeout {finalTimeoutDuration}s") + story.logger.info(f"Created direction: {direction.id} ({msg.id} -> {usedReturnMessage.id}) {condition.id} with timeout {finalTimeoutDuration}s") story.add(condition) story.add(direction) diff --git a/www/js/hugvey_console.js b/www/js/hugvey_console.js index fa0322b..91ff382 100644 --- a/www/js/hugvey_console.js +++ b/www/js/hugvey_console.js @@ -1229,6 +1229,18 @@ class Graph { chapterAttributes['checked'] = 'checked'; } + let generatedDirectionsJumpToChapterAttributes = { + 'name': msg['@id'] + '-generatedDirectionsJumpToChapter', +// 'readonly': 'readonly', + 'type': 'checkbox', + 'on': { + 'change': this.getEditEventListener() + } + } + if ( msg.hasOwnProperty('generatedDirectionsJumpToChapter') && msg['generatedDirectionsJumpToChapter'] == true ) { + generatedDirectionsJumpToChapterAttributes['checked'] = 'checked'; + } + let params = {}; if(msg.hasOwnProperty('params')) { params = msg['params']; @@ -1443,7 +1455,13 @@ class Graph { }, lightOptions ) - ) + ), + crel( 'label', + crel( 'span', { + 'title': "Only for diversions: when this message is the final message of a diversion, it jumps back to the next chapter instead of the given message (overrules settings of diversion on a per message basis)" + },'Generated directions jump to next chapter' ), + crel( 'input', generatedDirectionsJumpToChapterAttributes ) + ), ); msgEl.appendChild( msgInfoEl );