| import sys | |
| TEMPLATE_FILE = "template.fnt" | |
| TEMPLATE_LINE = "char id={id} x={x} y={y} width={w} height={h} xoffset=0 yoffset=0 xadvance=0 page=0 chnl=0\n" | |
| def parse(file): | |
| print("Parsing", file) | |
| out_file = file + ".fnt" | |
| with open(TEMPLATE_FILE, 'r') as tf: | |
| template = tf.read() | |
| char_data = "" | |
| count = 0 | |
| with open(file+".atlas", 'r') as af: | |
| lines = af.readlines() | |
| for id, line in enumerate(lines): | |
| line = line.rstrip() | |
| if len(line) == 1: | |
| count+=1 | |
| print(id, line) | |
| cid = ord(line) | |
| xy = lines[id+2].strip().split(':')[1].split(',') | |
| xy[0] = int(xy[0]) | |
| xy[1] = int(xy[1]) | |
| wh = lines[id+3].strip().split(':')[1].split(',') | |
| wh[0] = int(wh[0]) | |
| wh[1] = int(wh[1]) | |
| print(xy) | |
| print(wh) | |
| char_data += TEMPLATE_LINE.format(id=cid, x=xy[0], y=xy[1], w=wh[0], h=wh[1]) | |
| template = template.format(name=file, file=file, count=count, char_data=char_data[:-1]) | |
| print(template) | |
| with open(out_file, 'w') as out: | |
| out.write(template) | |
| def main(files=None): | |
| if not files: | |
| print("Add some files as params!") | |
| return | |
| for file in files: | |
| parse(file) | |
| if __name__ == '__main__': | |
| files = sys.argv[1:] | |
| main(files) | |
| """ template.fnt | |
| info face="{name}" size=17 bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=1,1 | |
| common lineHeight=20 base=18 scaleW=256 scaleH=128 pages=1 packed=0 | |
| page id=0 file="{file}.png" | |
| chars count={count} | |
| {char_data} | |
| kernings count=-1 | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment