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

correct delay

parent 122be474
...@@ -60,10 +60,6 @@ const ActiveList = [ ...@@ -60,10 +60,6 @@ const ActiveList = [
const NeosConfig = useConfig(); const NeosConfig = useConfig();
export default function handleGameMsg(pb: ygopro.YgoStocMsg) { export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
// 防止MSG更新太频繁,做下控频
const delay = matStore.delay;
setTimeout(() => {
const msg = pb.stoc_game_msg; const msg = pb.stoc_game_msg;
if (ActiveList.includes(msg.gameMsg)) { if (ActiveList.includes(msg.gameMsg)) {
...@@ -108,6 +104,7 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) { ...@@ -108,6 +104,7 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
} }
case "move": { case "move": {
onMsgMove(msg.move); onMsgMove(msg.move);
matStore.delay = NeosConfig.ui.moveDelay + 500;
break; break;
} }
...@@ -233,6 +230,7 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) { ...@@ -233,6 +230,7 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
} }
case "chaining": { case "chaining": {
onMsgChaining(msg.chaining); onMsgChaining(msg.chaining);
matStore.delay = NeosConfig.ui.chainingDelay;
break; break;
} }
...@@ -280,5 +278,4 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) { ...@@ -280,5 +278,4 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
break; 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,6 +31,12 @@ export default function handleSocketMessage(e: MessageEvent) { ...@@ -27,6 +31,12 @@ 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);
// 防止MSG更新太频繁,做下控频
const delay = matStore.delay;
// 重置`delay`
matStore.delay = NeosConfig.ui.commonDelay;
setTimeout(() => {
switch (pb.msg) { switch (pb.msg) {
case "stoc_join_game": { case "stoc_join_game": {
handleJoinGame(pb); handleJoinGame(pb);
...@@ -100,4 +110,5 @@ export default function handleSocketMessage(e: MessageEvent) { ...@@ -100,4 +110,5 @@ export default function handleSocketMessage(e: MessageEvent) {
break; 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