153 lines
3.0 KiB
Python
Executable File
153 lines
3.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import assetmgr
|
|
import json
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
def main():
|
|
fd = open(sys.argv[1], 'r')
|
|
data = fd.read()
|
|
fd.close()
|
|
|
|
basename = os.path.basename(sys.argv[1]).replace('.json', '')
|
|
shortname = get_shortname(basename)
|
|
|
|
rows = json.loads(data)
|
|
|
|
if os.environ['ROMID'].startswith('ntsc') and basename.endswith('E'):
|
|
make_header(rows, shortname)
|
|
elif os.environ['ROMID'].startswith('pal') and basename.endswith('P'):
|
|
make_header(rows, shortname)
|
|
elif os.environ['ROMID'].startswith('jpn') and basename.endswith('J'):
|
|
make_header(rows, shortname)
|
|
|
|
make_object(rows, basename)
|
|
|
|
def get_shortname(basename):
|
|
return re.match(r'^[a-z0-9]+', basename)[0]
|
|
|
|
def make_header(rows, shortname):
|
|
typename = 'l_%s' % shortname
|
|
enums = [row['id'] for row in rows]
|
|
filename = 'lang/%s.h' % shortname
|
|
terminator = 'L_%s_END' % shortname.upper()
|
|
start = banks.index(shortname) * 512
|
|
assetmgr.write_enums(typename, enums, filename, terminator, start=start)
|
|
|
|
def make_object(rows, basename):
|
|
binary = make_binary(rows)
|
|
zipped = assetmgr.zip(binary)
|
|
|
|
# Write the zipped file, purely so `make test` can verify it
|
|
if '_str_' in basename:
|
|
tmpfilename = basename + 'Z'
|
|
else:
|
|
tmpfilename = basename
|
|
|
|
assetmgr.writefile('build/%s/assets/files/L%s' % (os.environ['ROMID'], tmpfilename), zipped)
|
|
|
|
filename = 'files/L%s.o' % basename
|
|
assetmgr.write_object(zipped, filename)
|
|
|
|
def make_binary(rows):
|
|
if len(rows) == 0:
|
|
return (0).to_bytes(16, 'big')
|
|
|
|
output = bytes()
|
|
pos = len(rows) * 4
|
|
|
|
for index, row in enumerate(rows):
|
|
if row['text'] is None:
|
|
output += (0).to_bytes(4, 'big')
|
|
else:
|
|
output += pos.to_bytes(4, 'big')
|
|
pos += assetmgr.align4(len(row['text']) + 1)
|
|
|
|
for index, row in enumerate(rows):
|
|
if row['text'] is not None:
|
|
output += row['text'].encode('latin_1')
|
|
amount = 4 - (len(row['text']) % 4)
|
|
output += (0).to_bytes(amount, 'big')
|
|
|
|
if len(output) % 16:
|
|
amount = 16 - (len(output) % 16)
|
|
output += (0).to_bytes(amount, 'big')
|
|
|
|
return output
|
|
|
|
banks = [
|
|
'',
|
|
'ame',
|
|
'arch',
|
|
'ark',
|
|
'ash',
|
|
'azt',
|
|
'cat',
|
|
'cave',
|
|
'arec',
|
|
'crad',
|
|
'cryp',
|
|
'dam',
|
|
'depo',
|
|
'dest',
|
|
'dish',
|
|
'ear',
|
|
'eld',
|
|
'imp',
|
|
'jun',
|
|
'lee',
|
|
'len',
|
|
'lip',
|
|
'lue',
|
|
'oat',
|
|
'pam',
|
|
'pete',
|
|
'ref',
|
|
'rit',
|
|
'run',
|
|
'sevb',
|
|
'sev',
|
|
'sevx',
|
|
'sevxb',
|
|
'sho',
|
|
'silo',
|
|
'stat',
|
|
'tra',
|
|
'wax',
|
|
'gun',
|
|
'title',
|
|
'mpmenu',
|
|
'propobj',
|
|
'mpweapons',
|
|
'options',
|
|
'misc',
|
|
'uff',
|
|
'old',
|
|
'ate',
|
|
'lam',
|
|
'mp1',
|
|
'mp2',
|
|
'mp3',
|
|
'mp4',
|
|
'mp5',
|
|
'mp6',
|
|
'mp7',
|
|
'mp8',
|
|
'mp9',
|
|
'mp10',
|
|
'mp11',
|
|
'mp12',
|
|
'mp13',
|
|
'mp14',
|
|
'mp15',
|
|
'mp16',
|
|
'mp17',
|
|
'mp18',
|
|
'mp19',
|
|
'mp20',
|
|
]
|
|
|
|
main()
|