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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#!/usr/bin/python
import json
import os
import cgi
import sys
def getdata():
form = cgi.FieldStorage()
request = form.getvalue("collections")
collections = request.split(",")
with open("map.json", "r") as f:
data = json.load(f)
filecount = 0
udo_data = str()
icollectionid = 0
opcode_str1 = "opcode sounddb_getcollectionid, i, So\n\tScollection, i_ xin\n"
opcode_str2 = "opcode sounddb_getcollection, i[]i, S\n\tScollection xin\n"
first = True
for name, data in data.iteritems():
if name not in collections:
continue
safe_name = name.replace(".", "_")
if not first:
opcode_str1 += "\telseif "
opcode_str2 += "\telseif "
else:
first = False
opcode_str1 += "\tif "
opcode_str2 += "\tif "
opcode_str1 += "(strcmp(Scollection, \"{}\") == 0) then\n\t\ticollectionid = {}\n".format(name, icollectionid)
opcode_str2 += "(strcmp(Scollection, \"{0}\") == 0) then\n\t\ticollection[] = gisdbFn_{0}\n\t\ticollectionid = {1}\n".format(
safe_name, icollectionid
)
if data["type"] == "melsys":
melsys = True
note_data = [None for x in range(0, 128)]
note_str = "gisdbNotes_{}[] init 128, 2".format(safe_name)
else:
note_str = None
melsys = False
udo_data += "gisdbFn_{}[] fillarray ".format(safe_name)
index = 0
for item in data["sounds"]:
exists = False
if melsys:
if note_data[item["note"]]:
exists = True
else:
note_data[item["note"]] = {"fn": "gisdbFn_{}[{}]".format(safe_name, index), "ratio": 1}
if not exists:
udo_data += "ftgen(0, 0, 0, 1, \"{}\", 0, 0, 0),".format(item["path"])
index += 1
udo_data = udo_data[:-1] + "\n\n"
if melsys:
for note in note_data:
pass
icollectionid += 1
opcode_str1 += "\tendif\n\txout icollectionid\nendop\n"
opcode_str2 += "\tendif\n\txout icollection, icollectionid\nendop\n"
opcode_str = opcode_str1 + "\n" + opcode_str2 + "\nopcode sounddb_getcollection, i[], S\n\tScollection xin\n\ticollection[], i_ sounddb_getcollection Scollection\n\txout icollection\nendop\n"
print udo_data + "\n" + opcode_str
if __name__ == "__main__":
sys.stdout.write("Content-Type: text/plain\n\n")
getdata()
|