"""Prepara os recursos do The Burdened Raid para a edicao web (dentro do projeto extraido): - troca a fonte bitmap core/assets/font.fnt/.png (exportada da Alagard, que nao tem licenca registrada) por uma gerada da Jacquard 12 (SIL OFL 1.1), mesmo nome de arquivo e mesmos caracteres (BMFont em texto + pagina PNG); - apaga o badlogic.jpg (imagem padrao do libGDX que o jogo nao usa) e os arquivos do SoundManager2 e da pagina antiga em html/webapp (o libGDX atual nao usa o SoundManager2). Uso: fix-assets.py """ import os, shutil, sys from PIL import Image, ImageDraw, ImageFont root, ttf = sys.argv[1:3] assets = os.path.join(root, "core", "assets") SIZE = 36 font = ImageFont.truetype(ttf, SIZE) ascent, descent = font.getmetrics() glyphs = [] for c in range(32, 127): ch = chr(c) l, t, r, b = font.getbbox(ch, anchor="la") w, h = max(r - l, 0), max(b - t, 0) img = Image.new("L", (max(w, 1), max(h, 1)), 0) if w and h: ImageDraw.Draw(img).text((-l, -t), ch, font=font, fill=255, anchor="la") glyphs.append((c, img, w, h, l, t, round(font.getlength(ch)))) PAD, W, H = 2, 512, 512 page = Image.new("RGBA", (W, H), (255, 255, 255, 0)) x = y = PAD row_h = 0 lines = ["char id=10 x=0 y=0 width=0 height=0 xoffset=0 yoffset=0 xadvance=0 page=0 chnl=0"] for c, img, w, h, l, t, adv in glyphs: if x + w + PAD > W: x, y, row_h = PAD, y + row_h + PAD, 0 if w and h: rgba = Image.new("RGBA", img.size, (255, 255, 255, 0)) rgba.putalpha(img) page.paste(rgba, (x, y)) lines.append("char id=%d x=%d y=%d width=%d height=%d xoffset=%d yoffset=%d xadvance=%d page=0 chnl=0" % (c, x, y, w, h, l, t, adv)) x += w + PAD row_h = max(row_h, h) assert y + row_h + PAD <= H page.save(os.path.join(assets, "font.png"), optimize=False) with open(os.path.join(assets, "font.fnt"), "w", newline="\n") as f: f.write('info face="font" size=%d bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=2,2\n' % SIZE) f.write("common lineHeight=%d base=%d scaleW=%d scaleH=%d pages=1 packed=0\n" % (ascent + descent, ascent, W, H)) f.write('page id=0 file="font.png"\n') f.write("chars count=%d\n" % len(lines)) f.write("\n".join(lines) + "\n") os.remove(os.path.join(assets, "badlogic.jpg")) web = os.path.join(root, "html", "webapp") shutil.rmtree(web) os.makedirs(os.path.join(web, "WEB-INF")) open(os.path.join(web, "index.html"), "w").write("\n") # o index.html final sai do java-web/index-gwt.html.in print("ok")