Skip to content

Instantly share code, notes, and snippets.

@chand1012
Created November 18, 2017 06:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chand1012/c7e9db3b3d36f760fd398c5d3ab14290 to your computer and use it in GitHub Desktop.
Save chand1012/c7e9db3b3d36f760fd398c5d3ab14290 to your computer and use it in GitHub Desktop.
A script to copy sound effects between Pico-8 Carts
# Created by Chandler Lofland aka chand1012
# Licensed as CC 3.0 US
# This script is to copy sfx between carts in pico8
# Uses basic file commands in python and sys for arguments
# For Python 3.0+
# arguments go like so: python sfxcpy.py <inputFile> <outputFile>
import sys
args = sys.argv
lookup = "__sfx__"
inputfile = str(args[1])
inputfile_array = []
outputfile = str(args[2])
outputfile_array = []
final_array = []
final_str = ""
start_line_input = None
end_line_input = None
start_line_output = None
end_line_output = None
print("Starting with {} as input and {} as output.".format(inputfile,outputfile))
print("Finding sfx in input file.")
with open(inputfile) as sfxFile:
for num, line in enumerate(sfxFile, 1):
if lookup in line:
start_line_input = num+1
end_line_input = start_line_input+63
print("Finding sfx in output file.")
with open(outputfile) as sfxFile:
for num, line in enumerate(sfxFile, 1):
if lookup in line:
start_line_output = num
end_line_output = start_line_output+62
print("Copying lines from input file.")
with open(inputfile) as sfxFile:
for num, line in enumerate(sfxFile, 1):
if num>=start_line_input and num<=end_line_input:
inputfile_array+=[str(line)]
print("Copying output file.")
with open(outputfile) as sfxFile:
for num, line in enumerate(sfxFile, 1):
outputfile_array+=[line]
print("Pasting lines to output list.")
count=0
for line in outputfile_array:
lineIndex = outputfile_array.index(line)
if lineIndex>=start_line_output and lineIndex<=end_line_output:
final_array+=[inputfile_array[count]]
count+=1
else:
final_array+=[line]
final_str = final_str.join(final_array)
print("Writing to output file.")
with open(outputfile, 'w') as sfxFile:
sfxFile.write(final_str)
print("Done. Copied SFX from {} to {}".format(inputfile, outputfile))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment