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

correct delay

parent 122be474
......@@ -60,10 +60,6 @@ const ActiveList = [
const NeosConfig = useConfig();
export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
// 防止MSG更新太频繁,做下控频
const delay = matStore.delay;
setTimeout(() => {
const msg = pb.stoc_game_msg;
if (ActiveList.includes(msg.gameMsg)) {
......@@ -108,6 +104,7 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
}
case "move": {
onMsgMove(msg.move);
matStore.delay = NeosConfig.ui.moveDelay + 500;
break;
}
......@@ -233,6 +230,7 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
}
case "chaining": {
onMsgChaining(msg.chaining);
matStore.delay = NeosConfig.ui.chainingDelay;
break;
}
......@@ -280,5 +278,4 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
break;
}
}
}, delay);
}
import { sendTimeConfirm, ygopro } from "@/api";
import { useConfig } from "@/config";
import { matStore } from "@/stores";
export default function handleTimeLimit(timeLimit: ygopro.StocTimeLimit) {
setTimeout(() => {
matStore.timeLimits.set(timeLimit.player, timeLimit.left_time);
if (matStore.isMe(timeLimit.player)) {
sendTimeConfirm();
}, useConfig().ui.commonDelay);
}
}
......@@ -4,6 +4,8 @@
* */
import { adaptStoc } from "@/api/ocgcore/ocgAdapter/adapter";
import { YgoProPacket } from "@/api/ocgcore/ocgAdapter/packet";
import { useConfig } from "@/config";
import { matStore } from "@/stores";
import handleGameMsg from "./duel/gameMsg";
import handleTimeLimit from "./duel/timeLimit";
......@@ -18,6 +20,8 @@ import handleHsWatchChange from "./room/hsWatchChange";
import handleJoinGame from "./room/joinGame";
import handleTypeChange from "./room/typeChange";
const NeosConfig = useConfig();
/*
* 先将从长连接中读取到的二进制数据通过Adapter转成protobuf结构体,
* 然后再分发到各个处理函数中去处理。
......@@ -27,6 +31,12 @@ export default function handleSocketMessage(e: MessageEvent) {
const packet = YgoProPacket.deserialize(e.data);
const pb = adaptStoc(packet);
// 防止MSG更新太频繁,做下控频
const delay = matStore.delay;
// 重置`delay`
matStore.delay = NeosConfig.ui.commonDelay;
setTimeout(() => {
switch (pb.msg) {
case "stoc_join_game": {
handleJoinGame(pb);
......@@ -100,4 +110,5 @@ export default function handleSocketMessage(e: MessageEvent) {
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