Beispiel #1
0
    author = False
    if (infileLines[0].startswith("@author")):
        author = True
    # Calc the max width of this ascii art
    maxwidth = 0
    for index, line in enumerate(infileLines):
        if (len(line) > maxwidth and (author == False or index > 0)):
            maxwidth = len(line)
    # Cal the height of the ascii art
    height = len(infileLines)
    if (author == True):
        height -= 1
    # Write the beginning of the Database.addAscii() call
    outfile.write("Database.addAscii(\"" + tup[1].replace("\\", "/") + "\", " +
                  str(maxwidth - 1) + ", " + str(height) + ", \n[\n")
    # Write the ascii art itself to the function call
    for index, line in enumerate(infileLines):
        if (
                line.startswith("@author") == False or index > 0
        ):  # We don't write the line if it starts with @author and its the first line
            outfile.write("\"" + jsFormat(line.rstrip()) + "\"")
            if (index < len(infileLines) -
                    1):  # We don't write the "," if we're the last line
                outfile.write(",")
            outfile.write("\n")
    # Write the end of the function call
    outfile.write("]);\n")

# We close the output file
outfile.close()
Beispiel #2
0
rootdir = "./../text/"
finalFileName = "./../code/gen/genText.ts"

# We get the list of files in each subdirectory
for root, subFolders, files in os.walk(rootdir):
    for file in files:
        fullPath = os.path.join(root, file)
        if(os.path.splitext(fullPath)[0].replace(rootdir, "") != "cauldron/en"): # We don't want to use cauldron/en because the cauldron english text is contained in the book ascii art
            tupleList.append((fullPath, os.path.splitext(fullPath)[0].replace(rootdir, "")))
        
# We open the output file
outfile = open(finalFileName, mode='w', encoding="utf-8")

# We copy the content of each file in a big "genText.ts" file
for tup in tupleList:
    # Open the input file
    infile = open(tup[0], 'r')
    
    # Write the Database.addText() function calls
    for index, line in enumerate(infile.readlines()):
        if(index % 2 == 0):
            line = line.split(' ', 1)[0]
            outfile.write("Database.addText(\"" + line.rstrip() + "\", ")
        else:
            outfile.write("\"" + jsFormat(line.rstrip()) + "\");\n")
    # Close the input file
    infile.close()

# We close the output file
outfile.close()