From 20ef300fb66601d752671e9de950b1ecb3625971 Mon Sep 17 00:00:00 2001 From: LEEE Date: Mon, 9 Mar 2026 21:46:29 +0800 Subject: [PATCH] fix(badges): allow switching and show detailed badge intro --- game/badges.py | 2 ++ static/js/lobby.js | 37 +++++++++++++++++++++++++++++-------- static/js/user_profile.js | 9 +++++++++ 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/game/badges.py b/game/badges.py index a1832c1..f215393 100644 --- a/game/badges.py +++ b/game/badges.py @@ -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], } ) diff --git a/static/js/lobby.js b/static/js/lobby.js index d1afb11..d75d8b5 100644 --- a/static/js/lobby.js +++ b/static/js/lobby.js @@ -318,14 +318,35 @@ profileActiveBadgeInput.appendChild(option); }); - if (profileBadgeDesc) { - 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}`; - } + 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 = '未选择职业徽章,开局不会触发徽章加成。'; + 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(); }); } diff --git a/static/js/user_profile.js b/static/js/user_profile.js index 0c295ed..8072623 100644 --- a/static/js/user_profile.js +++ b/static/js/user_profile.js @@ -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)}`); }