Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- editor.beginUndoAction()
- pos = editor.getCurrentPos()
- inchoice = 0
- curopt = 1
- options = []
- result = ""
- text = editor.getText()
- for line in text.splitlines():
- meat = line.lstrip()
- indentation = line[0:len(line) - len(meat)]
- meat = meat.rstrip()
- if meat == "---":
- if inchoice == 0:
- result += indentation + "choice_start();\n"
- inchoice = 1
- elif inchoice == 1:
- result += indentation + "choice_end();\n"
- inchoice = 0
- result += indentation + "\n"
- for index, elem in enumerate(options):
- result += indentation + "// " + elem + "\n"
- result += indentation + "if (&result == " + str(index+1) + ")\n"
- result += indentation + "{\n"
- result += indentation + " \n"
- result += indentation + "}\n\n"
- options = []
- curopt = 1
- else:
- console.writeError("Incorrect menu nesting found!")
- result = text
- break
- continue
- if meat == "+++":
- if inchoice == 1:
- result += indentation + "title_start();\n"
- inchoice = 2
- elif inchoice == 2:
- result += indentation + "title_end();\n"
- inchoice = 1
- else:
- console.writeError("Incorrect menu nesting found!")
- result = text
- break
- continue
- if inchoice == 1:
- if meat[-1] == '"':
- options.append(meat.split('"')[1])
- result += line + "\n"
- editor.setText(result)
- editor.gotoPos(pos)
- editor.endUndoAction()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement