扫雷人数

This commit is contained in:
邹方成 2026-01-19 16:54:00 +08:00
parent 1af8bc7315
commit 51c6e872f3
2 changed files with 46 additions and 1 deletions

View File

@ -607,7 +607,6 @@ export default {
this.addLog('system', this.isSpectator ? '🔭 正在切入观察视角...' : '🚪 正在恢复战局...');
try {
await nakamaManager.joinMatch(this.matchId);
//
uni.setStorageSync('minesweeper_last_match_id', this.matchId);
this.addLog('system', '✅ 接入成功');
setTimeout(() => {
@ -620,6 +619,13 @@ export default {
uni.removeStorageSync('minesweeper_last_match_id');
}
}
// 线
this.joinLobby();
// 线
this.startOnlineCountPolling();
} catch (e) {
console.error('[初始化错误]', e);
this.addLog('system', '❌ 初始化失败: ' + e.message);
@ -1086,6 +1092,24 @@ export default {
console.warn('获取在线人数失败:', e);
}
},
async joinLobby() {
try {
// minesweeper_lobby , Type 1 (Room), Persistence True, Hidden False
await nakamaManager.joinChat('minesweeper_lobby', 1, true, false);
console.log('Successfully joined minesweeper lobby');
} catch (error) {
console.warn('Failed to join lobby channel:', error);
}
},
startOnlineCountPolling() {
if (this.onlineCountInterval) clearInterval(this.onlineCountInterval);
this.fetchOnlineCount(); // Fetch immediately
this.onlineCountInterval = setInterval(() => {
if (this.isConnected) {
this.fetchOnlineCount();
}
}, 5000); // Poll every 5 seconds
},
getItemIcon(itemId) {
const map = { medkit: '💊', bomb_timer: '⏰', poison: '☠️', shield: '🛡️', skip: '⏭️', magnifier: '🔍', knife: '🔪', revive: '💖', lightning: '⚡', chest: '📦', curse: '👻' };
return map[itemId] || '🎁';

View File

@ -379,6 +379,27 @@ class NakamaManager {
return response.match;
}
/**
* 加入聊天频道
* @param target 频道名称 (e.g., "minesweeper_lobby")
* @param type 频道类型 (1=Room, 2=Direct, 3=Group)
* @param persistence 是否持久化
* @param hidden 是否隐身
*/
async joinChat(target, type, persistence, hidden) {
console.log(`[Nakama] Joining chat channel: ${target}`);
const response = await this._send({
channel_join: {
target: target,
type: type,
persistence: persistence,
hidden: hidden
}
});
console.log('[Nakama] Joined channel:', response.channel?.id);
return response.channel;
}
/**
* 调用 RPC
*/