Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #XML modifier based on http://cps05box.wikia.com/wiki/Cp-s05box_Wiki:SWF_Tricks/Tutorials/Scaling_up_SWF_files#Quick_Drop by Penguin-Pal (JavaScript code: http://cps05box.wikia.com/wiki/MediaWiki:Common.js/swfxml.js)
- #Coded in Python 3 and designed for use with SWiX
- #Author: Hey.youcp - Date: June 27, 2015 - Version: Not final
- anotherLoop = True
- while anotherLoop == True:
- #Open file
- fileLoop = True
- while fileLoop == True:
- fileName = input("Enter name of XML file (without file extension): ")
- fileFound = False
- try:
- inputFile = open(fileName + ".xml",'r')
- fileFound = True
- print("Loading...")
- XML = []
- for line in inputFile:
- XML.append(line)
- inputFile.close()
- fileLoop = False
- except FileNotFoundError:
- print("File not found. Check that the file name is correct and that the XML file is in the same directory as the Python file.")
- continueLoop = True
- while continueLoop == True:
- continueChoice = input("\tContinue? (y/n): ")
- if continueChoice == "y":
- continueLoop = False
- elif continueChoice == "n":
- continueLoop = False
- fileLoop = False
- anotherLoop = False
- else:
- print("\t\tInvalid input.")
- #Get modifications from user
- if fileFound == True:
- print("File loaded.\n")
- #Ask for move
- moveChoiceLoop = True
- while moveChoiceLoop == True:
- moveChoice = input("Move? (y/n): ")
- if moveChoice == "y":
- moveRightLoop = True
- while moveRightLoop == True:
- moveRight = input("\tMove right by: ")
- if moveRight.replace("+","").replace("-","").replace(".","").isdigit():
- moveRight = eval(moveRight)
- moveRightLoop = False
- else:
- print("\t\tInvalid input.")
- moveDownLoop = True
- while moveDownLoop == True:
- moveDown = input("\tMove down by: ")
- if moveDown.replace("+","").replace("-","").replace(".","").isdigit():
- moveDown = eval(moveDown)
- moveDownLoop = False
- moveChoiceLoop = False
- else:
- print("\t\tInvalid input.")
- elif moveChoice == "n":
- moveChoiceLoop = False
- else:
- print("\tInvalid input.")
- #Ask for rescale
- rescaleChoiceLoop = True
- while rescaleChoiceLoop == True:
- rescaleChoice = input("Rescale? (y/n): ")
- if rescaleChoice == "y":
- rescaleLoop = True
- while rescaleLoop == True:
- rescale = input("\tMultiply shape dimensions by: ")
- if rescale.replace("+","").replace("-","").replace(".","").isdigit():
- rescale = eval(rescale)
- rescaleLoop = False
- rescaleChoiceLoop = False
- else:
- print("\t\tInvalid input.")
- elif rescaleChoice == "n":
- rescale = 1
- rescaleChoiceLoop = False
- else:
- print("\tInvalid input.")
- #Ask for window size change
- windowSizeChoiceLoop = True
- while windowSizeChoiceLoop == True:
- windowSizeChoice = input("Change window size? (y/n): ")
- if windowSizeChoice == "y":
- windowSizeLoop = True
- while windowSizeLoop == True:
- windowSize = input("\tWindow size: ")
- if windowSize.replace("+","").replace("-","").replace(".","").isdigit():
- windowSizeLoop = False
- windowSizeChoiceLoop = False
- else:
- print("\t\tInvalid input.")
- elif windowSizeChoice == "n":
- windowSizeChoiceLoop = False
- else:
- print("\tInvalid input.")
- #Apply modifications
- print("\nProcessing...",end="")
- outputFile = open(fileName + "_edited.xml",'w')
- modCounter = 0
- for line in range(0,len(XML)):
- #Make sure every PlaceObject element has Matrix, Translate, and Scale elements
- if "<PlaceObject" in XML[line]:
- if "<Matrix>" in XML[line+1]:
- if "<Translate" not in XML[line+2]:
- XML[line+1] += " <Translate TranslateX=\"0\" TranslateY=\"0\" />"
- modCounter += 1
- if "<Scale" not in XML[line+3]:
- XML[line+2] += " <Scale ScaleX=\"1\" ScaleY=\"1\" />"
- modCounter += 1
- else:
- XML[line] += " <Matrix> <Translate TranslateX=\"0\" TranslateY=\"0\" /> <Scale ScaleX=\"1\" ScaleY=\"1\" /> </Matrix>"
- modCounter += 1
- #Apply window size change
- if windowSizeChoice == "y":
- if "<Movie SwfVersion=" in XML[line]:
- splitLine = XML[line].split()
- splitLine[2] = "Width=\"" + windowSize + "\""
- splitLine[3] = "Height=\"" + windowSize + "\""
- for element in range(0,len(splitLine)):
- if element == 0:
- XML[line] = splitLine[0] + " "
- else:
- XML[line] += splitLine[element] + " "
- modCounter += 1
- #Apply move
- if moveChoice == "y":
- if "<Translate" in XML[line]:
- splitLine = XML[line].split()
- if len(splitLine) == 4 or len(splitLine) == 8:
- moveX = eval(splitLine[1].replace("TranslateX=","").replace("\"",""))
- moveY = eval(splitLine[2].replace("TranslateY=","").replace("\"",""))
- moveX = (moveX + moveRight) * rescale
- moveY = (moveY + moveDown) * rescale
- splitLine[1] = "TranslateX=\"" + str(moveX) + "\""
- splitLine[2] = "TranslateY=\"" + str(moveY) + "\""
- elif len(splitLine) == 14:
- moveX = eval(splitLine[6].replace("TranslateX=","").replace("\"",""))
- moveY = eval(splitLine[7].replace("TranslateY=","").replace("\"",""))
- moveX = (moveX + moveRight) * rescale
- moveY = (moveY + moveDown) * rescale
- splitLine[6] = "TranslateX=\"" + str(moveX) + "\""
- splitLine[7] = "TranslateY=\"" + str(moveY) + "\""
- else:
- print("\nError. Length of splitLine for move is " + str(len(splitLine)) + ". Please report this error. Content of splitLine:")
- print(splitLine)
- break
- for element in range(0,len(splitLine)):
- if element == 0:
- XML[line] = splitLine[0] + " "
- else:
- XML[line] += splitLine[element] + " "
- modCounter += 1
- #Apply rescale
- if rescaleChoice == "y":
- if "<Scale" in XML[line]:
- splitLine = XML[line].split()
- if len(splitLine) == 4:
- rescaleX = eval(splitLine[1].replace("ScaleX=","").replace("\"",""))
- rescaleY = eval(splitLine[2].replace("ScaleY=","").replace("\"",""))
- rescaleX *= rescale
- rescaleY *= rescale
- splitLine[1] = "ScaleX=\"" + str(rescaleX) + "\""
- splitLine[2] = "ScaleY=\"" + str(rescaleY) + "\""
- elif len(splitLine) == 8:
- rescaleX = eval(splitLine[5].replace("ScaleX=","").replace("\"",""))
- rescaleY = eval(splitLine[6].replace("ScaleY=","").replace("\"",""))
- rescaleX *= rescale
- rescaleY *= rescale
- splitLine[5] = "ScaleX=\"" + str(rescaleX) + "\""
- splitLine[6] = "ScaleY=\"" + str(rescaleY) + "\""
- elif len(splitLine) == 14:
- rescaleX = eval(splitLine[10].replace("ScaleX=","").replace("\"",""))
- rescaleY = eval(splitLine[11].replace("ScaleY=","").replace("\"",""))
- rescaleX *= rescale
- rescaleY *= rescale
- splitLine[10] = "ScaleX=\"" + str(rescaleX) + "\""
- splitLine[11] = "ScaleY=\"" + str(rescaleY) + "\""
- else:
- print("\nError. Length of splitLine for rescale is " + str(len(splitLine)) + ". Please report this error. Content of splitLine:")
- print(splitLine)
- break
- for element in range(0,len(splitLine)):
- if element == 0:
- XML[line] = splitLine[0] + " "
- else:
- XML[line] += splitLine[element] + " "
- modCounter += 1
- outputFile.write(XML[line])
- #Done
- outputFile.close()
- print("\n" + str(modCounter) + " modifications made in " + str(len(XML)) + " line(s).")
- print("Look for a file named \"" + fileName + "_edited.xml\" in your directory.\n")
- anotherChoiceLoop = True
- while anotherChoiceLoop == True:
- anotherChoice = input("Modify another XML file? (y/n): ")
- if anotherChoice == "y":
- anotherChoiceLoop = False
- elif anotherChoice == "n":
- anotherChoiceLoop = False
- anotherLoop = False
- else:
- print("\tInvalid input.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement