Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- import platform
- import struct
- import pprint
- import re
- import copy
- import math
- import zipfile
- import tempfile
- import Tkinter as tk
- import tkFileDialog as tkfd
- try:
- from PIL import Image, ImageTk
- except:
- print "PIL not found!"
- print "Install PIL or Pillow as such:"
- print "pip install python-PIL"
- print "pip install Pillow"
- print "Note that this code was not tested with Pillow; if PIL is unavailable it should work fine with Pillow, but if not, contact the script author"
- try:
- import png
- except:
- print "PyPNG not found!"
- print "If you're running this program to pack files you should be fine. Otherwise, install PyPNG as such:"
- print "pip install pypng"
- try:
- from colorama import Fore, Back, Style
- import colorama
- colorama.init()
- except:
- print "Colorama not found!"
- print "Colorama is completely unnecessary, but the console output for packing files might be ugly."
- # Defining Fore, Back, and Style, so they don't crash without Colorama
- # We need to make getters for the functions so that they work as Fore.BLACK and not just Fore.BLACK()
- def constant(f):
- def fset(self, value):
- raise TypeError
- def fget(self):
- return f()
- return property(fget, fset)
- # Define everything as returning "" so we can just append an empty string
- class coloramaFunc():
- @constant
- def GREEN():
- return ""
- @constant
- def RED():
- return ""
- @constant
- def BLACK():
- return ""
- @constant
- def RESET_ALL():
- return ""
- # Since Fore, Back, and Style are all just going to append empty strings, we don't need different functions for different ones
- Fore = coloramaFunc()
- Back = coloramaFunc()
- Style = coloramaFunc()
- pp = pprint.PrettyPrinter(depth=6)
- def LoadBaseFile():
- root = tk.Tk()
- root.withdraw()
- baseFieldPath = tkfd.askopenfilename(parent=root)
- baseFieldInfo = os.stat(baseFieldPath)
- baseFieldSize = baseFieldInfo.st_size
- fieldSizeTable = {
- 968: 88,
- 1040: 104,
- 1056: 88,
- 1152: 96,
- 1352: 104,
- 1568: 112,
- 1800: 120
- }
- return baseFieldPath, fieldSizeTable[baseFieldSize], baseFieldSize
- def LoadPNG():
- root = tk.Tk()
- root.withdraw()
- path = tkfd.askopenfilename(parent=root)
- r = png.Reader(filename=path)
- read = r.asRGB()
- pixelArray = list(read[2])
- width = read[0]
- height = read[1]
- return path, width, height, pixelArray
- def LoadFLDs():
- root = tk.Tk()
- root.withdraw()
- fieldList = tkfd.askopenfilenames(parent=root)
- # On Windows Python 2.6-2.7.6, askopenfilenames returns a Unicode string instead of a tuple >:I
- if type(fieldList) != tuple:
- if type(fieldList) is unicode or type(fieldList) is str:
- fieldList = root.tk.splitlist(fieldList)
- else:
- # As far as I know, this should never trigger, but computers are wily ones. Information is ordered from least to most likely to crash the program
- print "Unknown variable type for fieldList!"
- print "Please report this error and the following info to the script author :)"
- print type(fieldList), type(type(fieldList))
- print platform.platform(), platform.system(), platform.python_version()
- print platform.python_implementation(), platform.python_build()
- fieldSlotTable = {
- 968: ["field_clover.fld", "field_nightflight.fld", "field_practice.fld", "field_pudding.fld", "field_tomomo.fld", "field_vortex.fld", "field_wander.fld", "field_war.fld"],
- 1040: ["field_shipyard.fld"],
- 1056: [],
- 1152: ["field_starship.fld"],
- 1352: ["field_christmas.fld", "field_frost.fld", "field_island.fld", "field_islandnight.fld", "field_lagoon.fld"],
- 1568: ["field_winter.fld"],
- 1800: ["field_farm.fld", "field_highway.fld", "field_planet.fld", "field_seal.fld", "field_starcircuit.fld", "field_sunset.fld", "field_sweetheaven.fld", "field_training.fld"]
- }
- customMapTable = {
- 968: [1,2,3,4,5,6,7,8],
- 1040: [1,],
- 1056: [],
- 1152: [1,],
- 1352: [1,2,3,4,5],
- 1568: [1,],
- 1800: [1,2,3,4,5,6,7,8]
- }
- listOfMapsThatNeedAutoPadding = []
- correspondingListOfSizesToBePaddedTo = []
- # Iterating over the list of custom apps that were selected by the user; we insert the map in the first slot that's big enough
- for customMap in fieldList:
- foundMatch = 0
- info = os.stat(customMap)
- fieldSize = info.st_size
- for size,slotList in sorted(customMapTable.iteritems()):
- if size > fieldSize:
- if customMap not in listOfMapsThatNeedAutoPadding:
- listOfMapsThatNeedAutoPadding.append(customMap)
- correspondingListOfSizesToBePaddedTo.append(size)
- if fieldSize > size:
- pass
- else:
- for position in xrange(len(slotList)):
- #print size,fieldSize,position
- if type(slotList[position]) is int:
- slotList[position] = customMap
- foundMatch = 1
- break
- if foundMatch == 1:
- break
- # Padding out the rest of the map with default maps
- for size,cMapList in sorted(customMapTable.iteritems()):
- for slot in xrange(len(cMapList)):
- try:
- if type(cMapList[slot]) is int:
- cMapList[slot] = fieldSlotTable[size][slot]
- except:
- pass
- paddedMaps = {}
- for i in xrange(len(listOfMapsThatNeedAutoPadding)):
- paddedMaps[listOfMapsThatNeedAutoPadding[i]] = AutoPadMap(listOfMapsThatNeedAutoPadding[i],correspondingListOfSizesToBePaddedTo[i])
- return fieldList,customMapTable,fieldSlotTable, listOfMapsThatNeedAutoPadding, paddedMaps
- def AutoPadMap(cMap,necessarySize):
- # If a map is originally a smaller size than the size it's being imported as, we need to pad to make sure the width of the map matches the width of the slot it's going into
- mapSize = os.stat(cMap).st_size
- # fileSize: width in bytes
- fieldSizeTable = {
- 968: 88,
- 1040: 104,
- 1056: 88,
- 1152: 96,
- 1352: 104,
- 1568: 112,
- 1800: 120
- }
- # We need to increase the width of the map to match the new size, so every row should gain (nWidth - oWidth) bytes, where one tile is 8 bytes
- widthIncrement = fieldSizeTable[necessarySize] - fieldSizeTable[mapSize]
- # This next bit is very similar to CreateFieldArray, but for technical reasons it's probably best to have them separate
- smallFieldArray = []
- smallField = open(cMap,"rb")
- try:
- bytes = smallField.read(2)
- while bytes != "":
- smallFieldArray.append(struct.unpack("h", bytes)[0])
- bytes = smallField.read(2)
- finally:
- smallField.close()
- bigField = {0: []}
- count = 0
- pFARow = 0
- for i in smallFieldArray:
- if count%2 == 0:
- bigField[pFARow].append(hex(i)[2:])
- count += 1
- if count == fieldSizeTable[mapSize]/2:
- for i in xrange(widthIncrement/4): # Padding
- bigField[pFARow].append("0")
- count = 0
- pFARow += 1
- bigField[pFARow] = []
- tempMapFile = tempfile.NamedTemporaryFile(delete=False,dir=os.path.dirname(os.path.abspath(__file__)))
- for rowIdx in bigField:
- for i in bigField[rowIdx]:
- tempMapFile.write(struct.pack("h",int(i,16)))
- tempMapFile.write(buffer("\x00\x00"))
- tempMapFile.close()
- return tempMapFile
- def DEBUGPrintCustomMapTable(cmt):
- # Can't believe I'm writing for the Connecticut Mastery Test
- for key,value in sorted(cmt.iteritems()):
- print key,value
- def CreateFieldArray(path,size):
- fieldArray = []
- baseField = open(path, "rb")
- try:
- bytes = baseField.read(2)
- while bytes != "":
- fieldArray.append(struct.unpack("h", bytes)[0])
- bytes = baseField.read(2)
- finally:
- baseField.close()
- prettyFieldArray = {0: []}
- count = 0
- pFARow = 0
- for i in fieldArray:
- if count%2 == 0:
- #print hex(i)[2:],
- prettyFieldArray[pFARow].append(hex(i)[2:])
- count += 1
- if count == size/2:
- #print "\n"
- count = 0
- pFARow += 1
- prettyFieldArray[pFARow] = []
- return prettyFieldArray
- def TurnArrayIntoPixels(array):
- palette = {
- 0: (0x00,0x00,0x00),
- 1: (0x7f,0x7f,0x7f),
- 2: (0xff,0x7f,0x27),
- 3: (0xed,0x1c,0x24),
- 4: (0x22,0xb1,0x4c),
- 5: (0xff,0xc9,0x0e),
- 6: (0x3f,0x48,0xcc),
- 7: (0xa3,0x49,0xa4),
- 8: (0x0b,0x62,0x0f),
- 9: (0xae,0x87,0x00),
- 10: (0x1c,0x21,0x66),
- 11: (0xff,0xff,0xff),
- 12: (0xff,0xff,0xff),
- 13: (0xff,0xff,0xff),
- 14: (0xff,0xff,0xff),
- 15: (0xff,0xff,0xff),
- 16: (0xff,0xff,0xff),
- 17: (0xff,0xff,0xff),
- 18: (0x98,0x47,0x0c),
- 19: (0xff,0xff,0xff),
- 20: (0x88,0x00,0x15),
- 21: (0x00,0xa2,0xe8),
- 22: (0x00,0x83,0xbb),
- 23: (0xe2,0x38,0x9a),
- 24: (0xa2,0x17,0x67),
- 25: (0x99,0xd9,0xea)
- }
- pixelList = [[]]
- rowCount = 0
- colCount = 0
- for row in array:
- for i in array[row]:
- if colCount == 0:
- pixel = palette[int(i, 16)]
- pixelList[rowCount].append(pixel[0])
- pixelList[rowCount].append(pixel[1])
- pixelList[rowCount].append(pixel[2])
- colCount = 1
- else:
- colCount = 0
- pixelList.append([])
- rowCount += 1
- pixelList.pop()
- pixelList.pop()
- return pixelList
- def CreateImageFromPixels(pixelList, fileSize, size, path):
- m = re.search("([^/]+)/?$", path)
- newPath = m.group(0)[0:-4] + ".png"
- outputImage = open(newPath, "wb")
- height = fileSize/size
- width = size/8
- writer = png.Writer(width, height)
- writer.write(outputImage, pixelList)
- outputImage.close()
- return os.path.realpath(outputImage.name)
- def generateArrayFromPicture(pixels):
- tileArray = []
- for i in pixels:
- numberOfPixels = len(i)/3
- for j in range(0,numberOfPixels):
- nextPixel = (i.pop(0), i.pop(0), i.pop(0))
- pixelID = checkIfPixelInPalette(nextPixel)
- tileArray.append(pixelID)
- return tileArray
- def checkIfPixelInPalette(pixel):
- palette = {
- 0: (0x00,0x00,0x00),
- 1: (0x7f,0x7f,0x7f),
- 2: (0xff,0x7f,0x27),
- 3: (0xed,0x1c,0x24),
- 4: (0x22,0xb1,0x4c),
- 5: (0xff,0xc9,0x0e),
- 6: (0x3f,0x48,0xcc),
- 7: (0xa3,0x49,0xa4),
- 8: (0x0b,0x62,0x0f),
- 9: (0xae,0x87,0x00),
- 10: (0x1c,0x21,0x66),
- 11: (0xf0,0xf0,0xf0),
- 12: (0xf0,0xf0,0xf0),
- 13: (0xf0,0xf0,0xf0),
- 14: (0xf0,0xf0,0xf0),
- 15: (0xf0,0xf0,0xf0),
- 16: (0xf0,0xf0,0xf0),
- 17: (0xf0,0xf0,0xf0),
- 18: (0x98,0x47,0x0c),
- 19: (0xf0,0xf0,0xf0),
- 20: (0x88,0x00,0x15),
- 21: (0x00,0xa2,0xe8),
- 22: (0x00,0x83,0xbb),
- 23: (0xe2,0x38,0x9a),
- 24: (0xa2,0x17,0x67),
- 25: (0x99,0xd9,0xea)
- }
- for i in palette:
- if pixel[0] == palette[i][0]:
- if pixel[1] == palette[i][1]:
- if pixel[2] == palette[i][2]:
- return i
- return 99
- def downsizePixelArray(pixelArray):
- # Downsizes the pixel array, saving every third pixel
- # This effectively removes movement data, leaving only tile data
- downsizedPixelArray = []
- # Iterate over each row of pixels
- rowCount = 0
- for row in pixelArray:
- downsizedPixelArray.append([])
- colCount = 0
- for j in row:
- if colCount <3: #<3
- # If this is the first pixel, take all three RGB channels and insert them into the downsized array
- downsizedPixelArray[rowCount].append(j)
- colCount += 1
- elif colCount <8:
- # If this isn't the first pixel, ignore it
- colCount += 1
- else:
- # If this is the 9th byte, loop the counter and ignore it
- colCount = 0
- colCount = 0
- rowCount += 1
- #Only every third row is relevant to us, so we'll make a new list that only has the rows we want
- downsizedArrayFixed = []
- for i in range(len(downsizedPixelArray)):
- if (i+1)%3 == 1:
- downsizedArrayFixed.append(copy.deepcopy(downsizedPixelArray[i]))
- return downsizedArrayFixed
- def generateMovementPixelArray(pixelArray):
- """
- We need to check the colour of each pixel. If it's #404040 (64 64 64) it's an entrance;
- if it's pure white (255 255 255) it's an exit. For any pixel,
- we immediately disregard it.
- """
- movementArray = []
- count = 0
- for i in pixelArray:
- movementArray.append([])
- for j in xrange(0,len(i),3):
- if i[j] == 255: # Check if the R value is 255
- if i[j+1] == 255: # Check G
- if i[j+2] == 255: # Check B
- movementArray[count].append(255)
- else:
- movementArray[count].append(0)
- else:
- movementArray[count].append(0)
- elif i[j] == 64: # Check if the R value is 64
- if i[j+1] == 64: # Check G
- if i[j+2] == 64: # Check B
- movementArray[count].append(64)
- else:
- movementArray[count].append(0)
- else:
- movementArray[count].append(0)
- else: # Not a movement tile!
- movementArray[count].append(0)
- count += 1
- #DEBUGPrintTilePixelArray(movementArray)
- # Now we want to turn the pixel array into an array of bitflags
- bitflagArray = []
- for rowIdx in xrange(0,len(movementArray)):
- # Set up movementArray to be clearer for later
- for pxIdx in xrange(0,len(movementArray[rowIdx])):
- if movementArray[rowIdx][pxIdx] == 64:
- movementArray[rowIdx][pxIdx] = "N"
- elif movementArray[rowIdx][pxIdx] == 255:
- movementArray[rowIdx][pxIdx] = "X"
- else:
- movementArray[rowIdx][pxIdx] = "0"
- tileLength = len(movementArray[0])/3
- colCount = 0
- bitflagArray.append([])
- for i in xrange(0,tileLength):
- bitflagArray[rowIdx].append([])
- # Depending on which row we're in, we care about different pixels
- if rowIdx % 3 == 0: # We care about every other pixel starting at 1
- for pxIdx in xrange(1,tileLength*3,3): # If we're on an odd row, we only care about the second pixel of every tile (every third pixel, starting at 1)
- flag = movementArray[rowIdx][pxIdx]
- # Append the flag to the current tile's (row one) flag list
- bitflagArray[rowIdx][colCount].append(flag)
- colCount += 1
- elif rowIdx % 3 == 1: # If we're on an even row, we care about the first and third pixel of every tile (every other, starting at 0)
- pxIdxList = range(0,tileLength*3)
- del pxIdxList[1::3]
- for pxIdx in pxIdxList:
- flag = movementArray[rowIdx][pxIdx]
- # We append both left and right flags to the same tile's list here. Later, we'll combine the three lists for each tile into one
- if pxIdx % 3 == 0:
- bitflagArray[rowIdx][int(math.floor(colCount/2))].append(flag)
- elif pxIdx % 3 == 2:
- bitflagArray[rowIdx][int(math.floor(colCount/2))].append(flag)
- colCount += 1
- else:
- for pxIdx in xrange(1,tileLength*3,3):
- flag = movementArray[rowIdx][pxIdx]
- bitflagArray[rowIdx][colCount].append(flag)
- colCount += 1
- #for i in bitflagArray:
- # print i
- # Next, we need to condense our rows, as currently we have the information for each tile split across three rows
- condensedBitflagArray = []
- for rowIdx in xrange(0,len(bitflagArray),3):
- condensedBitflagArray.append([])
- for tileIdx in xrange(0,len(bitflagArray[rowIdx])):
- condensedTile = [bitflagArray[rowIdx][tileIdx][0],
- bitflagArray[rowIdx+1][tileIdx][0],
- bitflagArray[rowIdx+1][tileIdx][1],
- bitflagArray[rowIdx+2][tileIdx][0]]
- condensedBitflagArray[rowIdx/3].append(condensedTile)
- # Finally, for each tile, we compile the movement info into a single bitflag
- finalBitflagArray = []
- for rowIdx in xrange(0,len(condensedBitflagArray)):
- finalBitflagArray.append([])
- for tileIdx in xrange(0,len(condensedBitflagArray[rowIdx])):
- bitflag = 0
- tileData = condensedBitflagArray[rowIdx][tileIdx]
- if tileData[0] == "X":
- bitflag += 2
- elif tileData[0] == "N":
- bitflag += 32
- if tileData[1] == "X":
- bitflag += 1
- elif tileData[1] == "N":
- bitflag += 16
- if tileData[2] == "X":
- bitflag += 4
- elif tileData[2] == "N":
- bitflag += 64
- if tileData[3] == "X":
- bitflag += 8
- elif tileData[3] == "N":
- bitflag += 128
- finalBitflagArray[rowIdx].append(bitflag)
- return finalBitflagArray
- def CreateMapFromTileAndBitflags(tileArray,bitflagArray,path):
- m = re.search("([^/]+)/?$", path)
- newPath = m.group(0)[0:-4] + ".fld"
- outputFile = open(newPath, "wb")
- oneDBitflagTable = []
- for i in xrange(0,len(bitflagArray)):
- for j in xrange(0,len(bitflagArray[i])):
- oneDBitflagTable.append(bitflagArray[i][j])
- #print len(tileArray),len(oneDBitflagTable)
- for i in xrange(len(tileArray)):
- outputFile.write(struct.pack("h",tileArray[i]))
- outputFile.write(buffer("\x00\x00"))
- outputFile.write(struct.pack("h",oneDBitflagTable[i]))
- outputFile.write(buffer("\x00\x00"))
- def DEBUGPrintTilePixelArray(tilePixelArray):
- for i in tilePixelArray:
- for num in i:
- if num == 0:
- print " .",
- else:
- print "%3d" % num,
- print "\n",
- def DEBUGPrintBitflagArray(bitflagArray):
- for row in bitflagArray:
- for px in row:
- if px == 0:
- print ".\t",
- else:
- print hex(px)[2::] + "\t",
- print ""
- def DEBUGPrintTileArray(tileArray,width):
- tileWidth = width/3
- count = 0
- for i in tileArray:
- if i == 0:
- print " .\t",
- else:
- print "%2d\t" % i,
- count += 1
- if count >= tileWidth:
- print "\n",
- count = 0
- def DEBUGPrintMapPadding(tileArray):
- for rowIdx in tileArray:
- for i in tileArray[rowIdx]:
- print i,"\t",
- print ""
- def FLDtoPNG():
- # Converts a FLD to a PNG file
- # Here we load the FLD file, create an array from it, convert the tile IDs into appropriate pixels, and save an image of it
- path, size, fileSize = LoadBaseFile()
- FieldArray = CreateFieldArray(path, size)
- pixelVer = TurnArrayIntoPixels(FieldArray)
- imageName = CreateImageFromPixels(pixelVer, fileSize, size, path)
- # Next we draw the image to the program window for the user to see
- # First, label the globals that we need for our GUI
- global canvas
- global currentImage1
- global currentName
- global currentSize
- global currentHeight
- global currentWidth
- # Next we print the relevant text for this map
- m = re.search("([^/]+)/?$", path)
- currentName.set("Field Name:\n" + m.group(0)[0:-4])
- currentSize.set("Size:\n" + str(fileSize) + " bytes")
- currentHeight.set("Height:\n" + str(fileSize/size) + " tiles")
- currentWidth.set("Width:\n" + str(size/8) + " tiles")
- # Finally, we display the image to the screen
- pilImage = Image.open(imageName)
- pilImage = pilImage.transform((pilImage.width*10,pilImage.height*10),Image.EXTENT,(0,0,pilImage.width,pilImage.height))
- currentImage1 = ImageTk.PhotoImage(pilImage)
- tilePreview = canvas.create_image(77,77,image=currentImage1)
- def PNGtoFLD():
- path, width, height, fullPixelArray = LoadPNG()
- for i in range(height):
- fullPixelArray[i] = list(fullPixelArray[i])
- # Cut out all the movement pixels so that we can process just the tiles
- tilePixelArray = copy.deepcopy(fullPixelArray)
- tilePixelArray = downsizePixelArray(tilePixelArray)
- # Label our globals
- global canvas
- global currentImage1
- global currentImage2
- global currentName
- global currentSize
- global currentHeight
- global currentWidth
- # Print the relevant text for this map
- m = re.search("([^/]+)/?$", path)
- currentName.set("Field Name:\n" + m.group(0)[0:-4])
- fileSize = (width/3)*(height/3)*8
- currentSize.set("Size:\n" + str(fileSize) + " bytes")
- currentHeight.set("Height:\n" + str(height/3) + " tiles")
- currentWidth.set("Width:\n" + str(width/3) + " tiles")
- # Create an image out of just the tile pixels, so we can draw it to the canvas
- tpaCopy = copy.deepcopy(tilePixelArray)
- data = ""
- for row in tpaCopy:
- for col in row:
- data = data + struct.pack("B",col)
- tileImage = Image.frombytes("RGB",((width/3),(height/3)),data)
- tileImage = tileImage.transform((tileImage.width*10,tileImage.height*10),Image.EXTENT,(0,0,tileImage.width,tileImage.height))
- # Next, we have to convert the image to a form Tkinter can use
- currentImage1 = ImageTk.PhotoImage(tileImage)
- tilePreview = canvas.create_image(77,77,image=currentImage1)
- tileArray = generateArrayFromPicture(tilePixelArray)
- #DEBUGPrintTileArray(tileArray,width)
- print ""
- movementArray = generateMovementPixelArray(fullPixelArray)
- #DEBUGPrintBitflagArray(movementArray)
- print ""
- CreateMapFromTileAndBitflags(tileArray,movementArray,path)
- def FLDtoPAK():
- fieldList,cMapTable,officialFieldList,listOfPaddedMaps,paddedMaps = LoadFLDs()
- outputFile = zipfile.ZipFile("fields.pak",mode="w")
- for size,mapList in sorted(cMapTable.iteritems()):
- for index in xrange(len(mapList)):
- # C'e la luna, mezzo mare...
- # First we clip out the part of the math that's just path, so that it looks pretty when printed to the console
- m = re.search("([^/]+)/?$", mapList[index])
- newPath = m.group(0)
- # Now we check if the map is one of the user-supplied maps, and if it is, we print it brighter
- if mapList[index] in fieldList:
- print Back.GREEN + Fore.BLACK + newPath + Style.RESET_ALL + " will be exported as ",
- # We also change newPath to mapList[index], so that we can reference the proper file from newPath later
- # If we don't do this, we'd have to do another check to see if the map is official when writing it to the archive
- newPath = mapList[index]
- else:
- print Fore.GREEN + newPath + Style.RESET_ALL + " will be exported as ",
- # We also need to change the path to the path to the official file
- newPath = "OfficialFiles\\" + newPath
- # ...and if the file had to be padded, we print the red brighter and use the temp file
- if mapList[index] in listOfPaddedMaps:
- print Back.RED + Fore.BLACK + officialFieldList[size][index] + Style.RESET_ALL
- outputFile.write(paddedMaps[mapList[index]].name, arcname=officialFieldList[size][index])
- else:
- print Fore.RED + officialFieldList[size][index] + Style.RESET_ALL
- outputFile.write(newPath, arcname=officialFieldList[size][index])
- graphicsList = [
- "aurora.dat",
- "christmas_h.dat", "christmas_l.dat", "christmas_o.dat",
- "clover_l.dat",
- "empty.dat",
- "farm_h.dat", "farm_l.dat",
- "frost_l.dat",
- "highway_l.dat", "highway_o.dat",
- "island_h.dat", "island_l.dat",
- "islandnight_h.dat", "islandnight_l.dat",
- "lagoon_h.dat", "lagoon_l.dat",
- "nightflight_h.dat", "nightflight_l.dat", "nightflight_o.dat",
- "planet_h.dat", "planet_l.dat",
- "practice_l.dat",
- "pudding_l.dat",
- "seal_h.dat", "seal_l.dat", "seal_o.dat",
- "shipyard_h.dat", "shipyard_l.dat",
- "starcircuit_l.dat", "starcircuit_h.dat",
- "starship_h.dat", "starship_l.dat", "starship_o.dat",
- "sunset_h.dat", "sunset_l.dat", "sunset_o.dat",
- "sweet_h.dat", "sweet_l.dat",
- "tomomo_h.dat", "tomomo_l.dat", "tomomo_o.dat",
- "training_e.dat", "training_h.dat", "training_l.dat",
- "vortex_h.dat", "vortex_l.dat",
- "wander_h.dat", "wander_l.dat",
- "war_h.dat", "war_l.dat", "war_o.dat",
- "winter_l.dat"
- ]
- for i in graphicsList:
- newPath = "OfficialFiles\\" + i
- outputFile.write(newPath,arcname=i)
- outputFile.close()
- for i in paddedMaps:
- paddedMaps[i].close()
- os.unlink(paddedMaps[i].name)
- def FLDtoPAK_GUI():
- root = tk.Tk()
- menu = tk.Menu(root)
- root.config(menu=menu)
- root.geometry("308x300")
- root.wm_title("100% Orange Juice Field Editing Tool")
- root.iconbitmap('favicon.ico')
- filemenu = tk.Menu(menu)
- menu.add_cascade(label="File", menu=filemenu)
- filemenu.add_command(label="FLD to PNG", command=FLDtoPNG)
- filemenu.add_command(label="PNG to FLD", command=PNGtoFLD)
- filemenu.add_command(label="FLDs to PAK", command=FLDtoPAK)
- filemenu.add_command(label="DEBUG", command=DEBUGPrintImageData)
- filemenu.add_command(label="Exit", command=exitProgram)
- # Because we're referencing these GUI elements in other functions, we need to make them globals
- # Names are deliberately chosen such that they'd be unlikely to come up in other places outside of GUI stuff
- global canvas
- global currentImage1
- global currentImage2
- global topPane
- global rightPane
- global currentName
- global currentSize
- global currentHeight
- global currentWidth
- # In order to have the names auto-update later, they need to be converted from string vars to StringVars
- currentName = tk.StringVar()
- currentSize = tk.StringVar()
- currentHeight = tk.StringVar()
- currentWidth = tk.StringVar()
- topPane = tk.Frame(root, width=300, height=150)
- topPane.grid(row=0,column=0,sticky="w")
- leftPane = tk.Frame(root, width=150, height=150, bg="black")
- leftPane.grid(row=1,column=0,sticky="w")
- rightPane = tk.Frame(root, width=150, height=150, bg="black")
- rightPane.grid(row=1,column=1,sticky="w")
- canvas = tk.Canvas(leftPane, width=150, height=150, bg="dark slate gray")
- canvas.pack()
- canvas2 = tk.Canvas(rightPane, width=150, height=150, bg="dark slate gray")
- canvas2.pack()
- currentName.set("Field Name:\n")
- currentSize.set("Size:\n")
- currentHeight.set("Height:\n")
- currentWidth.set("Width:\n")
- nameLbl = tk.Label(topPane, textvariable=currentName, anchor="w", justify="left")
- sizeLbl = tk.Label(topPane, textvariable=currentSize, anchor="w", justify="left")
- heightLbl = tk.Label(topPane, textvariable=currentHeight, anchor="w", justify="left")
- widthLbl = tk.Label(topPane, textvariable=currentWidth, anchor="w", justify="left")
- nameLbl.pack(fill="x")
- sizeLbl.pack(fill="x")
- heightLbl.pack(fill="x")
- widthLbl.pack(fill="x")
- root.protocol("WM_DELETE_WINDOW", exitProgram)
- root.mainloop()
- sys.exit()
- def DEBUGPrintImageData():
- print currentImage.height()
- print currentImage.width()
- def exitProgram():
- sys.exit()
- FLDtoPAK_GUI()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement