重连即重画:断线重连与硬刷新复用同一条路径(填 GameState → emit RESYNC_ALL), 不为重连单写一套渲染。deskinfo 按 step 分组填充,重连不重放 70 分开底那类 一次性事件。StartWar 支持差异化下发,按本座位取自己那份。 路由表 12 条注册齐全,test_dispatcher 的完整性断言随之转绿—— 漏接一个包就会红。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
140 lines
5.5 KiB
JavaScript
140 lines
5.5 KiB
JavaScript
///////////////////////////////////////////////////////////////
|
||
////////// EQW_ResyncHandler: 重连(deskinfo)与开局(StartWar)
|
||
///////////////////////////////////////////////////////////////
|
||
// 前端 04 §3:重连 = 重画。断线重连与硬刷新本质相同,复用同一条路径:
|
||
// 填 GameState → emit EQW_RESYNC_ALL → 各组件据数据重建界面
|
||
// 【绝不为重连单写一套渲染】。
|
||
//
|
||
// deskinfo 按 step 只带对应阶段的分组(协议文末):
|
||
// 恒有 count / idx / PlayerInfo / step / MyCards
|
||
// CallRun(step1) ChooseMain(step2) BuryCards(step3) PushCards(step5) Balance(step6)
|
||
//
|
||
// 【重连不重放一次性事件】:70 分坐庄的 3 秒开底是上庄时的一次性事件,
|
||
// deskinfo 里没有 ancard3s,前端也不得补播。
|
||
var EQW_ResyncHandler = EQW_ResyncHandler || {
|
||
|
||
//平台房间信息(roomcode / 总局数 / roomtype 位串)
|
||
handleSetRoomDes: function (roomcode, asetcount, roomtype) {
|
||
if (typeof asetcount === 'number') { EQW_GameState.room.asetCount = asetcount; }
|
||
EQW_GameState.room.options = EQW_RoomOptions_Parse.parse(roomtype);
|
||
},
|
||
|
||
//开局:makewar 可能差异化下发(sendtype:1 + seatlist[]),先取自己那份
|
||
handleStartWar: function (msg) {
|
||
if (!msg || !msg.data) {
|
||
console.warn('[EQW_ResyncHandler] StartWar 无数据,已忽略');
|
||
return;
|
||
}
|
||
var raw = msg.data.deskwar || msg.data;
|
||
var mine = raw;
|
||
if (raw && raw.sendtype === 1 && Object.prototype.toString.call(raw.seatlist) === '[object Array]') {
|
||
mine = null;
|
||
for (var i = 0; i < raw.seatlist.length; i++) {
|
||
if (raw.seatlist[i] && raw.seatlist[i].seat === EQW_GameState.room.mySeat) {
|
||
mine = raw.seatlist[i].data;
|
||
break;
|
||
}
|
||
}
|
||
if (!mine) {
|
||
console.error('[EQW_ResyncHandler] StartWar 差异化下发里没有本座位的数据');
|
||
return;
|
||
}
|
||
}
|
||
this.handleDeskinfo(mine);
|
||
},
|
||
|
||
//重连:deskinfo 全量快照
|
||
handleDeskinfo: function (info) {
|
||
if (!info) {
|
||
console.warn('[EQW_ResyncHandler] deskinfo 为空,已忽略');
|
||
return;
|
||
}
|
||
|
||
EQW_GameState.reset();
|
||
|
||
//—— 恒有的部分 ——
|
||
EQW_GameState._apply(EQW_GameState.room, info, {
|
||
asetCount: 'count',
|
||
asetIdx: 'idx',
|
||
playerScores: 'PlayerInfo'
|
||
});
|
||
EQW_GameState._apply(EQW_GameState.aset, info, { step: 'step' });
|
||
EQW_GameState._apply(EQW_GameState.my, info, { cards: 'MyCards' });
|
||
|
||
//—— 按阶段分组 ——
|
||
if (info.CallRun) { this._applyCallRun(info.CallRun); }
|
||
if (info.ChooseMain) { this._applyChooseMain(info.ChooseMain); }
|
||
if (info.BuryCards) { this._applyBuryCards(info.BuryCards); }
|
||
if (info.PushCards) { this._applyPushCards(info.PushCards); }
|
||
if (info.Balance) { this._applyBalance(info.Balance); }
|
||
|
||
EventBus.emit(EQW_Events.EQW_RESYNC_ALL);
|
||
},
|
||
|
||
_applyCallRun: function (g) {
|
||
EQW_GameState._apply(EQW_GameState.call, g, {
|
||
currcall: 'nowcall',
|
||
calls: 'call'
|
||
});
|
||
EQW_GameState._apply(EQW_GameState.aset, g, { multiple: 'multiple' });
|
||
EQW_GameState._apply(EQW_GameState.turn, g, {
|
||
seat: 'seat',
|
||
countdown: 'countdown'
|
||
});
|
||
},
|
||
|
||
_applyChooseMain: function (g) {
|
||
EQW_GameState._apply(EQW_GameState.aset, g, {
|
||
banker: 'banker',
|
||
call: 'call',
|
||
multiple: 'multiple',
|
||
touxiang: 'touxiang'
|
||
});
|
||
EQW_GameState._apply(EQW_GameState.my, g, { bottomCards: 'bottomcards' });
|
||
EQW_GameState._apply(EQW_GameState.turn, g, { countdown: 'countdown' });
|
||
EQW_GameState.turn.seat = EQW_GameState.aset.banker; //选主由庄家做
|
||
},
|
||
|
||
_applyBuryCards: function (g) {
|
||
EQW_GameState._apply(EQW_GameState.aset, g, {
|
||
banker: 'banker',
|
||
call: 'call',
|
||
multiple: 'multiple',
|
||
flower: 'flower'
|
||
});
|
||
EQW_GameState._apply(EQW_GameState.my, g, { bottomCards: 'bottomcards' });
|
||
EQW_GameState._apply(EQW_GameState.turn, g, { countdown: 'countdown' });
|
||
EQW_GameState.turn.seat = EQW_GameState.aset.banker; //埋牌由庄家做
|
||
},
|
||
|
||
_applyPushCards: function (g) {
|
||
EQW_GameState._apply(EQW_GameState.aset, g, {
|
||
banker: 'banker',
|
||
call: 'call',
|
||
multiple: 'multiple',
|
||
flower: 'flower',
|
||
grade: 'grade',
|
||
curmultiple: 'curmultiple'
|
||
});
|
||
EQW_GameState._apply(EQW_GameState.my, g, {
|
||
buryCards: 'burycards',
|
||
mustCard: 'mustcard'
|
||
});
|
||
EQW_GameState._apply(EQW_GameState.table, g, {
|
||
playproc: 'playproc',
|
||
pushlist: 'pushlist',
|
||
seatlist: 'seatlist',
|
||
liangpai: 'liangpai'
|
||
});
|
||
EQW_GameState._apply(EQW_GameState.turn, g, { countdown: 'countdown' });
|
||
//当前该谁出牌由 playproc.currseat 给出(服务端权威,前端不推导)
|
||
if (g.playproc && typeof g.playproc.currseat === 'number') {
|
||
EQW_GameState.turn.seat = g.playproc.currseat;
|
||
}
|
||
},
|
||
|
||
_applyBalance: function (g) {
|
||
EQW_GameState._apply(EQW_GameState.result, g, { aset: 'aset' });
|
||
}
|
||
};
|