fix(badges): allow switching and show detailed badge intro

This commit is contained in:
leeexin committed 2026-03-09 21:46:29 +08:00
1 parent 81cc92efea
commit 20ef300fb6
3 files changed
+38 -6

No files matched your search

+2
View File
@@ -169,8 +169,10 @@ def build_badge_progress(
"progress_value": progress_value,
"progress_percent": progress_percent,
"unlocked": unlocked,
"genre_keywords": _parse_text_list(badge.get("genre_keywords", []), limit=16),
"special_choice": str(badge.get("special_choice", "")).strip()[:48],
"effect_item": str(badge.get("effect_item", "")).strip()[:48],
"effect_clue": str(badge.get("effect_clue", "")).strip()[:180],
}
)
+27 -6
View File
@@ -318,14 +318,35 @@
profileActiveBadgeInput.appendChild(option);
});
if (profileBadgeDesc) {
const selected = rows.find((row) => row.id === profileActiveBadgeInput.value) || null;
updateBadgeDescription();
};
const metricLabel = (metric) => {
const key = String(metric || '').trim();
if (key === 'wins') return '胜场';
if (key === 'best_streak') return '最高连胜';
return '对局数';
};
const updateBadgeDescription = () => {
if (!profileBadgeDesc) return;
const progress = lobbyState.badgeProgress || {};
const rows = Array.isArray(progress.badges) ? progress.badges : [];
const selected = rows.find((row) => row.id === profileActiveBadgeInput?.value) || null;
if (!selected) {
profileBadgeDesc.textContent = '未选择职业徽章,开局不会触发徽章加成。';
} else {
profileBadgeDesc.textContent = `${selected.description || ''} 当前解锁进度:${selected.progress_value || 0}/${selected.unlock_threshold || 1}`;
}
return;
}
const desc = String(selected.description || '').trim() || '暂无介绍';
const unlockLabel = `${metricLabel(selected.unlock_metric)} ${selected.unlock_current || 0}/${selected.unlock_threshold || 1}`;
const effects = [];
if (selected.effect_item) effects.push(`开局物品:${selected.effect_item}`);
if (selected.effect_clue) effects.push(`开局线索:${selected.effect_clue}`);
if (selected.special_choice) effects.push(`特殊行动:${selected.special_choice}`);
const tags = Array.isArray(selected.genre_keywords) ? selected.genre_keywords.filter(Boolean).slice(0, 8) : [];
const tagText = tags.length ? ` 适配题材:${tags.join('、')}` : '';
const effectText = effects.length ? ` 效果:${effects.join(';')}` : '';
profileBadgeDesc.textContent = `${desc} 解锁进度:${unlockLabel}.${effectText}${tagText}`;
};
const loadBadgeProgress = async () => {
@@ -553,7 +574,7 @@
if (profileActiveBadgeInput) {
profileActiveBadgeInput.addEventListener('change', () => {
renderBadgeOptions();
updateBadgeDescription();
});
}
+9
View File
@@ -282,6 +282,15 @@
`总回合:${stats.total_rounds || 0}`,
`职业徽章:${activeBadge ? activeBadge.name : '未选择'}`,
];
if (activeBadge) {
const badgeDesc = String(activeBadge.description || '').trim();
const effects = [];
if (activeBadge.effect_item) effects.push(`开局物品 ${activeBadge.effect_item}`);
if (activeBadge.effect_clue) effects.push(`开局线索 ${activeBadge.effect_clue}`);
if (activeBadge.special_choice) effects.push(`特殊行动 ${activeBadge.special_choice}`);
const intro = badgeDesc || '暂无介绍';
rows.push(`徽章介绍:${intro}${effects.length ? `(${effects.join(';')})` : ''}`);
}
if (points && typeof points === 'object') {
rows.push(`积分余额:${Number(points.balance || 0)} / 可用 ${Number(points.available_balance || 0)}`);
}