Files
pbz-progress-roadmap/render_png.py
T

141 lines
4.4 KiB
Python

"""跨区任务线视图:每条跨区任务一行,用 ①②③④⑤ 小方块显示断在第几步。
这张图回答「同一时间有几条线在跑、各自到哪了」,不按地图分组。
"""
from __future__ import annotations
import sys
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont
ROOT = Path(__file__).resolve().parent
sys.path.insert(0, str(ROOT))
from roadmap import Save, build, summary, MAIN_SLOT # noqa: E402
from fonts import font # noqa: E402
BG = (18, 16, 14)
FG = (232, 226, 216)
DIM = (139, 132, 121)
GREEN = (46, 194, 126)
AMBER = (245, 166, 35)
GREY = (100, 96, 90)
BLUE = (74, 158, 255)
RED = (229, 72, 77)
BOX_BG = (30, 26, 21)
COL = {"done": GREEN, "active": AMBER, "todo": GREY, "locked": RED,
"item": BLUE}
W = 1180
PAD = 40
ROW = 62
STEP = 26
def main():
save = Save(MAIN_SLOT)
rows = build(save)
s = summary(save, rows)
# 按跨区任务(who)分组,保留时间线顺序
order, groups = [], {}
for r in rows:
if r["type"] != "node" or not r.get("who"):
continue
w = r["who"]
if w not in groups:
order.append(w)
groups[w] = []
groups[w].append(r)
# 单节点的不算「跨区线」,否则会显示成 1/1 全部完成,误导
order = [w for w in order if len(groups[w]) >= 2]
f_title = font(28)
f_sub = font(14)
f_who = font(16)
f_tiny = font(10)
f_num = font(11)
H = PAD * 2 + 150 + ROW * len(order) + 40
img = Image.new("RGB", (W, H), BG)
d = ImageDraw.Draw(img)
d.text((PAD, PAD), "影之刃零 · 跨区任务线", font=f_title, fill=FG)
d.text((PAD, PAD + 38),
f"{s['hours']}h · 第 {s['cycle']+1} 轮 · 剩余 {s['days_left']} 天 · "
f"成就 {s['ach']}/66 · 共 {len(order)} 条跨区任务",
font=f_sub, fill=DIM)
lx, ly = PAD, PAD + 72
for label, col in (("已完成", GREEN), ("进行中", AMBER), ("未到达", GREY), ("已错过", RED)):
d.rectangle([lx, ly + 3, lx + 10, ly + 13], fill=col)
d.text((lx + 15, ly), label, font=f_tiny, fill=DIM)
lx += 15 + d.textlength(label, font=f_tiny) + 20
y = PAD + 104
d.line([PAD, y - 8, W - PAD, y - 8], fill=(44, 40, 35), width=1)
for who in order:
items = groups[who]
done = sum(1 for i in items if i["code"] == "done")
active = sum(1 for i in items if i["code"] == "active")
# 任务名 + 进度
d.text((PAD, y + 6), who, font=f_who, fill=FG)
nw = d.textlength(who, font=f_who)
d.text((PAD + nw + 10, y + 10), f"{done}/{len(items)}",
font=f_tiny, fill=DIM)
if active:
d.text((PAD + nw + 10 + 34, y + 10), "进行中", font=f_tiny, fill=AMBER)
# 步骤方块
bx = PAD + 210
for i, it in enumerate(items):
c = COL[it["code"]]
x0 = bx + i * STEP
d.rounded_rectangle([x0, y + 2, x0 + 19, y + 21], radius=3,
fill=c if it["code"] != "todo" else BOX_BG,
outline=c if it["code"] == "todo" else None,
width=1)
# 步骤号
d.text((x0 + 6, y + 5), str(i + 1), font=f_num,
fill=(20, 18, 15) if it["code"] in ("done", "active") else GREY)
# 断点提示:第一个未完成为止的步骤名
pend = next((i for i in items if i["code"] in ("active", "todo")), None)
if pend:
idx = items.index(pend) + 1
nm = pend["name"].split(" ", 1)[-1] if " " in pend["name"] else pend["name"]
nm = nm.replace(who + " ", "")
txt = f"第 {idx} 步:{nm}"
else:
txt = "全部完成"
d.text((PAD + 210, y + 30), txt, font=f_tiny,
fill=(200, 160, 88) if pend else (95, 139, 115))
# 涉及地图
maps = []
for it in items:
m = it.get("map", "")
if m and m not in maps:
maps.append(m)
d.text((PAD + 210 + d.textlength(txt, font=f_tiny) + 16, y + 30),
" / ".join(maps), font=f_tiny, fill=(112, 105, 94))
y += ROW
d.text((PAD, H - PAD),
f"存档 {s['date']} · 方块编号 = 推进步骤 · 灰色空心 = 未到达",
font=f_tiny, fill=(84, 78, 70))
out = ROOT / "roadmap.png"
img.save(out)
print("saved", out, img.size)
if __name__ == "__main__":
main()