Diversions now return to next chapter instead of next message
This commit is contained in:
parent
a286bbf1fa
commit
2f598ad7f7
4 changed files with 70 additions and 9 deletions
|
@ -42,6 +42,7 @@ class Message(object):
|
|||
self.id = id
|
||||
self.text = text
|
||||
self.isStart = False
|
||||
self.chapterStart = False
|
||||
self.reply = None
|
||||
# self.replyTime = None
|
||||
self.audioFile= None
|
||||
|
@ -64,6 +65,7 @@ class Message(object):
|
|||
def initFromJson(message, data, story):
|
||||
msg = message(data['@id'], data['text'])
|
||||
msg.isStart = data['beginning'] if 'beginning' in data else False
|
||||
msg.chapterStart = bool(data['chapterStart']) if 'chapterStart' in data else False
|
||||
msg.afterrunTime = data['afterrun'] if 'afterrun' in data else 0.
|
||||
msg.color = data['color'] if 'color' in data else None
|
||||
if 'audio' in data and data['audio'] is not None:
|
||||
|
@ -433,6 +435,7 @@ class Direction(object):
|
|||
class Diversion(object):
|
||||
"""
|
||||
An Diversion. Used to catch events outside of story flow.
|
||||
Not sure why I'm not using subclasses here o:)
|
||||
"""
|
||||
|
||||
def __init__(self, id, type: str, params: dict):
|
||||
|
@ -511,7 +514,12 @@ class Diversion(object):
|
|||
return
|
||||
|
||||
story.logger.info(f"Diverge: No response {self.id} {story.stats}")
|
||||
self.returnMessage = msgTo
|
||||
|
||||
# fall back to the next message to return on.
|
||||
# TODO: maybe, if not chapter is found, the diversion should be
|
||||
# blocked alltogether?
|
||||
self.returnMessage = story.getNextChapterForMsg(msgTo) or msgTo
|
||||
|
||||
await story.setCurrentMessage(msg)
|
||||
story.currentDiversion = self
|
||||
return True
|
||||
|
@ -545,7 +553,6 @@ class Diversion(object):
|
|||
if r is None:
|
||||
return
|
||||
|
||||
|
||||
if 'notForColor' in self.params and self.params['notForColor'] and story.currentMessage.color:
|
||||
if story.currentMessage.color.lower() == self.params['notForColor'].lower():
|
||||
story.logger.debug(f"Skip diversion {self.id} because of section color")
|
||||
|
@ -559,7 +566,10 @@ class Diversion(object):
|
|||
story.logger.critical(f"Not a valid message id for diversion: {self.params['msgId']}")
|
||||
return
|
||||
|
||||
self.returnMessage = msgTo
|
||||
# fall back to the next message to return on.
|
||||
# TODO: maybe, if not chapter is found, the diversion should be
|
||||
# blocked alltogether?
|
||||
self.returnMessage = story.getNextChapterForMsg(msgTo) or msgTo
|
||||
await story.setCurrentMessage(msg)
|
||||
story.currentDiversion = self
|
||||
return True
|
||||
|
@ -657,7 +667,11 @@ class Diversion(object):
|
|||
story.logger.critical(f"Not a valid message id for diversion: {self.params['msgId']}")
|
||||
return
|
||||
|
||||
self.returnMessage = story.currentMessage
|
||||
# fall back to the currentMessage to return on.
|
||||
# TODO: maybe, if not chapter is found, the diversion should be
|
||||
# blocked alltogether?
|
||||
self.returnMessage = story.getNextChapterForMsg(story.currentMessage, False) or story.currentMessage
|
||||
|
||||
await story.setCurrentMessage(msg)
|
||||
story.currentDiversion = self
|
||||
story.timer.setMark('last_diversion_timeout')
|
||||
|
@ -1150,6 +1164,25 @@ class Story(object):
|
|||
return []
|
||||
else:
|
||||
return self.directionsPerMsg[self.currentMessage.id]
|
||||
|
||||
def getNextChapterForMsg(self, msg, canIncludeSelf = True, depth = 0):
|
||||
if canIncludeSelf and msg.chapterStart:
|
||||
self.logger.info(f"Next chapter: {msg.id}")
|
||||
return msg
|
||||
|
||||
if depth >= 70:
|
||||
# protection against infinite loop?
|
||||
return None
|
||||
|
||||
if msg.id not in self.directionsPerMsg:
|
||||
return None
|
||||
|
||||
for direction in self.directionsPerMsg[msg.id]:
|
||||
r = self.getNextChapterForMsg(direction.msgTo, True, depth+1)
|
||||
if r:
|
||||
return r
|
||||
# none found
|
||||
return None
|
||||
|
||||
async def run(self, customStartMsgId = None):
|
||||
self.logger.info("Starting story")
|
||||
|
|
|
@ -136,6 +136,11 @@ img.icon {
|
|||
fill: #77618e; }
|
||||
#story .startMsg circle {
|
||||
fill: lightseagreen !important; }
|
||||
#story .chapterStartMsg circle {
|
||||
transform: scale(1.5);
|
||||
fill: white !important; }
|
||||
#story .chapterStartMsg text {
|
||||
fill: black; }
|
||||
#story .orphanedMsg {
|
||||
fill: lightcoral !important; }
|
||||
#story text {
|
||||
|
|
|
@ -739,7 +739,6 @@ class Graph {
|
|||
}
|
||||
|
||||
|
||||
|
||||
let startAttributes = {
|
||||
'name': msg['@id'] + '-start',
|
||||
// 'readonly': 'readonly',
|
||||
|
@ -763,6 +762,19 @@ class Graph {
|
|||
beginningAttributes['checked'] = 'checked';
|
||||
}
|
||||
|
||||
// chapter marker:
|
||||
let chapterAttributes = {
|
||||
'name': msg['@id'] + '-chapterStart',
|
||||
// 'readonly': 'readonly',
|
||||
'type': 'checkbox',
|
||||
'on': {
|
||||
'change': this.getEditEventListener()
|
||||
}
|
||||
}
|
||||
if ( typeof msg['chapterStart'] !== 'undefined' && msg['chapterStart'] == true ) {
|
||||
chapterAttributes['checked'] = 'checked';
|
||||
}
|
||||
|
||||
let params = {};
|
||||
if(msg.hasOwnProperty('params')) {
|
||||
params = msg['params'];
|
||||
|
@ -771,7 +783,6 @@ class Graph {
|
|||
}
|
||||
|
||||
let audioSrcEl = crel('source', {'src': msg['audio'] ? msg['audio']['file'] : this.getAudioUrlForMsg(msg)});
|
||||
// console.log(msg['audio']);
|
||||
let audioSpan = crel(
|
||||
'span',
|
||||
{
|
||||
|
@ -829,9 +840,13 @@ class Graph {
|
|||
crel( 'input', startAttributes )
|
||||
),
|
||||
crel( 'label',
|
||||
crel( 'span', 'Beginning' ),
|
||||
crel( 'input', beginningAttributes )
|
||||
),
|
||||
crel( 'span', 'Beginning' ),
|
||||
crel( 'input', beginningAttributes )
|
||||
),
|
||||
crel( 'label',
|
||||
crel( 'span', 'Chapter start' ),
|
||||
crel( 'input', chapterAttributes )
|
||||
),
|
||||
|
||||
crel( 'label',
|
||||
crel( 'span', 'Audio' ),
|
||||
|
@ -1681,6 +1696,7 @@ class Graph {
|
|||
let classes = [];
|
||||
if ( this.selectedMsg == msg ) classes.push( 'selectedMsg' );
|
||||
if ( msg['start'] == true ) classes.push( 'startMsg' );
|
||||
if ( msg.hasOwnProperty('chapterStart') && msg['chapterStart'] == true ) classes.push( 'chapterStartMsg' );
|
||||
if ( this.getDirectionsFrom( msg ).length < 1 ) {
|
||||
classes.push( 'endMsg' );
|
||||
if ( this.getDirectionsTo( msg ).length < 1 ) classes.push( 'orphanedMsg' );
|
||||
|
|
|
@ -221,6 +221,13 @@ img.icon{
|
|||
.endMsg circle{
|
||||
// fill: lightslategray !important;
|
||||
}
|
||||
.chapterStartMsg circle{
|
||||
transform: scale(1.5);
|
||||
fill: white !important;
|
||||
}
|
||||
.chapterStartMsg text{
|
||||
fill: black;
|
||||
}
|
||||
|
||||
.orphanedMsg{
|
||||
fill: lightcoral !important;
|
||||
|
|
Loading…
Reference in a new issue