# -*- coding: utf-8 -*- """Story IR -> 单文件可视化 HTML 面板生成器。 用法: python ir_to_html.py samples/yuye_koumen.ir.json python ir_to_html.py samples/yuye_koumen.ir.json -o out.html 产出一个自包含、离线可打开的 .html:分层分支树 + 点节点看台词/角色/奖励 + 奖励总览 + 导出 IR。所有渲染逻辑在前端,IR 以 JSON 内联进页面。 """ import argparse import json import os import sys TEMPLATE = r""" __TITLE__ · Story 面板

节点详情
点击左侧任意节点查看台词 / 角色 / 奖励
奖励总览
""" def main(): ap = argparse.ArgumentParser() ap.add_argument("ir", help="Story IR JSON 文件路径") ap.add_argument("-o", "--out", help="输出 HTML 路径(默认与输入同名 .html)") args = ap.parse_args() with open(args.ir, encoding="utf-8") as f: ir = json.load(f) base = args.ir for ext in (".json", ".ir"): if base.endswith(ext): base = base[: -len(ext)] out = args.out or base + ".html" html = (TEMPLATE .replace("__IR_JSON__", json.dumps(ir, ensure_ascii=False)) .replace("__TITLE__", ir.get("title", "Story"))) with open(out, "w", encoding="utf-8") as f: f.write(html) print("OK ->", out) if __name__ == "__main__": main()