From acafb152155c0be5ee238ae1aac931fcbc15c443 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Thu, 24 Mar 2022 00:34:05 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=97=AC=EB=9F=AC=ED=84=B4=20=EC=98=88?= =?UTF-8?q?=EC=95=BD=EC=9D=84=20ReserveBulkdCommand=EB=A1=9C=20=EB=8C=80?= =?UTF-8?q?=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/API/Command/ReserveBulkCommand.php | 76 ++++++++++++++++++++ hwe/ts/PartialReservedCommand.vue | 47 ++++++------ hwe/ts/SammoAPI.ts | 13 ++-- hwe/ts/defs.ts | 5 ++ hwe/ts/util/callSammoAPI.ts | 8 +-- 5 files changed, 114 insertions(+), 35 deletions(-) create mode 100644 hwe/sammo/API/Command/ReserveBulkCommand.php diff --git a/hwe/sammo/API/Command/ReserveBulkCommand.php b/hwe/sammo/API/Command/ReserveBulkCommand.php new file mode 100644 index 00000000..d612aa77 --- /dev/null +++ b/hwe/sammo/API/Command/ReserveBulkCommand.php @@ -0,0 +1,76 @@ +args as $idx => $turn) { + $v = new Validator($turn); + $v->rule('required', [ + 'action', + 'turnList' + ]) + ->rule('lengthMin', 'action', 1) + ->rule('integerArray', 'turnList'); + + if (!$v->validate()) { + return "{$idx}:{$v->errorStr()}"; + } + } + + return null; + } + + public function getRequiredSessionMode(): int + { + return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY; + } + + public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag) + { + $briefList = []; + foreach ($this->args as $idx => $turn) { + $action = $turn['action']; + $turnList = $turn['turnList']; + $arg = $turn['arg'] ?? []; + + if (!$turnList) { + return "{$idx}: 턴이 입력되지 않았습니다"; + } + + if (!in_array($action, Util::array_flatten(GameConst::$availableGeneralCommand))) { + return "{$idx}: 사용할 수 없는 커맨드입니다."; + } + + if (!is_array($arg)) { + return "{$idx}: 올바른 arg 형태가 아닙니다."; + } + $partialResult = setGeneralCommand($session->generalID, $turnList, $action, $arg); + if(!$partialResult['result']){ + return [ + 'result' => false, + 'briefList' => $briefList, + 'errorIdx' => $idx, + 'reason' => $partialResult['reason'] + ]; + } + $briefList[$idx] = $partialResult['brief']; + } + + return [ + 'result' => true, + 'briefList' => $briefList, + 'reason' => 'success' + ]; + } +} diff --git a/hwe/ts/PartialReservedCommand.vue b/hwe/ts/PartialReservedCommand.vue index d96be3d8..e2403bde 100644 --- a/hwe/ts/PartialReservedCommand.vue +++ b/hwe/ts/PartialReservedCommand.vue @@ -319,12 +319,13 @@ import { parseTime } from "@util/parseTime"; import { parseYearMonth } from "@util/parseYearMonth"; import DragSelect from "@/components/DragSelect.vue"; import { SammoAPI, type InvalidResponse } from "./SammoAPI"; -import type { CommandItem, ReserveCommandResponse } from "@/defs"; +import type { CommandItem, ReserveBulkCommandResponse, ReserveCommandResponse } from "@/defs"; import CommandSelectForm from "@/components/CommandSelectForm.vue"; import { BButton, BButtonGroup, BDropdownItem, BDropdown, BDropdownText, BDropdownDivider } from "bootstrap-vue-3"; import { StoredActionsHelper } from "./util/StoredActionsHelper"; import type { TurnObj } from '@/defs'; import { unwrap } from "./util/unwrap"; +import type { Args } from "./processing/args"; type TurnObjWithTime = TurnObj & { time: string; @@ -620,37 +621,33 @@ async function reloadCommandList() { async function reserveCommandDirect(args: [number[], TurnObj][], reload = true): Promise { const waiterList: Promise[] = []; + + const query: { + turnList: number[], + action: string, + arg: Args + }[] = []; for (const [turnList, { action, arg }] of args) { - waiterList.push( - SammoAPI.Command.ReserveCommand({ - turnList, - action, - arg, - }, true) - ); + query.push({ + turnList, + action, + arg + }); } - let success = true; - for (const [idx, waiter] of waiterList.entries()) { - try { - const response = await waiter; - if (!response.result) { - const message = `${args[idx][0].join(',')}을 예약하지 못했습니다: ${response.reason}` - console.error(message, args[idx][1]); - alert(message); - success = false; - } - } - catch (e) { - const message = `${args[idx][0].join(',')}을 예약하지 못했습니다: ${e}` - console.error(message, args[idx][1]); - success = false; - } + try { + await SammoAPI.Command.ReserveBulkCommand(query); + releaseSelectedTurnList(); + } catch (e) { + console.error(e); + alert(`실패했습니다: ${e}`); + return false; } + if (reload) { await reloadCommandList(); } - return success; + return true; } function getSelectedTurnList(): number[] { diff --git a/hwe/ts/SammoAPI.ts b/hwe/ts/SammoAPI.ts index 47f9f2d3..74308537 100644 --- a/hwe/ts/SammoAPI.ts +++ b/hwe/ts/SammoAPI.ts @@ -3,17 +3,17 @@ import { APIPathGen } from "./util/APIPathGen"; import { callSammoAPI, type ValidResponse } from "./util/callSammoAPI"; export type { ValidResponse, InvalidResponse }; -async function done(args?: Record): Promise; -async function done(args: Record | undefined, returnError: false): Promise; -async function done(args: Record | undefined, returnError: true): Promise; +async function done(args?: Record | Record[]): Promise; +async function done(args: Record | Record[] | undefined, returnError: false): Promise; +async function done(args: Record | Record[] | undefined, returnError: true): Promise; -async function done(args?: Record, returnError = false): Promise { +async function done(args?: Record | Record[], returnError = false): Promise { console.error(`Can't directly call. ${args}, ${returnError}. Use auto-generated path API.`); return callSammoAPI([], args, true); } const apiRealPath = { - Betting:{ + Betting: { Bet: done, GetBettingDetail: done, GetBettingList: done, @@ -23,6 +23,7 @@ const apiRealPath = { PushCommand: done, RepeatCommand: done, ReserveCommand: done, + ReserveBulkCommand: done, }, General: { Join: done, @@ -54,7 +55,7 @@ const apiRealPath = { } as const; export const SammoAPI = APIPathGen(apiRealPath, (path: string[]) => { - return (args?: Record, returnError?: boolean) => { + return (args?: Record | Record[], returnError?: boolean) => { if (returnError) { return callSammoAPI(path.join('/'), args, true); } diff --git a/hwe/ts/defs.ts b/hwe/ts/defs.ts index bf95199b..3c10c256 100644 --- a/hwe/ts/defs.ts +++ b/hwe/ts/defs.ts @@ -40,6 +40,11 @@ export type ReserveCommandResponse = { brief: string, } +export type ReserveBulkCommandResponse = { + result: true, + briefList: string[], +} + export type NationLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7; export const NationLevelText: Record = { 0: '방랑군', diff --git a/hwe/ts/util/callSammoAPI.ts b/hwe/ts/util/callSammoAPI.ts index dad9c3bd..bfb0652d 100644 --- a/hwe/ts/util/callSammoAPI.ts +++ b/hwe/ts/util/callSammoAPI.ts @@ -6,11 +6,11 @@ export type ValidResponse = { result: true } -export async function callSammoAPI(path: string | string[], args?: Record): Promise; -export async function callSammoAPI(path: string | string[], args: Record | undefined, returnError: false): Promise; -export async function callSammoAPI(path: string | string[], args: Record | undefined, returnError: true): Promise; +export async function callSammoAPI(path: string | string[], args?: Record | Record[]): Promise; +export async function callSammoAPI(path: string | string[], args: Record | Record[] | undefined, returnError: false): Promise; +export async function callSammoAPI(path: string | string[], args: Record | Record[] | undefined, returnError: true): Promise; -export async function callSammoAPI(path: string | string[], args?: Record, returnError = false): Promise { +export async function callSammoAPI(path: string | string[], args?: Record | Record[], returnError = false): Promise { if (isArray(path)) { path = path.join('/'); }