first commit
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
|
||||
ROOT = Path(r"C:\milimoe\osm-game")
|
||||
ASSET_ROOT = ROOT / "assets/images/2d-game-characters/02-xinyin"
|
||||
SOURCE_DIR = ASSET_ROOT / "source/down"
|
||||
MASTER = SOURCE_DIR / "xinyin-down-neutral-master-v1.png"
|
||||
CORE = SOURCE_DIR / "xinyin-down-core-parts-sheet-v1.png"
|
||||
SOFT = SOURCE_DIR / "xinyin-down-soft-parts-sheet-v2.png"
|
||||
CORE_DIAGNOSTIC = ASSET_ROOT / "diagnostics/xinyin-down-core-parts-v1-components.png"
|
||||
CORE_COMPONENTS = ASSET_ROOT / "diagnostics/xinyin-down-core-parts-v1-components.json"
|
||||
SOFT_DIAGNOSTIC = ASSET_ROOT / "diagnostics/xinyin-down-soft-parts-v2-components.png"
|
||||
SOFT_COMPONENTS = ASSET_ROOT / "diagnostics/xinyin-down-soft-parts-v2-components.json"
|
||||
MANIFEST = SOURCE_DIR / "source-sheet-manifest-v1.json"
|
||||
OUTPUT = ASSET_ROOT / "previews/xinyin-down-parts-sheets-validation-v1.png"
|
||||
FONT = Path(r"C:\Windows\Fonts\msyh.ttc")
|
||||
|
||||
|
||||
def font(size: int) -> ImageFont.FreeTypeFont:
|
||||
return ImageFont.truetype(str(FONT), size)
|
||||
|
||||
|
||||
def contain(image: Image.Image, size: tuple[int, int], margin: int = 0) -> Image.Image:
|
||||
result = image.copy()
|
||||
result.thumbnail((size[0] - margin * 2, size[1] - margin * 2), Image.Resampling.LANCZOS)
|
||||
return result
|
||||
|
||||
|
||||
def paste_center(canvas: Image.Image, image: Image.Image, rect: tuple[int, int, int, int]) -> None:
|
||||
x0, y0, x1, y1 = rect
|
||||
canvas.alpha_composite(image, (x0 + (x1 - x0 - image.width) // 2, y0 + (y1 - y0 - image.height) // 2))
|
||||
|
||||
|
||||
def corners_transparent(image: Image.Image) -> bool:
|
||||
alpha = image.getchannel("A")
|
||||
width, height = image.size
|
||||
return all(alpha.getpixel(point) == 0 for point in ((0, 0), (width - 1, 0), (0, height - 1), (width - 1, height - 1)))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
master = Image.open(MASTER).convert("RGBA")
|
||||
core = Image.open(CORE).convert("RGBA")
|
||||
soft = Image.open(SOFT).convert("RGBA")
|
||||
core_diagnostic = Image.open(CORE_DIAGNOSTIC).convert("RGBA")
|
||||
soft_diagnostic = Image.open(SOFT_DIAGNOSTIC).convert("RGBA")
|
||||
core_scan = json.loads(CORE_COMPONENTS.read_text(encoding="utf-8-sig"))
|
||||
soft_scan = json.loads(SOFT_COMPONENTS.read_text(encoding="utf-8-sig"))
|
||||
|
||||
if core_scan["componentCount"] != 17:
|
||||
raise ValueError(f"Expected 17 core components, got {core_scan['componentCount']}")
|
||||
if soft_scan["componentCount"] != 24:
|
||||
raise ValueError(f"Expected 24 soft components, got {soft_scan['componentCount']}")
|
||||
|
||||
manifest = {
|
||||
"character": "02-xinyin",
|
||||
"direction": "down",
|
||||
"version": 1,
|
||||
"status": "source-sheets-alpha-validated",
|
||||
"directionReference": "xinyin-down-neutral-master-v1.png",
|
||||
"sheets": [
|
||||
{
|
||||
"id": "core",
|
||||
"file": CORE.name,
|
||||
"canvas": list(core.size),
|
||||
"componentCount": core_scan["componentCount"],
|
||||
"contents": [
|
||||
"head-face-base", "neck-connector", "upper-torso", "pelvis-hip-core",
|
||||
"shoulder-armor-a", "shoulder-armor-b", "upper-arm-a", "upper-arm-b",
|
||||
"forearm-a", "forearm-b", "fan-grip-hand-a", "relaxed-hand-b",
|
||||
"throw-open-hand-a", "thigh-a", "thigh-b", "lower-leg-boot-a", "lower-leg-boot-b",
|
||||
],
|
||||
},
|
||||
{
|
||||
"id": "soft-accessories",
|
||||
"file": SOFT.name,
|
||||
"canvas": list(soft.size),
|
||||
"componentCount": soft_scan["componentCount"],
|
||||
"contents": [
|
||||
"front-bangs-side-locks", "back-head-hair-cap", "ponytail-root", "ponytail-middle",
|
||||
"ponytail-tip", "silver-floral-hair-ornament", "outer-sleeve-cape-a", "outer-sleeve-cape-b",
|
||||
"skirt-coat-panel-01", "skirt-coat-panel-02", "skirt-coat-panel-03", "skirt-coat-panel-04",
|
||||
"skirt-coat-panel-05", "skirt-coat-panel-06", "skirt-coat-panel-07", "skirt-coat-panel-08",
|
||||
"waist-front-cloth", "waist-pouch", "red-tassel-cluster-a", "red-tassel-cluster-b",
|
||||
"weapon-fan-open", "weapon-blade-single", "weapon-double-feather", "skirt-coat-panel-alt-09",
|
||||
],
|
||||
},
|
||||
],
|
||||
"validation": {
|
||||
"alphaThreshold": 16,
|
||||
"minimumComponentArea": 80,
|
||||
"edgeCornersTransparent": corners_transparent(core) and corners_transparent(soft),
|
||||
"touchingComponents": False,
|
||||
"coreComponentCount": core_scan["componentCount"],
|
||||
"softComponentCount": soft_scan["componentCount"],
|
||||
"notes": [
|
||||
"Core v1 has exactly 17 disconnected alpha components and separates shoulder armor, upper arms, forearms, and hand variants.",
|
||||
"Soft v2 replaces the rejected crowded v1 layout with an invisible 6x4 production grid and exactly 24 disconnected alpha components.",
|
||||
"The alternate ninth coat panel is retained for action silhouettes; eight primary panels form the neutral skirt.",
|
||||
"Part names and pivots are provisional until the independent extraction and assembly pass.",
|
||||
],
|
||||
},
|
||||
}
|
||||
MANIFEST.write_text(json.dumps(manifest, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
|
||||
canvas = Image.new("RGBA", (2000, 1240), (24, 30, 42, 255))
|
||||
draw = ImageDraw.Draw(canvas)
|
||||
white = (242, 246, 252, 255)
|
||||
muted = (166, 181, 205, 255)
|
||||
blue = (98, 205, 255, 255)
|
||||
green = (123, 225, 170, 255)
|
||||
|
||||
draw.text((48, 30), "心音|DOWN 正面分解源板验证 v1", font=font(40), fill=white)
|
||||
draw.text((50, 82), "核心板 17 件 + 软性/附件板 v2 24 件 · Alpha 阈值 16 · 8 邻域连通检测", font=font(21), fill=muted)
|
||||
|
||||
panels = [
|
||||
((42, 126, 470, 1178), "A 正面母版"),
|
||||
((500, 126, 1958, 625), "B 核心身体/四肢板 · 17 件"),
|
||||
((500, 650, 1958, 1178), "C 头发/衣摆/附件板 v2 · 24 件"),
|
||||
]
|
||||
for rect, title in panels:
|
||||
draw.rounded_rectangle(rect, radius=16, fill=(34, 42, 57, 255), outline=(68, 84, 108, 255), width=2)
|
||||
draw.text((rect[0] + 22, rect[1] + 18), title, font=font(23), fill=white)
|
||||
|
||||
master_visible = master.crop(master.getchannel("A").getbbox())
|
||||
paste_center(canvas, contain(master_visible, (380, 940), 12), (66, 190, 446, 1130))
|
||||
paste_center(canvas, contain(core_diagnostic, (1400, 400), 8), (526, 190, 1932, 606))
|
||||
paste_center(canvas, contain(soft_diagnostic, (1400, 420), 8), (526, 716, 1932, 1150))
|
||||
|
||||
draw.text((72, 1128), "严格正面", font=font(20), fill=blue)
|
||||
draw.text((205, 1128), "左右装备关系冻结", font=font(20), fill=green)
|
||||
draw.text((1530, 590), "17 / 17 独立", font=font(19), fill=green)
|
||||
draw.text((1510, 1142), "24 / 24 独立", font=font(19), fill=green)
|
||||
|
||||
OUTPUT.parent.mkdir(parents=True, exist_ok=True)
|
||||
canvas.convert("RGB").save(OUTPUT, quality=95)
|
||||
print(MANIFEST)
|
||||
print(OUTPUT)
|
||||
print(json.dumps(manifest["validation"], ensure_ascii=False, indent=2))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user