Advertisement
Guest User

BG3_dialog_script

a guest
Nov 3rd, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.11 KB | None | 0 0
  1. import re
  2.  
  3. dialog_script_path = input()
  4. dialog_script = open(dialog_script_path, encoding="utf8").readlines()
  5. translation_file = open("english.xml", encoding="utf8").readlines()
  6.  
  7. w_file_name = dialog_script_path.split("\\")[-1].split(".")[0]
  8.  
  9. f = open(str(w_file_name) + ".txt", "w")
  10.  
  11. actors_id = {"e0d1ff71-04a8-4340-ae64-9684d846eb83": "PC", "c7c13742-bacd-460a-8f65-f864fe41f255": "Astarion",
  12.           "ad9af97d-75da-406a-ae13-7071c563f604": "Gale", "98b9a4da-d3af-494e-890b-c8ec85d3146d": "Helia",
  13.           "0de603c5-42e2-4811-9dad-f652de080eba": "Minsc", "3ed74f06-3c60-42dc-83f6-f034cb47c679": "ShadowHeart",
  14.           "58a69333-40bf-8358-1d17-fff240d7fb12": "Laezel", "c774d764-4a17-48dc-b470-32ace9ce447d": "Wyll",
  15.           "2c76687d-93a2-477b-8b18-8a14b549304c": "Karlach"}
  16.  
  17. final_lines = []
  18.  
  19.  
  20. def get_actors():
  21.     actors_dict = {}
  22.     index = int
  23.     for line in dialog_script:
  24.         if '"index"' in line:
  25.             index = line.split(":")[-1][2]
  26.         if '"list"' in line:
  27.             temp_actor_id = line.split(":")[-1].split('"')[1]
  28.             if temp_actor_id in actors_id:
  29.                 actor_id = actors_id.get(temp_actor_id)
  30.             else:
  31.                 actor_id = "NPC"
  32.             actors_dict[index] = actor_id
  33.     return actors_dict
  34.  
  35.  
  36. def get_synopsis():
  37.     temp_line = str
  38.     for line in dialog_script:
  39.         if "synopsis" in line:
  40.             temp_line = line.split(":")[-1][1:-3]
  41.     return temp_line
  42.  
  43.  
  44. def get_lines():
  45.     actors = get_actors()
  46.     lines = []
  47.     dialog_line = str
  48.     for line in dialog_script:
  49.         if "handle" in line:
  50.             temp_line_id = line.split('"')[-2]
  51.             for line in translation_file:
  52.                 if temp_line_id in line:
  53.                     dialog_line = re.findall(u'>(.+?)<', line)[0]
  54.         if '"speaker"' in line:
  55.             if line.split(":")[-1][1].isdigit():
  56.                 actor = actors[line.split(":")[-1][1]]
  57.                 lines.append(actor + ': ' + str(dialog_line))
  58.     synopsis = get_synopsis()
  59.     lines.append("\nSynopsis: " + synopsis)
  60.     f.write("\n".join(lines))
  61.  
  62.  
  63. get_lines()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement