@ -121,7 +121,14 @@ class Toolbox:
logger . info ( " {} files missing " . format ( len ( missingFiles ) ) )
@classmethod
def find_direction_for_condition ( cls , conditionId , story ) :
for i , item in enumerate ( story ) :
if item [ ' @type ' ] == ' Direction ' :
for dConditionId in item [ ' conditions ' ] :
if dConditionId == conditionId :
return item
def fix_story_file ( self , lang_code ) :
if lang_code not in self . languages . keys ( ) :
logger . critical ( " Invalid langauge code " )
@ -136,10 +143,11 @@ class Toolbox:
if len ( beginnings ) < 1 :
logger . critical ( " No beginning set " )
if len ( beginnings ) > 1 :
logger . warn ( f " { len ( beginnings ) } beginning messages configured. Set only one " )
beginningIds = [ i [ ' @id ' ] for i in beginnings ]
logger . warn ( f " { len ( beginnings ) } beginning messages configured. Set only one of { beginningIds } " )
itemsPerId = { item [ ' @id ' ] : item for item in story }
orphans = 0
for i , item in enumerate ( story ) :
if item [ ' @type ' ] == ' Direction ' :
if type ( item [ ' source ' ] ) == dict :
@ -152,11 +160,21 @@ class Toolbox:
logger . info ( f " Direction pointed to { item [ ' source ' ] } " )
logger . info ( f " Will now point to { validMsg } " )
item [ ' source ' ] = item [ ' source ' ] [ ' @id ' ]
for conditionId in item [ ' conditions ' ] :
if conditionId not in itemsPerId :
logger . critical ( f " Direction { item [ ' @id ' ] } refers to non-existing condition { conditionId } ! (This will result in a crash when playing the message) " )
if item [ ' @type ' ] == ' Condition ' :
direction = self . find_direction_for_condition ( item [ ' @id ' ] , story )
if not direction :
orphans + = 1
# This should be fine, but I don't dare to do it yet...
# logger.info("Clear residu condition {item['@id']} ... this is not properly done by the editor.")
# del story[i]
continue
if item [ ' type ' ] == ' messagePlayed ' :
msgId = item [ ' vars ' ] [ ' msgId ' ] . strip ( )
if msgId not in itemsPerId :
logger . critical ( f " Message played condition for non-existing message { msgId } ! " )
logger . warning ( f " Message played condition for non-existing message { msgId } when going from { direction [ ' source ' ] } to { direction [ ' target ' ] } ! (this will ignore the condition) " )
if item [ ' type ' ] == ' replyContains ' :
if ' regex ' in item [ ' vars ' ] and len ( item [ ' vars ' ] [ ' regex ' ] . rstrip ( ) ) :
try :
@ -165,6 +183,8 @@ class Toolbox:
logger . critical ( f " Invalid regex for condition { item [ ' @id ' ] } : { item [ ' vars ' ] [ ' regex ' ] . rstrip ( ) } " )
logger . exception ( e )
logger . debug ( f " Can clear { orphans } orphaned conditions (uncomment code in tools.py) " )
with open ( filename , ' w ' ) as fp :
json . dump ( story , fp , indent = 2 )
logger . info ( f " Wrote to { filename } " )
@ -274,4 +294,36 @@ class Toolbox:
json . dump ( story , fp , indent = 2 )
logger . info ( f " Wrote to { filename } " )
def parse_cutelog ( self , filename ) :
with open ( filename , ' r ' ) as fp :
cutelog = json . load ( fp ) ;
hugvey_ids = list ( range ( 1 , 30 ) )
hugveys_stats = { }
for id in hugvey_ids :
print ( f " HUGVEY { id } " )
log = [ i for i in cutelog if ' name ' in i and i [ ' name ' ] . startswith ( f ' hugvey. { id } . ' ) ]
txts = [ i for i in log if ' msg ' in i and ( ( i [ ' msg ' ] . startswith ( ' Text: ' ) and i [ ' msg ' ] != " Text: " ) or i [ ' msg ' ] . startswith ( ' Current message ' ) or i [ ' msg ' ] . startswith ( ' ignore ' ) ) ]
last = None
for txt in txts :
if last :
if txt [ ' msg ' ] . startswith ( ' Current ' ) :
print ( ' -------------------- ' , txt [ ' created ' ] )
elif txt [ ' msg ' ] . startswith ( ' ignore ' ) :
print ( ' ///////////////////// ' , txt [ ' created ' ] )
else :
print ( txt [ ' created ' ] - last [ ' created ' ] , txt [ ' msg ' ] , txt [ ' levelname ' ]
)
last = txt
else :
last = txt
tC = [ i for i in log if ' msg ' in i and ( i [ ' msg ' ] . startswith ( " Condition is met " ) ) ]
tR = [ i for i in log if ' msg ' in i and ( i [ ' msg ' ] . startswith ( " Received { ' file " ) ) ]
tP = [ i for i in log if ' msg ' in i and ( i [ ' msg ' ] . startswith ( " [ ' play ' " ) ) ]
for i , txt in enumerate ( tP ) :
print ( txt [ ' created ' ] - tC [ i ] [ ' created ' ] , txt [ ' msg ' ] , tC [ i ] [ ' msg ' ] , tR [ i ] [ ' msg ' ] )
print ( ' =================== ' )