feat(v1.2): 阶段1 —— 立绘表五档 + 回退链 + 编辑界面(v2.0.56)
按 v1.2 需求,`front` 从单文件名扩成五档立绘表,立绘随情绪自动切换。 ## 数据层 `store.normalize_image`:兼容规则是需求原话的"旧格式视为仅有「平常」档"。 ★ 放在**读**的时候归一化(`list_agents` 出口),不是写的时候: 老数据已经在 agents.json 里了,写时归一化管不到它们;读时归一化一次 覆盖新旧两种,而且写入路径一行都不用改。 ★ 归一化不丢信息:字典里多出来的自定义档位原样保留。 ## 回退链 `agent_api.portrait_of`:`当前 preset 档 → 平常档 → 旧单一 front → 空串` (空串 = 界面用内置默认人物)。 ★ 由内核算好、经 `/api/state` 的 `portrait` 字段给界面 —— 回退链是**一条规则**, 而选择界面、对话界面、编辑预览三处都要用。 ★ 查 `os.path.isfile`:用户可能手动删过 agent-assets 里的文件, 指着不存在的路径会让界面显示空白,比回退到默认图糟得多。 ## 落盘与槽位 - `_save_assets`:front 单独处理,每档文件名带档位(`front-喜-happy.png`), 否则五档会互相覆盖;老格式落成「平常」档 - `_set_asset`:槽位名支持 `front:喜`(不带档位视为「平常」,兼容旧调用); 换图时把旧文件删掉,不然越攒越多 ## 界面 - `AgentImage.front` 从 String 改成 `Map<String, String>` + 新增 `portrait` - 所有显示处改用 `portrait`(编译器一次列出 5 个文件 11 处,逐个改的) - 编辑界面外观组拆两段:**角色立绘(五档,每档带"缺了退回哪张"的说明)** + 其他三件套 ## 验证 探针第 19 节 10 项,**真造文件**测(回退链里有一环是 os.path.isfile, 不落真文件测不到):老格式归一化、命中当前档、回退平常、 连平常都没有时用任意可用档、**档位文件被删时跳过它**、完全没图返回空串、 归一化保留自定义档位、自定义档位也能被选中。 装机实测五档编辑器。全部探针 + audit-ui-tree 全绿。 ## 阶段 1 剩余(很小的尾巴) 立绘切换的 crossfade(0.3s)放到阶段 5 的 §4.4 一起做 —— 那时要同时处理"群聊背景跟随发言者",两处共用同一套缓动参数。
This commit is contained in:
@@ -556,6 +556,53 @@ def main():
|
||||
and agentdb.emotion_state(did)["text"] == "气消了一半",
|
||||
str(agentdb.emotion_state(did)))
|
||||
|
||||
# ---------------------------------------------------------------- 19
|
||||
section("19. v1.2 立绘表:五档 + 回退链(需求 2.5 / 2.6)")
|
||||
#
|
||||
# 真造几个文件出来测 —— 回退链里有一环是 `os.path.isfile`(用户可能
|
||||
# 手动删过 agent-assets 里的图),不落真文件就测不到那一环。
|
||||
pic_dir = tempfile.mkdtemp(prefix="doubao-pics-")
|
||||
|
||||
def pic(name):
|
||||
p = os.path.join(pic_dir, name)
|
||||
with open(p, "wb") as fh:
|
||||
fh.write(b"\x89PNG\r\n\x1a\n" + name.encode())
|
||||
return p
|
||||
|
||||
normal, happy, sad, gone = pic("normal.png"), pic("happy.png"), pic("sad.png"), pic("deleted.png")
|
||||
os.remove(gone) # 造一个"文件被删了"的档位
|
||||
|
||||
from agent_api import portrait_of
|
||||
|
||||
# ① 旧格式(单文件名)经 normalize 之后变成只有「平常」档
|
||||
old = store.normalize_image({"front": normal})
|
||||
check("旧格式归一化成「平常」档", old["front"] == {"平常": normal}, str(old["front"]))
|
||||
check("旧格式的立绘任何 preset 都能用(回退到平常)",
|
||||
portrait_of(old, "怒") == normal, portrait_of(old, "怒"))
|
||||
|
||||
# ② 五档表:命中当前档
|
||||
five = store.normalize_image({"front": {"喜": happy, "哀": sad, "平常": normal}})
|
||||
check("命中当前档", portrait_of(five, "喜") == happy)
|
||||
check("没那一档时回退到「平常」", portrait_of(five, "怒") == normal)
|
||||
# ③ 没有平常档 → 拿字典里任何一个还能用的(用户可能只传了一档)
|
||||
only_happy = store.normalize_image({"front": {"喜": happy}})
|
||||
check("连平常档都没有时,用字典里任何一个能用的",
|
||||
portrait_of(only_happy, "死亡") == happy, portrait_of(only_happy, "死亡"))
|
||||
# ④ **文件被删了**的那一档不许返回不存在的路径(那会让界面显示空白)
|
||||
broken = store.normalize_image({"front": {"喜": gone, "平常": normal}})
|
||||
check("档位指向的文件不存在时,跳过它去回退",
|
||||
portrait_of(broken, "喜") == normal, portrait_of(broken, "喜"))
|
||||
# ⑤ 完全没图 → 空串(界面据此用内置默认人物)
|
||||
check("没有立绘时返回空串(界面用内置默认人物)",
|
||||
portrait_of(store.normalize_image({}), "平常") == "")
|
||||
check("全是坏路径时也返回空串",
|
||||
portrait_of(store.normalize_image({"front": {"喜": gone}}), "喜") == "")
|
||||
# ⑥ 归一化不丢自定义档位(用户可能自己加了需求之外的档)
|
||||
custom = store.normalize_image({"front": {"醉": sad, "平常": normal}})
|
||||
check("归一化保留自定义档位(不丢信息)", custom["front"].get("醉") == sad, str(custom["front"]))
|
||||
check("自定义档位也能被选中", portrait_of(custom, "醉") == sad)
|
||||
shutil.rmtree(pic_dir, ignore_errors=True)
|
||||
|
||||
# ---------------------------------------------------------------- 汇总
|
||||
print()
|
||||
if fails:
|
||||
|
||||
Reference in New Issue
Block a user