Guest User

DinkC_Talk.py

a guest
Jun 9th, 2014
54
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. editor.beginUndoAction()
  2.  
  3. pos = editor.getCurrentPos()
  4. chars = {}
  5. chars['>'] = "14 1".split()
  6. chars['<'] = "14 &current_sprite".split()
  7. result = ""
  8. waittime = 0
  9. colours = "1234567890!@#$%"
  10.  
  11. text = editor.getText().splitlines()
  12.  
  13. for line in text:
  14.   try:
  15.     front, back = line.split(None,1)
  16.   except:
  17.     result += line + "\n"
  18.     continue
  19.  
  20.   indentation = line[0:len(line) - len(line.lstrip())]
  21.   if len(front) == 3 and front[0:2] == "//":
  22.     if front[2] == '&':
  23.       waittime = int(back)
  24.     else:
  25.       chars[front[2]] = back.split()
  26.       chars[front[2]].append("&current_sprite")
  27.       chars[front[2]] = chars[front[2]][0:2]
  28.   elif len(front) == 1 and front[0] in chars:
  29.     colourcode, sprite = chars[front[0]]
  30.     colstr = "`" + colours[int(colourcode) - 1]
  31.     if colourcode == "14":
  32.       colstr = ""
  33.     result += indentation
  34.     result += "say_stop(\"" + colstr + back + "\"," + sprite + ");\n"
  35.     if waittime != 0:
  36.       result += indentation
  37.       result += "wait(" + str(waittime) + ");\n"
  38.     continue
  39.   result += line + "\n"
  40.  
  41. editor.setText(result)
  42. editor.gotoPos(pos)
  43.  
  44. editor.endUndoAction()
RAW Paste Data