feat(WIP): 턴 선택기 고급 확장

- 최근 예약 턴 저장
This commit is contained in:
2022-03-23 20:12:59 +09:00
parent 30b78a1938
commit bcf52e0460
5 changed files with 243 additions and 70 deletions
+21 -5
View File
@@ -9,11 +9,18 @@ import { type App, createApp } from 'vue';
import { auto500px } from './util/auto500px';
import { isString } from 'lodash';
import { type Args, testSubmitArgs } from './processing/args';
import { SammoAPI, type ValidResponse } from './SammoAPI';
import { SammoAPI } from './SammoAPI';
import { StoredActionsHelper } from './util/StoredActionsHelper';
import type { ReserveCommandResponse } from './defs';
declare const turnList: number[];
declare const staticValues: {
serverNick: string,
turnList: number[],
};
async function submitCommand<T extends ValidResponse>(isChiefTurn: boolean, turnList: number[], action: string, arg: Args): Promise<T> {
const { turnList } = staticValues;
async function submitCommand<T extends ReserveCommandResponse>(isChiefTurn: boolean, turnList: number[], action: string, arg: Args): Promise<T> {
const targetAPI = isChiefTurn ? SammoAPI.NationCommand.ReserveCommand : SammoAPI.Command.ReserveCommand;
try {
@@ -22,19 +29,28 @@ async function submitCommand<T extends ValidResponse>(isChiefTurn: boolean, turn
throw new TypeError(`Invalied Type ${testResult[0]}, ${testResult[2]} should be ${testResult[1]}`);
}
console.log('trySubmit', arg);
const response = await targetAPI({
const responseP = targetAPI<T>({
action,
turnList,
arg,
});
const storedActionsHelper = new StoredActionsHelper(staticValues.serverNick, isChiefTurn?'nation':'general');
const response = await responseP;
storedActionsHelper.pushRecentActions({
action,
brief: response.brief,
arg: (arg??{}),
})
if (!isChiefTurn) {
window.location.href = './';
} else {
window.location.href = 'v_chiefCenter.php';
}
return response as T;
return response;
}
catch (e) {
console.error(e);