Advertisement
Guest User

Untitled

a guest
Aug 15th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.99 KB | None | 0 0
  1. import re
  2. import glob
  3. import textwrap
  4. import os
  5. import shutil
  6.  
  7. class Encounter:
  8.   def __init__(self, desc="Fuck", nextEnc=(None, None)):
  9.     self.desc = desc
  10.     self.nextEnc = nextEnc
  11.  
  12.   def setEncounter(self, encs = []): #sadly this is the part you do manually
  13.     if encs:
  14.       self.nextEnc = encs
  15.     else:
  16.       self.nextEnc = (None, None)
  17.  
  18. #===
  19.  
  20. def openFile(filename):
  21.   with open(filename, "r") as f:
  22.     return f.read()
  23.  
  24. def getEncs(filename):
  25.   with open(filename, "r") as f:
  26.     fil = f.read()
  27.   lis = re.findall("\$[0-9]*\.le", fil)
  28.   lis = [ (int(x.replace("$",'').replace(".le",'')) - 1) for x in lis ]
  29.   return lis
  30.  
  31. def moveSomewhere(currentEnc):
  32.   try: userChoice = int(input(">"))
  33.   except: userChoice = 1
  34.   return currentEnc.nextEnc[userChoice-1]
  35.  
  36. def init():
  37.   allEncounters = []
  38.   descriptions = [f for f in glob.glob("*.le")]
  39.   descriptions.sort()
  40.   for x in descriptions:
  41.     allEncounters.append(Encounter(desc = openFile(x)))
  42.   for y,x in enumerate(allEncounters):
  43.     tup = getEncs(descriptions[y])
  44.     if tup == []:
  45.       pass
  46.     else:
  47.       print([x for x in tup])
  48.       x.setEncounter( [allEncounters[x] for x in tup] )
  49.   return allEncounters
  50.  
  51. def getText(inp):
  52.   wordList = inp.split('\n')
  53.   realWordList = []
  54.   (columns, lines) = shutil.get_terminal_size()
  55.  
  56.   wrapper = textwrap.TextWrapper(width=columns - 5, replace_whitespace=False, drop_whitespace=False)
  57.   for x in wordList:
  58.     if x == '':
  59.       realWordList.append('')
  60.     else:
  61.       realWordList.extend(wrapper.wrap(text=x))
  62.  
  63.   lineCounter = 0
  64.   os.system("clear")
  65.   for x in realWordList:
  66.     if lineCounter >= lines - 1:
  67.       lineCounter = 0
  68.       input("press any key to cont")
  69.       os.system("clear")
  70.     else:
  71.       print(x)
  72.       lineCounter += 1
  73.  
  74. if __name__ == "__main__":
  75.   allEncounters = init()
  76.   enc = allEncounters[0]
  77.   while enc:
  78.     getText(enc.desc)
  79.     if enc.nextEnc == (None, None):
  80.       enc = None
  81.     else:
  82.       enc = moveSomewhere(enc)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement