/
pico-build
executable file
·52 lines (46 loc) · 1.78 KB
/
pico-build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python2.7
import glob, sys, os, platform
output = os.path.basename(os.getcwd()) + '.p8' # name the final file whatever the parent folder is
with open(output, 'w') as f:
# nab the head of the _assets.p8 file
with open('src/_assets.p8') as r:
for line in r:
line = line.rstrip()
if line != '':
f.write(line + '\n')
else:
break
# add in all files in directories
for root, dirs, files in os.walk('src'):
dirs.sort()
for dirname in dirs:
filenames = sorted(glob.glob('src/' + dirname + '/*.p8')) # get the .p8 files in the src directory
for filename in filenames:
with open(filename, 'r') as r:
f.write('\n' + r.read())
# add in all files (except _assets.p8) from the src directory
filenames = sorted(glob.glob('src/*.p8')) # get the .p8 files in the src directory
for filename in filenames:
if filename != 'src/_assets.p8':
with open(filename, 'r') as r:
f.write('\n' + r.read())
# get the graphics and sound effects from the second half of _assets.p8
with open('src/_assets.p8', 'r') as r:
head = True;
for line in r:
line = line.rstrip()
if head:
if line == '':
head = False
f.write('\n')
else:
f.write(line + '\n')
if platform.system() == 'Darwin':
command = "/Applications/PICO-8.app/Contents/MacOS/pico8"
else:
command = "pico8"
if len(sys.argv) > 1:
if sys.argv[1]=='run':
os.system(command + " -run " + os.getcwd() + "/" + output)
elif sys.argv[1]=='edit':
os.system(command + " -run " + os.getcwd() + "/src/_assets.p8")