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 26, 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.")
- if fileFound == True:
- print("File loaded.\n")
- #Get modifications from user
- 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.")
- 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.")
- 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("output.xml",'w')
- modCounter = 0
- for line in range(0,len(xml)):
- if windowSizeChoice == "y":
- if "<Movie SwfVersion=" in xml[line]:
- splitLine = xml[line].split()
- splitLine[2] = "Width=\"" + windowSize + "\""
- splitLine[3] = "Height=\"" + windowSize + "\""
- xml[line] = splitLine[0] + " " + splitLine[1] + " " + splitLine[2] + " " + splitLine[3] + " " + splitLine[4] + " " + splitLine[5] + "\n"
- modCounter += 1
- if moveChoice == "y":
- if "<Translate" in xml[line] and "TranslateX=\"0\"" not in xml[line] and "TranslateY=\"0\"" not in xml[line]:
- splitLine = xml[line].split()
- 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) + "\""
- xml[line] = "\t\t\t" + splitLine[0] + " " + splitLine[1] + " " + splitLine[2] + " " + splitLine[3]
- modCounter += 1
- if rescaleChoice == "y":
- if "<Translate" in xml[line] and "TranslateX=\"0\"" not in xml[line] and "TranslateY=\"0\"" not in xml[line]:
- if "<Scale" in xml[line+1]:
- splitLine = xml[line+1].split()
- 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) + "\""
- xml[line+1] = "\n\t\t\t" + splitLine[0] + " " + splitLine[1] + " " + splitLine[2] + " " + splitLine[3] + "\n"
- else:
- xml[line] += "\n\t\t\t" + splitLine[0] + " " + splitLine[1] + " " + splitLine[2] + " " + splitLine[3] + "\n"
- modCounter += 1
- outputFile.write(xml[line])
- #Done
- outputFile.close()
- print("\n" + str(modCounter) + " line(s) modified out of " + str(len(xml)) + " line(s) in total.")
- print("Look for a file named \"output.xml\" in your directory.\n")
- anotherChoiceLoop = True
- while anotherChoiceLoop == True:
- anotherChoice = input("Modify another XML file? (y/n): ")
- if anotherChoice == "y":
- anotherChoiceLoop = False
- print("Warning: File will still output to \"output.xml\", so rename the old output file if you don't want it to be overwritten.\n")
- elif anotherChoice == "n":
- anotherChoiceLoop = False
- anotherLoop = False
- else:
- print("\tInvalid input.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement