Ending messages can be configured to jump to next chapter instead of return message

This commit is contained in:
Ruben van de Ven 2019-08-23 12:37:01 +02:00
parent f135520c87
commit 6ca3a79acd
3 changed files with 31 additions and 4 deletions

View file

@ -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

View file

@ -75,6 +75,9 @@ class Message(object):
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
# all our instance attributes. Always use the dict.copy()
@ -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'])
@ -766,7 +770,11 @@ class Diversion(object):
if not msg:
continue
direction = Direction(f"{self.id}-{i}-{self.counter}", msg, returnMsg)
usedReturnMessage = returnMsg
if msg.generatedDirectionsJumpToChapter:
usedReturnMessage = story.getNextChapterForMsg(returnMsg, canIncludeSelf=True)
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)

View file

@ -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 );