Commit 954fb8be authored by Chunchi Che's avatar Chunchi Che

correct delay

parent 122be474
...@@ -60,225 +60,222 @@ const ActiveList = [ ...@@ -60,225 +60,222 @@ const ActiveList = [
const NeosConfig = useConfig(); const NeosConfig = useConfig();
export default function handleGameMsg(pb: ygopro.YgoStocMsg) { export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
// 防止MSG更新太频繁,做下控频 const msg = pb.stoc_game_msg;
const delay = matStore.delay;
if (ActiveList.includes(msg.gameMsg)) {
setTimeout(() => { matStore.waiting = false;
const msg = pb.stoc_game_msg; }
if (ActiveList.includes(msg.gameMsg)) { switch (msg.gameMsg) {
matStore.waiting = false; case "start": {
} onMsgStart(msg.start);
switch (msg.gameMsg) { break;
case "start": { }
onMsgStart(msg.start); case "draw": {
onMsgDraw(msg.draw);
break;
} break;
case "draw": { }
onMsgDraw(msg.draw); case "new_turn": {
onMsgNewTurn(msg.new_turn);
break;
} break;
case "new_turn": { }
onMsgNewTurn(msg.new_turn); case "new_phase": {
onMsgNewPhase(msg.new_phase);
break;
} break;
case "new_phase": { }
onMsgNewPhase(msg.new_phase); case "hint": {
onMsgHint(msg.hint);
break;
} break;
case "hint": { }
onMsgHint(msg.hint); case "select_idle_cmd": {
onMsgSelectIdleCmd(msg.select_idle_cmd);
break;
} break;
case "select_idle_cmd": { }
onMsgSelectIdleCmd(msg.select_idle_cmd); case "select_place": {
onMsgSelectPlace(msg.select_place);
break;
} break;
case "select_place": { }
onMsgSelectPlace(msg.select_place); case "move": {
onMsgMove(msg.move);
break; matStore.delay = NeosConfig.ui.moveDelay + 500;
}
case "move": { break;
onMsgMove(msg.move); }
case "select_card": {
break; onMsgSelectCard(msg.select_card);
}
case "select_card": { break;
onMsgSelectCard(msg.select_card); }
case "select_chain": {
break; onMsgSelectChain(msg.select_chain);
}
case "select_chain": { break;
onMsgSelectChain(msg.select_chain); }
case "select_effect_yn": {
break; onMsgSelectEffectYn(msg.select_effect_yn);
}
case "select_effect_yn": { break;
onMsgSelectEffectYn(msg.select_effect_yn); }
case "select_position": {
break; onMsgSelectPosition(msg.select_position);
}
case "select_position": { break;
onMsgSelectPosition(msg.select_position); }
case "select_option": {
break; onMsgSelectOption(msg.select_option);
}
case "select_option": { break;
onMsgSelectOption(msg.select_option); }
case "shuffle_hand": {
break; onMsgShuffleHand(msg.shuffle_hand);
}
case "shuffle_hand": { break;
onMsgShuffleHand(msg.shuffle_hand); }
case "select_battle_cmd": {
break; onMsgSelectBattleCmd(msg.select_battle_cmd);
}
case "select_battle_cmd": { break;
onMsgSelectBattleCmd(msg.select_battle_cmd); }
case "pos_change": {
break; onMsgPosChange(msg.pos_change);
}
case "pos_change": { break;
onMsgPosChange(msg.pos_change); }
case "select_unselect_card": {
break; onMsgSelectUnselectCard(msg.select_unselect_card);
}
case "select_unselect_card": { break;
onMsgSelectUnselectCard(msg.select_unselect_card); }
case "select_yes_no": {
break; onMsgSelectYesNo(msg.select_yes_no);
}
case "select_yes_no": { break;
onMsgSelectYesNo(msg.select_yes_no); }
case "update_hp": {
break; onMsgUpdateHp(msg.update_hp);
}
case "update_hp": { break;
onMsgUpdateHp(msg.update_hp); }
case "win": {
break; onMsgWin(msg.win);
}
case "win": { break;
onMsgWin(msg.win); }
case "wait": {
break; onMsgWait(msg.wait);
}
case "wait": { break;
onMsgWait(msg.wait); }
case "update_data": {
break; onMsgUpdateData(msg.update_data);
}
case "update_data": { break;
onMsgUpdateData(msg.update_data); }
case "reload_field": {
break; onMsgReloadField(msg.reload_field);
}
case "reload_field": { break;
onMsgReloadField(msg.reload_field); }
case "select_sum": {
break; onMsgSelectSum(msg.select_sum);
}
case "select_sum": { break;
onMsgSelectSum(msg.select_sum); }
case "select_tribute": {
break; onMsgSelectTribute(msg.select_tribute);
}
case "select_tribute": { break;
onMsgSelectTribute(msg.select_tribute); }
case "update_counter": {
break; onMsgUpdateCounter(msg.update_counter);
}
case "update_counter": { break;
onMsgUpdateCounter(msg.update_counter); }
case "select_counter": {
break; onMsgSelectCounter(msg.select_counter);
}
case "select_counter": { break;
onMsgSelectCounter(msg.select_counter); }
case "sort_card": {
break; onMsgSortCard(msg.sort_card);
}
case "sort_card": { break;
onMsgSortCard(msg.sort_card); }
case "set": {
break; onMsgSet(msg.set);
}
case "set": { break;
onMsgSet(msg.set); }
case "swap": {
break; onMsgSwap(msg.swap);
}
case "swap": { break;
onMsgSwap(msg.swap); }
case "attack": {
break; onMsgAttack(msg.attack);
}
case "attack": { break;
onMsgAttack(msg.attack); }
case "attack_disable": {
break; onMsgAttackDisable(msg.attack_disable);
}
case "attack_disable": { break;
onMsgAttackDisable(msg.attack_disable); }
case "chaining": {
break; onMsgChaining(msg.chaining);
} matStore.delay = NeosConfig.ui.chainingDelay;
case "chaining": {
onMsgChaining(msg.chaining); break;
}
break; case "chain_solved": {
} onMsgChainSolved(msg.chain_solved);
case "chain_solved": {
onMsgChainSolved(msg.chain_solved); break;
}
break; case "summoning": {
} onMsgSummoning(msg.summoning);
case "summoning": {
onMsgSummoning(msg.summoning); break;
}
break; case "summoned": {
} onMsgSummoned(msg.summoned);
case "summoned": {
onMsgSummoned(msg.summoned); break;
}
break; case "flip_summoning": {
} onMsgFlipSummoning(msg.flip_summoning);
case "flip_summoning": {
onMsgFlipSummoning(msg.flip_summoning); break;
}
break; case "flip_summoned": {
} onMsgFilpSummoned(msg.flip_summoned);
case "flip_summoned": {
onMsgFilpSummoned(msg.flip_summoned); break;
}
break; case "sp_summoning": {
} onMsgSpSummoning(msg.sp_summoning);
case "sp_summoning": {
onMsgSpSummoning(msg.sp_summoning); break;
}
break; case "sp_summoned": {
} onMsgSpSummoned(msg.sp_summoned);
case "sp_summoned": {
onMsgSpSummoned(msg.sp_summoned); break;
}
break; case "unimplemented": {
} onUnimplemented(msg.unimplemented);
case "unimplemented": {
onUnimplemented(msg.unimplemented); break;
}
break; default: {
} break;
default: { }
break; }
}
}
}, delay);
} }
import { sendTimeConfirm, ygopro } from "@/api"; import { sendTimeConfirm, ygopro } from "@/api";
import { useConfig } from "@/config";
import { matStore } from "@/stores"; import { matStore } from "@/stores";
export default function handleTimeLimit(timeLimit: ygopro.StocTimeLimit) { export default function handleTimeLimit(timeLimit: ygopro.StocTimeLimit) {
setTimeout(() => { matStore.timeLimits.set(timeLimit.player, timeLimit.left_time);
matStore.timeLimits.set(timeLimit.player, timeLimit.left_time); if (matStore.isMe(timeLimit.player)) {
sendTimeConfirm(); sendTimeConfirm();
}, useConfig().ui.commonDelay); }
} }
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
* */ * */
import { adaptStoc } from "@/api/ocgcore/ocgAdapter/adapter"; import { adaptStoc } from "@/api/ocgcore/ocgAdapter/adapter";
import { YgoProPacket } from "@/api/ocgcore/ocgAdapter/packet"; import { YgoProPacket } from "@/api/ocgcore/ocgAdapter/packet";
import { useConfig } from "@/config";
import { matStore } from "@/stores";
import handleGameMsg from "./duel/gameMsg"; import handleGameMsg from "./duel/gameMsg";
import handleTimeLimit from "./duel/timeLimit"; import handleTimeLimit from "./duel/timeLimit";
...@@ -18,6 +20,8 @@ import handleHsWatchChange from "./room/hsWatchChange"; ...@@ -18,6 +20,8 @@ import handleHsWatchChange from "./room/hsWatchChange";
import handleJoinGame from "./room/joinGame"; import handleJoinGame from "./room/joinGame";
import handleTypeChange from "./room/typeChange"; import handleTypeChange from "./room/typeChange";
const NeosConfig = useConfig();
/* /*
* 先将从长连接中读取到的二进制数据通过Adapter转成protobuf结构体, * 先将从长连接中读取到的二进制数据通过Adapter转成protobuf结构体,
* 然后再分发到各个处理函数中去处理。 * 然后再分发到各个处理函数中去处理。
...@@ -27,77 +31,84 @@ export default function handleSocketMessage(e: MessageEvent) { ...@@ -27,77 +31,84 @@ export default function handleSocketMessage(e: MessageEvent) {
const packet = YgoProPacket.deserialize(e.data); const packet = YgoProPacket.deserialize(e.data);
const pb = adaptStoc(packet); const pb = adaptStoc(packet);
switch (pb.msg) { // 防止MSG更新太频繁,做下控频
case "stoc_join_game": { const delay = matStore.delay;
handleJoinGame(pb); // 重置`delay`
matStore.delay = NeosConfig.ui.commonDelay;
break;
} setTimeout(() => {
case "stoc_chat": { switch (pb.msg) {
handleChat(pb); case "stoc_join_game": {
handleJoinGame(pb);
break;
} break;
case "stoc_hs_player_change": { }
handleHsPlayerChange(pb); case "stoc_chat": {
handleChat(pb);
break;
} break;
case "stoc_hs_watch_change": { }
handleHsWatchChange(pb); case "stoc_hs_player_change": {
handleHsPlayerChange(pb);
break;
} break;
case "stoc_hs_player_enter": { }
handleHsPlayerEnter(pb); case "stoc_hs_watch_change": {
handleHsWatchChange(pb);
break;
} break;
case "stoc_type_change": { }
handleTypeChange(pb); case "stoc_hs_player_enter": {
handleHsPlayerEnter(pb);
break;
} break;
case "stoc_select_hand": { }
handleSelectHand(pb); case "stoc_type_change": {
handleTypeChange(pb);
break;
} break;
case "stoc_hand_result": { }
// TODO case "stoc_select_hand": {
console.log("TODO: handle STOC HandResult."); handleSelectHand(pb);
break; break;
} }
case "stoc_select_tp": { case "stoc_hand_result": {
handleSelectTp(pb); // TODO
console.log("TODO: handle STOC HandResult.");
break;
} break;
case "stoc_deck_count": { }
handleDeckCount(pb); case "stoc_select_tp": {
handleSelectTp(pb);
break;
} break;
case "stoc_duel_start": { }
handleDuelStart(pb); case "stoc_deck_count": {
handleDeckCount(pb);
break;
} break;
case "stoc_game_msg": { }
handleGameMsg(pb); case "stoc_duel_start": {
handleDuelStart(pb);
break;
} break;
case "stoc_time_limit": { }
handleTimeLimit(pb.stoc_time_limit); case "stoc_game_msg": {
handleGameMsg(pb);
break;
} break;
default: { }
console.log(packet); case "stoc_time_limit": {
handleTimeLimit(pb.stoc_time_limit);
break;
break;
}
default: {
console.log(packet);
break;
}
} }
} }, delay);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment