112 lines
3.4 KiB
Python
112 lines
3.4 KiB
Python
import convert
|
|
import argparse
|
|
|
|
"""
|
|
Command line utility for converting SR* files bidirectionally
|
|
"""
|
|
|
|
|
|
def getOutputPath(args) -> list:
|
|
"""
|
|
Takes our argParser args, infers and returns the proper output path and what action to take (what function to use)
|
|
"""
|
|
outputPath = ""
|
|
action = ""
|
|
if "outputPath" in args:
|
|
outputPath = args.outputPath
|
|
else:
|
|
if args.animation:
|
|
if ".srb" in args.inputPath:
|
|
action = "toAnimation"
|
|
outputPath = ".".join(args.inputPath.split(".")[:-1])
|
|
else:
|
|
action = "toSRB"
|
|
outputPath = inputPath + ".srb"
|
|
else:
|
|
if ".sr" in args.inputPath:
|
|
action = "toStill"
|
|
if "outputFormat" in args:
|
|
outputPath = ".".join(inputPath.split(".")[:-1]) + args.outputFormat
|
|
else:
|
|
outputPath = ".".join(inputPath.split(".")[:-1]) + ".png"
|
|
else:
|
|
action = "toSR"
|
|
if "." in inputPath:
|
|
outputPath = ".".join(inputPath.split(".")[:-1]) + ".sr"
|
|
else:
|
|
outputPath = inputPath + ".sr"
|
|
return [outputPath, action]
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("inputPath", help="Path to load input file from")
|
|
parser.add_argument(
|
|
"-o",
|
|
"--outputPath",
|
|
help="Output path, if this is set improperly for the output we will infer the proper path",
|
|
default=argparse.SUPPRESS,
|
|
)
|
|
parser.add_argument(
|
|
"-a", "--animation", help="Whether this is an animation", default=False
|
|
)
|
|
parser.add_argument(
|
|
"-f", "--outputFormat", help="Format to convert to", default=argparse.SUPPRESS
|
|
)
|
|
parser.add_argument(
|
|
"-i", "--inputFormat", help="Format to convert from", default=argparse.SUPPRESS
|
|
)
|
|
parser.add_argument(
|
|
"-t",
|
|
"--transparent",
|
|
help="Whether output should be transparent",
|
|
default=False,
|
|
)
|
|
parser.add_argument(
|
|
"-p",
|
|
"--palettes",
|
|
help="Comma seperated list of .hex palettes to create swaps from",
|
|
default=argparse.SUPPRESS,
|
|
)
|
|
parser.add_argument(
|
|
"-s",
|
|
"--scalingFactor",
|
|
help="Scale up this many times when rendering",
|
|
default=1,
|
|
)
|
|
parser.add_argument(
|
|
"-m",
|
|
"--metadataFile",
|
|
help="JSON (.json) or Msgpack (.bin) encoded metadata file",
|
|
default=argparse.SUPPRESS,
|
|
)
|
|
parser.add_argument(
|
|
"-e",
|
|
"--encryptionKey",
|
|
help="Encryption key for image",
|
|
default=argparse.SUPPRESS,
|
|
)
|
|
parser.add_argument(
|
|
"-x", "--excludeAll", help="Only encrypt metadatas secret field", default=False
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
inputPath = args.inputPath
|
|
|
|
outputPath, action = getOutputPath(args)
|
|
|
|
if action == "toSR":
|
|
if "hexPalette" in args:
|
|
convert.toSR(
|
|
inputPath, outputPath, scale=args.scale, palette=args.hexPalette
|
|
)
|
|
else:
|
|
convert.toSR(inputPath, outputPath, scale=args.scale)
|
|
elif action == "toSRB":
|
|
convert.toSRB(inputPath, outputPath, scale=args.scale)
|
|
elif action == "toStill":
|
|
if "hexPalette" in args:
|
|
convert.toStill(inputPath, outputPath, palette=args.hexPalette)
|
|
else:
|
|
convert.toStill(inputPath, outputPath)
|