Commit fb18f29b authored by Chunchi Che's avatar Chunchi Che

Merge branch 'optimize/ui/select_chain' into 'main'

Make some operation to be automated

See merge request !371
parents ec460b80 57c0f0c1
Pipeline #27176 passed with stages
in 13 minutes and 15 seconds
import { ygopro } from "@/api"; import { sendSelectMultiResponse, ygopro } from "@/api";
import MsgSelectCard = ygopro.StocGameMessage.MsgSelectCard; import MsgSelectCard = ygopro.StocGameMessage.MsgSelectCard;
import { displaySelectActionsModal } from "@/ui/Duel/Message/SelectActionsModal"; import { displaySelectActionsModal } from "@/ui/Duel/Message/SelectActionsModal";
...@@ -10,6 +10,12 @@ export default async (selectCard: MsgSelectCard) => { ...@@ -10,6 +10,12 @@ export default async (selectCard: MsgSelectCard) => {
// TODO: handle release_param // TODO: handle release_param
if (!cancelable && cards.length === 1) {
// auto send
sendSelectMultiResponse([cards[0].response]);
return;
}
const { selecteds, mustSelects, selectables } = await fetchCheckCardMeta( const { selecteds, mustSelects, selectables } = await fetchCheckCardMeta(
cards, cards,
); );
......
...@@ -13,6 +13,11 @@ export default async (selectOption: ygopro.StocGameMessage.MsgSelectOption) => { ...@@ -13,6 +13,11 @@ export default async (selectOption: ygopro.StocGameMessage.MsgSelectOption) => {
sendSelectOptionResponse(0); sendSelectOptionResponse(0);
return; return;
} }
if (options.length === 1) {
sendSelectOptionResponse(options[0].response);
return;
}
await displayOptionModal( await displayOptionModal(
fetchStrings(Region.System, 556), fetchStrings(Region.System, 556),
options.map(({ code, response }) => ({ options.map(({ code, response }) => ({
......
...@@ -3,8 +3,8 @@ import { cardStore, matStore } from "@/stores"; ...@@ -3,8 +3,8 @@ import { cardStore, matStore } from "@/stores";
import { displaySelectActionsModal } from "@/ui/Duel/Message/SelectActionsModal"; import { displaySelectActionsModal } from "@/ui/Duel/Message/SelectActionsModal";
import { fetchCheckCardMeta } from "../utils"; import { fetchCheckCardMeta } from "../utils";
import { isAllOnField } from "./util";
type MsgSelectUnselectCard = ygopro.StocGameMessage.MsgSelectUnselectCard; type MsgSelectUnselectCard = ygopro.StocGameMessage.MsgSelectUnselectCard;
const { MZONE, SZONE, HAND } = ygopro.CardZone;
export default async ({ export default async ({
finishable, finishable,
...@@ -15,9 +15,9 @@ export default async ({ ...@@ -15,9 +15,9 @@ export default async ({
selected_cards: selectedCards, selected_cards: selectedCards,
}: MsgSelectUnselectCard) => { }: MsgSelectUnselectCard) => {
if ( if (
selectableCards isAllOnField(
.concat(selectedCards) selectableCards.concat(selectedCards).map((info) => info.location),
.find((info) => !isOnField(info.location)) === undefined )
) { ) {
// 所有可选卡和已选卡都是在场上或手牌 // 所有可选卡和已选卡都是在场上或手牌
// 通过让玩家点击场上的卡来进行选择 // 通过让玩家点击场上的卡来进行选择
...@@ -65,7 +65,3 @@ export default async ({ ...@@ -65,7 +65,3 @@ export default async ({
}); });
} }
}; };
function isOnField(location: ygopro.CardLocation): boolean {
return [MZONE, SZONE, HAND].includes(location.zone);
}
import { ygopro } from "@/api";
const { MZONE, SZONE, HAND } = ygopro.CardZone;
export function isAllOnField(locations: ygopro.CardLocation[]): boolean {
const isOnField = (location: ygopro.CardLocation) => {
return [MZONE, SZONE, HAND].includes(location.zone);
};
return locations.find((location) => !isOnField(location)) === undefined;
}
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