Advertisement
Guest User

DinkC_Choice.py

a guest
Jun 9th, 2014
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. editor.beginUndoAction()
  2.  
  3. pos = editor.getCurrentPos()
  4. inchoice = 0
  5. curopt = 1
  6. options = []
  7. result = ""
  8.  
  9.  
  10. text = editor.getText()
  11.  
  12. for line in text.splitlines():
  13.   meat = line.lstrip()
  14.   indentation = line[0:len(line) - len(meat)]
  15.   meat = meat.rstrip()
  16.  
  17.   if meat == "---":
  18.     if inchoice == 0:
  19.       result += indentation + "choice_start();\n"
  20.       inchoice = 1
  21.     elif inchoice == 1:
  22.       result += indentation + "choice_end();\n"
  23.       inchoice = 0
  24.       result += indentation + "\n"
  25.       for index, elem in enumerate(options):
  26.         result += indentation + "// " + elem + "\n"
  27.         result += indentation + "if (&result == " + str(index+1) + ")\n"
  28.         result += indentation + "{\n"
  29.         result += indentation + "  \n"
  30.         result += indentation + "}\n\n"
  31.       options = []
  32.       curopt = 1
  33.     else:
  34.       console.writeError("Incorrect menu nesting found!")
  35.       result = text
  36.       break
  37.     continue
  38.  
  39.   if meat == "+++":
  40.     if inchoice == 1:
  41.       result += indentation + "title_start();\n"
  42.       inchoice = 2
  43.     elif inchoice == 2:
  44.       result += indentation + "title_end();\n"
  45.       inchoice = 1
  46.     else:
  47.       console.writeError("Incorrect menu nesting found!")
  48.       result = text
  49.       break
  50.     continue
  51.  
  52.   if inchoice == 1:
  53.     if meat[-1] == '"':
  54.       options.append(meat.split('"')[1])
  55.  
  56.   result += line + "\n"
  57.  
  58. editor.setText(result)
  59. editor.gotoPos(pos)
  60.  
  61. editor.endUndoAction()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement