Commit a65896ee authored by chechunchi's avatar chechunchi

update announce service

parent 1de2b5d6
Pipeline #21827 passed with stages
in 14 minutes and 11 seconds
import { ygopro } from "@/api";
type MsgAnnounce = ygopro.StocGameMessage.MsgAnnounce;
import { fetchCard, fetchStrings, getStrings, ygopro } from "@/api";
import { messageStore } from "@/stores";
import MsgAnnounce = ygopro.StocGameMessage.MsgAnnounce;
export default (announce: MsgAnnounce) => {
console.log(announce);
const { announceModal } = messageStore;
export default async (announce: MsgAnnounce) => {
const type_ = announce.announce_type;
let min = announce.min;
if (
type_ == MsgAnnounce.AnnounceType.Card ||
type_ == MsgAnnounce.AnnounceType.Number
) {
min = 1;
}
announceModal.min = min;
switch (type_) {
case MsgAnnounce.AnnounceType.RACE: {
announceModal.title = fetchStrings("!system", 563);
announceModal.options = announce.options.map((option) => ({
info: fetchStrings("!system", 1200 + option.code),
response: option.response,
}));
announceModal.isOpen = true;
break;
}
case MsgAnnounce.AnnounceType.Attribute: {
announceModal.title = fetchStrings("!system", 562);
announceModal.options = announce.options.map((option) => ({
info: fetchStrings("!system", 1010 + option.code),
response: option.response,
}));
announceModal.isOpen = true;
break;
}
case MsgAnnounce.AnnounceType.Card: {
announceModal.title = fetchStrings("!system", 564);
announceModal.options = await Promise.all(
announce.options.map(async (option) => ({
info: await fetchCard(option.code).then(
(meta) => meta.text.name ?? "[?]"
),
response: option.response,
}))
);
announceModal.isOpen = true;
break;
}
case MsgAnnounce.AnnounceType.Number: {
announceModal.title = fetchStrings("!system", 565);
announceModal.options = announce.options.map((option) => ({
info: option.code.toString(),
response: option.response,
}));
announceModal.isOpen = true;
break;
}
default: {
console.warn(`Unknown announce_type = ${type_}`);
}
}
};
......@@ -272,7 +272,7 @@ export default async function handleGameMsg(pb: ygopro.YgoStocMsg) {
break;
}
case "announce": {
onAnnounce(msg.announce);
await onAnnounce(msg.announce);
break;
}
......
......@@ -27,6 +27,7 @@ export const messageStore = proxy<ModalState>({
},
announceModal: {
isOpen: false,
min: 1,
options: [],
},
});
......
......@@ -91,6 +91,7 @@ export interface ModalState {
announceModal: {
isOpen: boolean;
title?: string;
min: number;
options: {
info: string;
response: number;
......
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