# Path: script_file.py
# class ScriptFile():
#   def __init__(self, filename = None, scene_info = None):
#     self.translated = ""
#     self.translated_notags = ""
#     self.original = ""
#     self.original_notags = ""
#     self.comments = ""
#     
#     self.filename = None
#     
#     if not filename == None:
#       self.open(filename)
#     
#       if scene_info == None:
#         # Squeeze the file ID out of the filename.
#         scene_info = SceneInfo(file_id = int(os.path.splitext(os.path.basename(filename))[0]))
#     
#     self.scene_info = scene_info
#   
#   def open(self, filename):
#     
#     if not filename or not os.path.isfile(filename):
#       return
#     
#     text = load_text(filename)
#     
#     self.from_data(text)
#     
#     self.filename = filename
#   
#   def from_data(self, data):
#     
#     self.filename = None
#     self.translated = ""
#     self.translated_notags = ""
#     self.original = ""
#     self.original_notags = ""
#     self.comments = ""
#     
#     # Sanitize our line-breaks. The game handles \r\n in some instances,
#     # but not all. It always handles \n properly.
#     text = LINE_BREAKS.sub("\n", data)
#     
#     match = TEXT_PARSER.search(text)
#     
#     if match:
#       # Remove any trailing linebreaks, because 
#       first_part = match.group(1)
#       second_part = match.group(2)
#       third_part = match.group(4)
#       
#       if not second_part:
#         self.original = first_part
#       else:
#         self.translated = first_part
#         self.original = second_part
#       
#       if third_part:
#         self.comments = third_part
#     
#     self.original_notags = TAG_KILLER.sub("", self.original)
#     self.translated_notags = TAG_KILLER.sub("", self.translated)
#   
#   ##############################################################################
#   ### @fn    pack()
#   ### @desc  Converts all the data into the script file format.
#   ### @param for_game -- Whether to include the original, untranslated data.
#   ###                    True = exclude untranslated, since we don't need it.
#   ##############################################################################
#   def pack(self, for_game = False):
#   
#     if self.translated == "":
#       output = u"\ufeff" + self.original + u"\u0000"
#       
#       if self.comments != "" and not for_game:
#         output += "\n[" + self.comments + "]"
#     else:
#       output = u"\ufeff" + self.translated + u"\u0000"
#       
#       if not for_game:
#         output +=  "\n" + self.original
#         if self.comments != "":
#           # We want a newline, but not a thousand.
#           if not self.original[-1] == '\n':
#             output += "\n"
#           
#           output += "[" + self.comments + "]"
#     
#     # Sanitize our line breaks, just in case.
#     output = LINE_BREAKS.sub("\n", output)
#     
#     return output
#   
#   def save(self, filename = None):
#     
#     if filename == None:
#       if self.filename == None:
#         return
#       else:
#         filename = self.filename
#     
#     output = self.pack(for_game = False)
#     
#     save_text(output, filename)


from bitstring import BitStream, ConstBitStream
from enum import Enum
from script_file import ScriptFile
import os
import re
import shutil
import time
import common
    if dat_file.pos >= dat_file.len:
      # If we don't have more data, then consider this untranslated.
      # Therefore, the data we collected becomes the data for the original anagram.
      easy_orig    = easy
      normal_orig  = normal
      hard_orig    = hard
      
      num_letters  = 0
      easy         = None
      normal       = None
      hard         = None
    else:
      # If we DO have more data, consider this translated and grab the
      # info about the untranslated anagram. This data is not used by the game,
      # only the translators.
      letters_orig = dat_file.read('uintle:16')
      easy_orig    = dat_file.read(letters_orig * 2 * 8)
      normal_orig  = dat_file.read(letters_orig * 2 * 8)
      if type == ANAGRAM_TYPE.Full:
        hard_orig  = dat_file.read(letters_orig * 2 * 8)
    
    ##########################################################
    ### Now convert all this into a useful format.
    ##########################################################
    base_dir = os.path.dirname(self.filename)
    
    self.type           = type
    self.solution_index = solution_index
    self.solution       = ScriptFile(os.path.join(base_dir, ANAGRAM_DIR, "%04d.txt" % self.solution_index))
    self.extra_index    = extra_index

# Path: script_file.py
# class ScriptFile():
#   def __init__(self, filename = None, scene_info = None):
#     self.translated = ""
#     self.translated_notags = ""
#     self.original = ""
#     self.original_notags = ""
#     self.comments = ""
#     
#     self.filename = None
#     
#     if not filename == None:
#       self.open(filename)
#     
#       if scene_info == None:
#         # Squeeze the file ID out of the filename.
#         scene_info = SceneInfo(file_id = int(os.path.splitext(os.path.basename(filename))[0]))
#     
#     self.scene_info = scene_info
#   
#   def open(self, filename):
#     
#     if not filename or not os.path.isfile(filename):
#       return
#     
#     text = load_text(filename)
#     
#     self.from_data(text)
#     
#     self.filename = filename
#   
#   def from_data(self, data):
#     
#     self.filename = None
#     self.translated = ""
#     self.translated_notags = ""
#     self.original = ""
#     self.original_notags = ""
#     self.comments = ""
#     
#     # Sanitize our line-breaks. The game handles \r\n in some instances,
#     # but not all. It always handles \n properly.
#     text = LINE_BREAKS.sub("\n", data)
#     
#     match = TEXT_PARSER.search(text)
#     
#     if match:
#       # Remove any trailing linebreaks, because 
#       first_part = match.group(1)
#       second_part = match.group(2)
#       third_part = match.group(4)
#       
#       if not second_part:
#         self.original = first_part
#       else:
#         self.translated = first_part
#         self.original = second_part
#       
#       if third_part:
#         self.comments = third_part
#     
#     self.original_notags = TAG_KILLER.sub("", self.original)
#     self.translated_notags = TAG_KILLER.sub("", self.translated)
#   
#   ##############################################################################
#   ### @fn    pack()
#   ### @desc  Converts all the data into the script file format.
#   ### @param for_game -- Whether to include the original, untranslated data.
#   ###                    True = exclude untranslated, since we don't need it.
#   ##############################################################################
#   def pack(self, for_game = False):
#   
#     if self.translated == "":
#       output = u"\ufeff" + self.original + u"\u0000"
#       
#       if self.comments != "" and not for_game:
#         output += "\n[" + self.comments + "]"
#     else:
#       output = u"\ufeff" + self.translated + u"\u0000"
#       
#       if not for_game:
#         output +=  "\n" + self.original
#         if self.comments != "":
#           # We want a newline, but not a thousand.
#           if not self.original[-1] == '\n':
#             output += "\n"
#           
#           output += "[" + self.comments + "]"
#     
#     # Sanitize our line breaks, just in case.
#     output = LINE_BREAKS.sub("\n", output)
#     
#     return output
#   
#   def save(self, filename = None):
#     
#     if filename == None:
#       if self.filename == None:
#         return
#       else:
#         filename = self.filename
#     
#     output = self.pack(for_game = False)
#     
#     save_text(output, filename)


# Path: anagram_file.py
from bitstring import BitStream, ConstBitStream
from enum import Enum
from script_file import ScriptFile
import os
import re
import shutil
import time
import common

    if dat_file.pos >= dat_file.len:
      # If we don't have more data, then consider this untranslated.
      # Therefore, the data we collected becomes the data for the original anagram.
      easy_orig    = easy
      normal_orig  = normal
      hard_orig    = hard
      
      num_letters  = 0
      easy         = None
      normal       = None
      hard         = None
    else:
      # If we DO have more data, consider this translated and grab the
      # info about the untranslated anagram. This data is not used by the game,
      # only the translators.
      letters_orig = dat_file.read('uintle:16')
      easy_orig    = dat_file.read(letters_orig * 2 * 8)
      normal_orig  = dat_file.read(letters_orig * 2 * 8)
      if type == ANAGRAM_TYPE.Full:
        hard_orig  = dat_file.read(letters_orig * 2 * 8)
    
    ##########################################################
    ### Now convert all this into a useful format.
    ##########################################################
    base_dir = os.path.dirname(self.filename)
    
    self.type           = type
    self.solution_index = solution_index
    self.solution       = ScriptFile(os.path.join(base_dir, ANAGRAM_DIR, "%04d.txt" % self.solution_index))
    self.extra_index    = extra_index

    self.extra          = ScriptFile(os.path.join(base_dir, ANAGRAM_DIR, "%04d.txt" % self.extra_index))