feat: upgrade combat and item icons

This commit is contained in:
2026-07-17 21:25:57 +09:00
parent e92535165d
commit eb41c05f60
19 changed files with 437 additions and 42 deletions

View File

@@ -9,39 +9,183 @@ from PIL import Image, ImageDraw, ImageEnhance, ImageFilter
ROOT = Path(__file__).resolve().parents[1]
OUT = ROOT / "src" / "assets" / "images" / "ui" / "battle-ui-icons.png"
SEED_ATLAS = ROOT / "docs" / "battle-ui-icons-hq-batch1-atlas.png"
MICRO_OUT = ROOT / "src" / "assets" / "images" / "ui" / "battle-ui-icons-micro.png"
PROOF_OUT = ROOT / "docs" / "battle-ui-icons-v2-action-item-contact.png"
SEED_ATLAS = ROOT / "docs" / "battle-ui-icons-hq-gapfix-v1-atlas.png"
TERRAIN_SOURCE = ROOT / "src" / "assets" / "images" / "battle" / "first-battle-map.webp"
SOURCE_DIR = ROOT / "src" / "assets" / "images" / "ui" / "icon-sources" / "battle-ui-v2"
BASE_FRAME = 48
FRAME = 128
MICRO_FRAME = 32
SCALE = 4
COLS = 5
ROWS = 6
SOURCE_FRAMES = {
4: ("attack", "attack-v2.png"),
16: ("hit", "hit-v2.png"),
17: ("critical", "critical-v2.png"),
19: ("counter", "counter-v2.png"),
24: ("fire", "fire-v2.png"),
27: ("bean", "bean-v2.png"),
28: ("salve", "salve-v2.png"),
29: ("wine", "wine-v2.png"),
}
REPLACEMENT_FRAMES: dict[int, tuple[str, Callable[[Image.Image], Image.Image]]] = {
4: ("attack", lambda atlas: compose_attack_icon(atlas)),
10: ("axe", lambda atlas: compose_axe_icon(atlas)),
18: ("terrain", lambda atlas: compose_terrain_icon()),
}
def main() -> None:
OUT.parent.mkdir(parents=True, exist_ok=True)
PROOF_OUT.parent.mkdir(parents=True, exist_ok=True)
seed_path = SEED_ATLAS if SEED_ATLAS.exists() else OUT
if not seed_path.exists():
raise FileNotFoundError(f"missing seed atlas: {seed_path}")
atlas = Image.open(seed_path).convert("RGBA")
seed_atlas = Image.open(seed_path).convert("RGBA")
expected_size = (COLS * FRAME, ROWS * FRAME)
if atlas.size != expected_size:
raise ValueError(f"seed atlas must be {expected_size}, got {atlas.size}: {seed_path}")
if seed_atlas.size != expected_size:
raise ValueError(f"seed atlas must be {expected_size}, got {seed_atlas.size}: {seed_path}")
atlas = seed_atlas.copy()
for index, (name, filename) in SOURCE_FRAMES.items():
tile = source_icon(SOURCE_DIR / filename)
replace_frame(atlas, index, tile)
print(f"Applied frame {index:02d} {name} from {filename}")
for index, (_name, build_icon) in REPLACEMENT_FRAMES.items():
tile = build_icon(atlas)
frame_box = ((index % COLS) * FRAME, (index // COLS) * FRAME)
atlas.paste(Image.new("RGBA", (FRAME, FRAME), (0, 0, 0, 0)), frame_box)
atlas.alpha_composite(tile, frame_box)
replace_frame(atlas, index, tile)
validate_source_frames(atlas)
atlas.save(OUT, optimize=True)
micro_atlas = build_micro_atlas(atlas)
validate_micro_frames(micro_atlas)
micro_atlas.save(MICRO_OUT, optimize=True)
write_contact_sheet(seed_atlas, atlas, micro_atlas)
print(f"Wrote {OUT}")
print(f"Wrote {MICRO_OUT}")
print(f"Wrote {PROOF_OUT}")
def replace_frame(atlas: Image.Image, index: int, tile: Image.Image) -> None:
frame_box = ((index % COLS) * FRAME, (index // COLS) * FRAME)
atlas.paste(Image.new("RGBA", (FRAME, FRAME), (0, 0, 0, 0)), frame_box)
atlas.alpha_composite(tile.convert("RGBA"), frame_box)
def source_icon(path: Path) -> Image.Image:
if not path.exists():
raise FileNotFoundError(f"missing V2 icon source: {path}")
image = Image.open(path).convert("RGBA")
alpha = image.getchannel("A")
corner_alpha = [
alpha.getpixel((0, 0)),
alpha.getpixel((image.width - 1, 0)),
alpha.getpixel((0, image.height - 1)),
alpha.getpixel((image.width - 1, image.height - 1)),
]
if max(corner_alpha) > 8:
raise ValueError(f"V2 icon source must have transparent corners: {path}")
bounds = alpha.getbbox()
if bounds is None:
raise ValueError(f"V2 icon source is fully transparent: {path}")
cropped = image.crop(bounds)
content_size = 104
scale = min(content_size / cropped.width, content_size / cropped.height)
width = max(1, round(cropped.width * scale))
height = max(1, round(cropped.height * scale))
resized = cropped.resize((width, height), Image.Resampling.LANCZOS)
resized = resized.filter(ImageFilter.UnsharpMask(radius=0.7, percent=85, threshold=2))
tile = Image.new("RGBA", (FRAME, FRAME), (0, 0, 0, 0))
tile.alpha_composite(resized, ((FRAME - width) // 2, (FRAME - height) // 2))
return tile
def build_micro_atlas(atlas: Image.Image) -> Image.Image:
micro = Image.new("RGBA", (COLS * MICRO_FRAME, ROWS * MICRO_FRAME), (0, 0, 0, 0))
for index in range(COLS * ROWS):
micro_content_size = MICRO_FRAME - 2
frame = atlas_frame(atlas, index).resize((micro_content_size, micro_content_size), Image.Resampling.LANCZOS)
alpha = frame.getchannel("A")
frame = frame.filter(ImageFilter.UnsharpMask(radius=0.45, percent=120, threshold=1))
frame.putalpha(alpha)
micro.alpha_composite(frame, ((index % COLS) * MICRO_FRAME + 1, (index // COLS) * MICRO_FRAME + 1))
return micro
def validate_source_frames(atlas: Image.Image) -> None:
for index, (name, _filename) in SOURCE_FRAMES.items():
bounds = atlas_frame(atlas, index).getchannel("A").getbbox()
if bounds is None:
raise ValueError(f"V2 atlas frame {index:02d} {name} is fully transparent")
width = bounds[2] - bounds[0]
height = bounds[3] - bounds[1]
if min(width, height) < 48:
raise ValueError(f"V2 atlas frame {index:02d} {name} is too narrow for runtime readability: {bounds}")
if bounds[0] < 8 or bounds[1] < 8 or bounds[2] > FRAME - 8 or bounds[3] > FRAME - 8:
raise ValueError(f"V2 atlas frame {index:02d} {name} violates the 8px safe edge: {bounds}")
def validate_micro_frames(atlas: Image.Image) -> None:
for index, (name, _filename) in SOURCE_FRAMES.items():
bounds = micro_atlas_frame(atlas, index).getchannel("A").getbbox()
if bounds is None:
raise ValueError(f"micro atlas frame {index:02d} {name} is fully transparent")
if bounds[0] == 0 or bounds[1] == 0 or bounds[2] == MICRO_FRAME or bounds[3] == MICRO_FRAME:
raise ValueError(f"micro atlas frame {index:02d} {name} touches an outer edge: {bounds}")
def micro_atlas_frame(atlas: Image.Image, index: int) -> Image.Image:
x = (index % COLS) * MICRO_FRAME
y = (index // COLS) * MICRO_FRAME
return atlas.crop((x, y, x + MICRO_FRAME, y + MICRO_FRAME)).convert("RGBA")
def write_contact_sheet(seed_atlas: Image.Image, atlas: Image.Image, micro_atlas: Image.Image) -> None:
card_width = 500
card_height = 220
sheet = Image.new("RGB", (card_width * 4, 40 + card_height * 2), (8, 14, 20))
draw = ImageDraw.Draw(sheet)
draw.text((14, 13), "Battle UI V2 action/item icons - before, HQ, runtime sizes", fill=(232, 220, 183))
labels = list(SOURCE_FRAMES.items())
runtime_sizes = (14, 20, 30, 34, 52, 70)
for position, (index, (name, _filename)) in enumerate(labels):
column = position % 4
row = position // 4
left = column * card_width
top = 40 + row * card_height
draw.rounded_rectangle((left + 6, top + 6, left + card_width - 6, top + card_height - 6), radius=8, fill=(15, 25, 34), outline=(64, 83, 98), width=1)
draw.text((left + 16, top + 14), f"{index:02d} {name}", fill=(236, 221, 176))
before = atlas_frame(seed_atlas, index).resize((72, 72), Image.Resampling.LANCZOS)
after = atlas_frame(atlas, index).resize((72, 72), Image.Resampling.LANCZOS)
sheet.paste(before, (left + 16, top + 46), before)
sheet.paste(after, (left + 104, top + 46), after)
draw.text((left + 29, top + 124), "before", fill=(125, 145, 159))
draw.text((left + 121, top + 124), "HQ", fill=(125, 145, 159))
cursor_x = left + 194
micro_frame = micro_atlas_frame(micro_atlas, index)
hq_frame = atlas_frame(atlas, index)
for size in runtime_sizes:
source = micro_frame if size <= MICRO_FRAME else hq_frame
sample = source.resize((size, size), Image.Resampling.LANCZOS)
sample_y = top + 78 - size // 2
sheet.paste(sample, (cursor_x, sample_y), sample)
draw.text((cursor_x, top + 124), str(size), fill=(125, 145, 159))
cursor_x += max(size, 28) + 8
bounds = atlas_frame(atlas, index).getchannel("A").getbbox()
occupancy = 0 if bounds is None else round(100 * max(bounds[2] - bounds[0], bounds[3] - bounds[1]) / FRAME)
draw.text((left + 16, top + 164), f"frame {FRAME}px / micro {MICRO_FRAME}px / max span {occupancy}%", fill=(143, 164, 176))
sheet.save(PROOF_OUT, optimize=True)
def make_icon(draw_icon: Callable[[ImageDraw.ImageDraw], None]) -> Image.Image: