Commit e47d0dd2 authored by chechunchi's avatar chechunchi

migrate to async/await

parent c4303824
Pipeline #21729 passed with stages
in 13 minutes and 23 seconds
import { ygopro } from "@/api";
import { sleep } from "@/infra";
import { fetchEsHintMeta, matStore } from "@/stores";
export default (attack: ygopro.StocGameMessage.MsgAttack) => {
export default async (attack: ygopro.StocGameMessage.MsgAttack) => {
fetchEsHintMeta({
originMsg: "「[?]」攻击时",
location: attack.attacker_location,
......@@ -16,7 +17,8 @@ export default (attack: ygopro.StocGameMessage.MsgAttack) => {
if (attack.direct_attack) {
attacker.directAttack = true;
setTimeout(() => (attacker.directAttack = false), 500);
await sleep(500);
attacker.directAttack = false;
} else {
const target = matStore
.in(attack.target_location.location)
......@@ -30,7 +32,8 @@ export default (attack: ygopro.StocGameMessage.MsgAttack) => {
...target,
};
setTimeout(() => (attacker.attackTarget = undefined), 500);
await sleep(500);
attacker.attackTarget = undefined;
}
}
}
......
import { ygopro } from "@/api";
import { useConfig } from "@/config";
import { sleep } from "@/infra";
import { fetchEsHintMeta, matStore } from "@/stores";
export default (chaining: ygopro.StocGameMessage.MsgChaining) => {
export default async (chaining: ygopro.StocGameMessage.MsgChaining) => {
fetchEsHintMeta({
originMsg: "「[?]」被发动时",
cardID: chaining.code,
......@@ -10,8 +11,7 @@ export default (chaining: ygopro.StocGameMessage.MsgChaining) => {
matStore.setChaining(chaining.location, chaining.code, true);
setTimeout(() => {
matStore.setChaining(chaining.location, chaining.code, false);
// TODO: set chained
}, useConfig().ui.chainingDelay);
await sleep(useConfig().ui.chainingDelay);
matStore.setChaining(chaining.location, chaining.code, false);
// TODO: set chained
};
......@@ -56,7 +56,7 @@ const ActiveList = [
"select_yes_no",
];
export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
export default async function handleGameMsg(pb: ygopro.YgoStocMsg) {
const msg = pb.stoc_game_msg;
if (ActiveList.includes(msg.gameMsg)) {
......@@ -100,7 +100,7 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
break;
}
case "move": {
onMsgMove(msg.move);
await onMsgMove(msg.move);
break;
}
......@@ -215,7 +215,7 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
break;
}
case "attack": {
onMsgAttack(msg.attack);
await onMsgAttack(msg.attack);
break;
}
......@@ -225,7 +225,7 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
break;
}
case "chaining": {
onMsgChaining(msg.chaining);
await onMsgChaining(msg.chaining);
break;
}
......
......@@ -4,6 +4,7 @@ import { ygopro } from "@/api";
import { fetchOverlayMeta, store } from "@/stores";
type MsgMove = ygopro.StocGameMessage.MsgMove;
import { useConfig } from "@/config";
import { sleep } from "@/infra";
import { REASON_MATERIAL } from "../../common";
......@@ -12,7 +13,7 @@ const NeosConfig = useConfig();
const OVERLAY_STACK: { uuid: string; code: number; sequence: number }[] = [];
export default (move: MsgMove) => {
export default async (move: MsgMove) => {
const code = move.code;
const from = move.from;
const to = move.to;
......@@ -79,12 +80,8 @@ export default (move: MsgMove) => {
matStore.in(to.location).of(to.controler)[to.sequence].uuid = uuid;
}
setTimeout(
() =>
(matStore.in(to.location).of(to.controler)[to.sequence].focus =
false),
NeosConfig.ui.moveDelay
);
await sleep(NeosConfig.ui.moveDelay);
matStore.in(to.location).of(to.controler)[to.sequence].focus = false;
break;
}
case ygopro.CardZone.REMOVED:
......@@ -112,12 +109,11 @@ export default (move: MsgMove) => {
true
);
setTimeout(() => {
// 因为手牌可能会洗牌,sequence就对不上了,所以这里把所有手牌的focus字段都设置成false
for (const hand of matStore.in(to.location).of(to.controler)) {
hand.focus = false;
}
}, NeosConfig.ui.moveDelay);
await sleep(NeosConfig.ui.moveDelay);
// 因为手牌可能会洗牌,sequence就对不上了,所以这里把所有手牌的focus字段都设置成false
for (const hand of matStore.in(to.location).of(to.controler)) {
hand.focus = false;
}
}
break;
}
......
......@@ -6,6 +6,7 @@ import { ygopro } from "@/api";
import { adaptStoc } from "@/api/ocgcore/ocgAdapter/adapter";
import { YgoProPacket } from "@/api/ocgcore/ocgAdapter/packet";
import { useConfig } from "@/config";
import { sleep } from "@/infra";
import { matStore } from "@/stores";
import handleGameMsg from "./duel/gameMsg";
......@@ -33,81 +34,81 @@ export default async function handleSocketMessage(e: MessageEvent) {
const pb = adaptStoc(packet);
const delay = handleDelay(pb);
setTimeout(() => {
switch (pb.msg) {
case "stoc_join_game": {
handleJoinGame(pb);
break;
}
case "stoc_chat": {
handleChat(pb);
break;
}
case "stoc_hs_player_change": {
handleHsPlayerChange(pb);
break;
}
case "stoc_hs_watch_change": {
handleHsWatchChange(pb);
break;
}
case "stoc_hs_player_enter": {
handleHsPlayerEnter(pb);
break;
}
case "stoc_type_change": {
handleTypeChange(pb);
break;
}
case "stoc_select_hand": {
handleSelectHand(pb);
break;
}
case "stoc_hand_result": {
// TODO
console.log("TODO: handle STOC HandResult.");
break;
}
case "stoc_select_tp": {
handleSelectTp(pb);
break;
}
case "stoc_deck_count": {
handleDeckCount(pb);
break;
}
case "stoc_duel_start": {
handleDuelStart(pb);
break;
}
case "stoc_game_msg": {
handleGameMsg(pb);
break;
}
case "stoc_time_limit": {
handleTimeLimit(pb.stoc_time_limit);
break;
}
default: {
console.log(packet);
break;
}
await sleep(delay);
switch (pb.msg) {
case "stoc_join_game": {
handleJoinGame(pb);
break;
}
case "stoc_chat": {
handleChat(pb);
break;
}
case "stoc_hs_player_change": {
handleHsPlayerChange(pb);
break;
}
case "stoc_hs_watch_change": {
handleHsWatchChange(pb);
break;
}
}, delay);
case "stoc_hs_player_enter": {
handleHsPlayerEnter(pb);
break;
}
case "stoc_type_change": {
handleTypeChange(pb);
break;
}
case "stoc_select_hand": {
handleSelectHand(pb);
break;
}
case "stoc_hand_result": {
// TODO
console.log("TODO: handle STOC HandResult.");
break;
}
case "stoc_select_tp": {
handleSelectTp(pb);
break;
}
case "stoc_deck_count": {
handleDeckCount(pb);
break;
}
case "stoc_duel_start": {
handleDuelStart(pb);
break;
}
case "stoc_game_msg": {
await handleGameMsg(pb);
break;
}
case "stoc_time_limit": {
handleTimeLimit(pb.stoc_time_limit);
break;
}
default: {
console.log(packet);
break;
}
}
}
// 该函数用于控频,防止MSG更新太频繁,返回值是延迟的时间戳(毫秒)
......
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