wobblyhead hg > minor_monsters
comparison tools/preview.py @ 16:30bd10284fd8
added ./game to .hgignore
| author | ark |
|---|---|
| date | 2026-10-19 23:47 +0200 |
| parents | 3dd5b745fa08 |
| children | 3a831478eda4 |
comparison
equal
deleted
inserted
replaced
| 15:c1c7e4f54bf6 | 16:30bd10284fd8 |
|---|---|
| 79 for k, p in enumerate(panels): | 79 for k, p in enumerate(panels): |
| 80 sheet.paste(p, ((k % cols) * pw, (k // cols) * ph)) | 80 sheet.paste(p, ((k % cols) * pw, (k // cols) * ph)) |
| 81 return sheet | 81 return sheet |
| 82 | 82 |
| 83 | 83 |
| 84 def tower_sheet(assets, pivots): | 84 def tower_sheet(assets, pivots, footprint, scale): |
| 85 """ | 85 """ |
| 86 tower levels 1-5 per row: at full size on grey, so the white fill shows, | 86 tower levels 1-5 per row: at full size on grey, so the white fill shows, |
| 87 and at game scale next to each other. a cross marks the rotation point. | 87 and at game scale next to each other. a cross marks the rotation point, |
| 88 which is the tower position, and a circle the footprint around it. | |
| 89 footprint is the footprint radius in map pixels, scale the sprite scale. | |
| 88 """ | 90 """ |
| 89 rows = [] | 91 rows = [] |
| 90 for t in range(4): | 92 for t in range(4): |
| 91 names = [f"t{t}"] + [f"t{t}_{lv}" for lv in range(2, 6)] | 93 names = [f"t{t}"] + [f"t{t}_{lv}" for lv in range(2, 6)] |
| 92 rows.append([Image.open(assets / f"{n}.png") for n in names]) | 94 rows.append([Image.open(assets / f"{n}.png") for n in names]) |
| 93 pad = 16 | 95 pad = 16 |
| 94 cell_w = max(im.width for r in rows for im in r) + pad | 96 cell_w = max(im.width for r in rows for im in r) + pad |
| 95 cell_h = max(im.height for r in rows for im in r) + pad | 97 cell_h = max(im.height for r in rows for im in r) + pad |
| 96 small_w = cell_w // 4 + 4 | 98 small_w = round(cell_w * scale) + 4 |
| 99 full_r = footprint / scale | |
| 97 sheet = Image.new("RGBA", (5 * cell_w + 5 * small_w + pad, 4 * cell_h + 20), | 100 sheet = Image.new("RGBA", (5 * cell_w + 5 * small_w + pad, 4 * cell_h + 20), |
| 98 (170, 170, 170, 255)) | 101 (170, 170, 170, 255)) |
| 99 draw = ImageDraw.Draw(sheet) | 102 draw = ImageDraw.Draw(sheet) |
| 100 for lv in range(5): | 103 for lv in range(5): |
| 101 draw.text((lv * cell_w + pad, 4), f"level {lv + 1}", fill=(0, 0, 0)) | 104 draw.text((lv * cell_w + pad, 4), f"level {lv + 1}", fill=(0, 0, 0)) |
| 102 draw.text((5 * cell_w + pad, 4), "game scale 0.25", fill=(0, 0, 0)) | 105 draw.text((5 * cell_w + pad, 4), f"game scale {scale}", fill=(0, 0, 0)) |
| 103 for t, r in enumerate(rows): | 106 for t, r in enumerate(rows): |
| 104 y = 20 + t * cell_h | 107 y = 20 + t * cell_h |
| 105 for lv, im in enumerate(r): | 108 for lv, im in enumerate(r): |
| 106 x = lv * cell_w + pad // 2 | 109 x = lv * cell_w + pad // 2 |
| 107 sheet.alpha_composite(im, (x, y)) | 110 sheet.alpha_composite(im, (x, y)) |
| 108 name = f"t{t}" if lv == 0 else f"t{t}_{lv + 1}" | 111 name = f"t{t}" if lv == 0 else f"t{t}_{lv + 1}" |
| 109 px, py = pivots.get(name, (0.5, 0.5)) | 112 px, py = pivots.get(name, (0.5, 0.5)) |
| 110 cx, cy = x + round(im.width * px), y + round(im.height * py) | 113 cx, cy = x + round(im.width * px), y + round(im.height * py) |
| 111 draw.line((cx - 5, cy, cx + 5, cy), fill=(255, 0, 0)) | 114 draw.line((cx - 5, cy, cx + 5, cy), fill=(255, 0, 0)) |
| 112 draw.line((cx, cy - 5, cx, cy + 5), fill=(255, 0, 0)) | 115 draw.line((cx, cy - 5, cx, cy + 5), fill=(255, 0, 0)) |
| 113 small = im.resize((max(1, im.width // 4), max(1, im.height // 4)), Image.LANCZOS) | 116 draw.ellipse((cx - full_r, cy - full_r, cx + full_r, cy + full_r), |
| 114 sheet.alpha_composite(small, (5 * cell_w + pad + lv * small_w, y + cell_h // 3)) | 117 outline=(0, 0, 255), width=2) |
| 118 small = im.resize((max(1, round(im.width * scale)), max(1, round(im.height * scale))), | |
| 119 Image.LANCZOS) | |
| 120 sx, sy = 5 * cell_w + pad + lv * small_w, y + cell_h // 3 | |
| 121 sheet.alpha_composite(small, (sx, sy)) | |
| 122 scx, scy = sx + small.width * px, sy + small.height * py | |
| 123 draw.ellipse((scx - footprint, scy - footprint, scx + footprint, scy + footprint), | |
| 124 outline=(0, 0, 255)) | |
| 115 return sheet | 125 return sheet |
