feat: 猜成语游戏 - 完整题库、管理后台、答题弹窗
- 创建 idioms 表(102条谜语式成语题库)和 idiom_game_rounds 表 - 后台成语管理页面:增删改题目 + 游戏参数(金币/经验/间隔)内联设置 + 出题按钮 - IdiomQuizController:出题/答题/当前回合查询,Redis 防并发抢答 - IdiomGameStarted / IdiomGameAnswered 广播事件 - 前端答题弹窗模块:聊天消息带【答题】按钮,点击弹出输入框 - GameConfig 注册 idiom 游戏,由 admin.game-configs 统一管理开关
This commit is contained in:
@@ -366,6 +366,41 @@ export function bindChatEvents() {
|
||||
}
|
||||
enqueueChatMessage(msg);
|
||||
|
||||
// 猜成语消息:追加【答题】按钮
|
||||
if (msg.idom_game_round_id || msg.idiom_game_round_id) {
|
||||
const roundId = msg.idom_game_round_id || msg.idiom_game_round_id;
|
||||
const hint = msg.content || "";
|
||||
const rewardGold = msg.idiom_reward_gold || 0;
|
||||
const rewardExp = msg.idiom_reward_exp || 0;
|
||||
|
||||
// 延迟等消息渲染完成再追加按钮
|
||||
setTimeout(() => {
|
||||
const containers = [
|
||||
document.getElementById("chat-messages-container"),
|
||||
document.getElementById("chat-messages-container2"),
|
||||
];
|
||||
containers.forEach((container) => {
|
||||
if (!container) return;
|
||||
const lastMsg = container.lastElementChild;
|
||||
if (!lastMsg || lastMsg.querySelector("[data-idiom-answer-btn]")) return;
|
||||
if (lastMsg.dataset.fromUser !== "星海小博士") return;
|
||||
|
||||
const btn = document.createElement("button");
|
||||
btn.type = "button";
|
||||
btn.dataset.idiomAnswerBtn = String(roundId);
|
||||
btn.dataset.idiomHint = hint;
|
||||
btn.dataset.idiomGold = String(rewardGold);
|
||||
btn.dataset.idiomExp = String(rewardExp);
|
||||
btn.textContent = "🎯 答题";
|
||||
btn.style.cssText =
|
||||
"margin-left:8px;padding:2px 12px;background:linear-gradient(135deg,#7c3aed,#a78bfa);" +
|
||||
"color:#fff;border:none;border-radius:999px;font-size:11px;cursor:pointer;" +
|
||||
"font-weight:bold;vertical-align:middle;";
|
||||
lastMsg.appendChild(btn);
|
||||
});
|
||||
}, 50);
|
||||
}
|
||||
|
||||
if (msg.action === "vip_presence" && typeof window.showVipPresenceBanner === "function") {
|
||||
window.showVipPresenceBanner(msg);
|
||||
}
|
||||
@@ -470,6 +505,20 @@ export function bindChatEvents() {
|
||||
}
|
||||
});
|
||||
|
||||
// chat:idiom-started — 猜成语出题
|
||||
window.addEventListener("chat:idiom-started", (e) => {
|
||||
if (typeof window.handleIdiomGameStarted === "function") {
|
||||
window.handleIdiomGameStarted(e);
|
||||
}
|
||||
});
|
||||
|
||||
// chat:idiom-answered — 猜成语答题结果
|
||||
window.addEventListener("chat:idiom-answered", (e) => {
|
||||
if (typeof window.handleIdiomGameAnswered === "function") {
|
||||
window.handleIdiomGameAnswered(e);
|
||||
}
|
||||
});
|
||||
|
||||
// Echo 级监听器(延迟绑定,等待 Echo 就绪)
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
setupScreenClearedListener();
|
||||
|
||||
Reference in New Issue
Block a user