-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_manifests.py
52 lines (45 loc) · 1.37 KB
/
generate_manifests.py
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
import os, json
from pprint import pprint
all_textures = {}
for subdir, dirs, files in os.walk('data/textures'):
for file in files:
all_textures[os.path.join(subdir, file)] = True
texture_to_shader = {}
for subdir, dirs, files in os.walk('data/scripts'):
for file in files:
f = open(os.path.join(subdir, file), 'r', encoding="utf8", errors='ignore')
current_texture = None
braces = 0
shader_source = []
for line in f:
line = line.strip()
if line.startswith('//') or len(line) == 0:
continue
if current_texture:
if line == '{':
braces += 1
if braces == 2:
shader_source.append([])
elif line == '}':
braces -= 1
else:
if braces == 1:
shader_source.append(line.split(' '))
elif braces == 2:
shader_source[-1].append(line.split(' '))
else:
assert False
if braces == 0:
texture_to_shader[current_texture] = shader_source
current_texture = None
if line.startswith('textures'):
current_texture = line
braces = 0
shader_source = []
file = open('./data/textures_manifest.json', 'w')
file.truncate(0)
file.write(json.dumps({
'textures': all_textures,
'shaders': texture_to_shader
}))
file.close()