feat: 添加扫雷游戏在线人数显示及定时更新功能
This commit is contained in:
parent
41ab104f83
commit
420912b3a7
@ -375,6 +375,16 @@
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.online-number {
|
||||
color: $accent-orange;
|
||||
font-weight: 700;
|
||||
font-size: 36rpx;
|
||||
}
|
||||
|
||||
.online-count-row {
|
||||
margin-top: $spacing-sm;
|
||||
}
|
||||
|
||||
// 按钮使用全局定义
|
||||
.start-btn {
|
||||
width: 380rpx;
|
||||
|
||||
@ -53,6 +53,10 @@
|
||||
<text class="intro-icon">🏆</text>
|
||||
<text class="intro-text">胜者赢取全额奖励</text>
|
||||
</view>
|
||||
<view class="intro-item online-count-row">
|
||||
<text class="intro-icon">👥</text>
|
||||
<text class="intro-text">当前在线: <text class="online-number">{{ onlineCount }}</text> 人</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="btn-primary start-btn" @tap="startMatchmaking">
|
||||
@ -329,6 +333,8 @@ export default {
|
||||
showSettlement: false,
|
||||
settlementWinnerId: '',
|
||||
showResultModal: false,
|
||||
onlineCount: 0,
|
||||
onlineCountInterval: null,
|
||||
// Timers
|
||||
matchInterval: null,
|
||||
turnInterval: null,
|
||||
@ -482,6 +488,10 @@ export default {
|
||||
this.addLog('system', '✅ 已连接到远程节点');
|
||||
this.setupSocketListeners();
|
||||
|
||||
// 获取在线人数
|
||||
this.fetchOnlineCount();
|
||||
this.onlineCountInterval = setInterval(() => this.fetchOnlineCount(), 10000);
|
||||
|
||||
// 跨设备对局发现逻辑:调用 RPC 询问服务器我当前是否有正在进行的战局
|
||||
if (!this.matchId) {
|
||||
try {
|
||||
@ -862,8 +872,19 @@ export default {
|
||||
cleanup() {
|
||||
clearInterval(this.matchInterval);
|
||||
clearInterval(this.turnInterval);
|
||||
clearInterval(this.onlineCountInterval);
|
||||
nakamaManager.disconnect();
|
||||
},
|
||||
async fetchOnlineCount() {
|
||||
try {
|
||||
const result = await nakamaManager.rpc('get_online_count', {});
|
||||
if (result && typeof result.online_count === 'number') {
|
||||
this.onlineCount = result.online_count;
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('获取在线人数失败:', e);
|
||||
}
|
||||
},
|
||||
getItemIcon(itemId) {
|
||||
const map = { medkit: '💊', bomb_timer: '⏰', poison: '☠️', shield: '🛡️', skip: '⏭️', magnifier: '🔍', knife: '🔪', revive: '💖', lightning: '⚡', chest: '📦', curse: '👻' };
|
||||
return map[itemId] || '🎁';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user