refac(WIP): SammoAPI, select_npc

This commit is contained in:
2022-04-07 03:03:38 +09:00
parent 94acf87695
commit 3b4cbf68ca
3 changed files with 62 additions and 64 deletions
+4
View File
@@ -13,6 +13,7 @@ import type { SetBlockWarResponse } from "./defs/API/Nation";
import type { UploadImageResponse } from "./defs/API/Misc";
import type { JoinArgs } from "./defs/API/General";
import type { GetConstResponse } from "./defs/API/Global";
import type { GeneralListResponse } from "./defs";
const apiRealPath = {
Betting: {
@@ -49,6 +50,9 @@ const apiRealPath = {
Join: POST as APICallT<JoinArgs>,
},
Global: {
GeneralList: GET as APICallT<{
with_token?: boolean
}, GeneralListResponse>,
GetConst: GET as APICallT<undefined, GetConstResponse>,
},
InheritAction: {
+39 -11
View File
@@ -1,5 +1,6 @@
import type { Args } from "@/processing/args";
import type { ValidResponse, InvalidResponse } from "@/util/callSammoAPI";
import type { GameObjClassKey } from "./GameObj";
export type { ValidResponse, InvalidResponse };
export type BasicGeneralListResponse = {
@@ -15,21 +16,48 @@ export type BasicGeneralListResponse = {
}>
}
export type PublicGeneralItem = {
no: number,
picture: string,
imgsvr: 0 | 1,
npc: number,
age: number,
nation: string,
specialDomestic: GameObjClassKey,
specialWar: GameObjClassKey,
personal: GameObjClassKey,
name: string,
ownerName: string | null,
injury: number,
leadership: number,
lbonus: number,
strength: number,
intel: number,
explevel: number,
experienceStr: string,
dedicationStr: string,
officerLevelStr: string,
killturn: number,
connect: number,
}
export type GeneralListResponse = {
result: true,
list: [
number,
string, 0 | 1,
number, number, string,
string, string, string,
string, string | null,
number,
number, number, number, number,
number,
string, string, string,
number, number
PublicGeneralItem['no'],
PublicGeneralItem['picture'], PublicGeneralItem['imgsvr'],
PublicGeneralItem['npc'], PublicGeneralItem['age'], PublicGeneralItem['nation'],
PublicGeneralItem['specialDomestic'], PublicGeneralItem['specialWar'], PublicGeneralItem['personal'],
PublicGeneralItem['name'], PublicGeneralItem['ownerName'],
PublicGeneralItem['injury'],
PublicGeneralItem['leadership'], PublicGeneralItem['lbonus'], PublicGeneralItem['strength'], PublicGeneralItem['intel'],
PublicGeneralItem['explevel'],
PublicGeneralItem['experienceStr'], PublicGeneralItem['dedicationStr'], PublicGeneralItem['officerLevelStr'],
PublicGeneralItem['killturn'], PublicGeneralItem['connect']
][],
token: Record<number, number>,
token?: Record<number, number>,
}
export type NationLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
+19 -53
View File
@@ -3,12 +3,14 @@ import { errUnknown } from '@/common_legacy';
import { getIconPath } from "@util/getIconPath";
import { TemplateEngine } from "@util/TemplateEngine";
import { getNpcColor } from '@/common_legacy';
import type { GeneralListResponse, InvalidResponse } from '@/defs';
import type { GeneralListResponse, InvalidResponse, PublicGeneralItem } from '@/defs';
import { convertFormData } from '@util/convertFormData';
import { unwrap_any } from '@util/unwrap_any';
import { setAxiosXMLHttpRequest } from '@util/setAxiosXMLHttpRequest';
import { Tooltip } from 'bootstrap';
import { trim } from 'lodash';
import { SammoAPI } from './SammoAPI';
import { unwrap } from './util/unwrap';
setAxiosXMLHttpRequest();
@@ -40,29 +42,7 @@ type NPCPick = {
personalText?: string,
}
type NPCPickPrintableR = {
no: number,
picture: string,
imgsvr: 0 | 1,
npc: number,
age: number,
nation: string,
special: string,
special2: string,
personal: string,
name: string,
ownerName: string | null,
injury: number,
leadership: number,
lbonus: number,
strength: number,
intel: number,
explevel: number,
experience: string,
dedication: string,
officerLevel: string,
killturn: number,
connect: number,
type NPCPickPrintableR = PublicGeneralItem & {
reserved: number,
userCSS?: string,
@@ -269,7 +249,7 @@ function printGenerals(value: NPCToken) {
function printGeneralList(value: GeneralListResponse) {
console.log(value);
const tokenList = value.token;
const tokenList = unwrap(value.token);
const generalList: NPCPickPrintable[] = value.list.map((rawGeneral) => {
const general: NPCPickPrintableR = {
no: rawGeneral[0],
@@ -278,8 +258,8 @@ function printGeneralList(value: GeneralListResponse) {
npc: rawGeneral[3],
age: rawGeneral[4],
nation: rawGeneral[5],
special: rawGeneral[6],
special2: rawGeneral[7],
specialDomestic: rawGeneral[6],
specialWar: rawGeneral[7],
personal: rawGeneral[8],
name: rawGeneral[9],
ownerName: rawGeneral[10],
@@ -289,9 +269,9 @@ function printGeneralList(value: GeneralListResponse) {
strength: rawGeneral[14],
intel: rawGeneral[15],
explevel: rawGeneral[16],
experience: rawGeneral[17],
dedication: rawGeneral[18],
officerLevel: rawGeneral[19],
experienceStr: rawGeneral[17],
dedicationStr: rawGeneral[18],
officerLevelStr: rawGeneral[19],
killturn: rawGeneral[20],
connect: rawGeneral[21],
reserved: 0
@@ -325,13 +305,13 @@ function printGeneralList(value: GeneralListResponse) {
general.iconPath = getIconPath(general.imgsvr, general.picture);
general.specialDomesticWithTooltip = TemplateEngine(templateSpecial, {
text: general.special,
info: specialInfo[general.special]
text: general.specialDomestic,
info: specialInfo[general.specialDomestic]
});
general.specialWarWithTooltip = TemplateEngine(templateSpecial, {
text: general.special2,
info: specialInfo[general.special2]
text: general.specialWar,
info: specialInfo[general.specialWar]
});
general.personalWithTooltip = TemplateEngine(templateSpecial, {
@@ -438,34 +418,20 @@ $(function ($) {
}, errUnknown);
});
$('#btn_load_general_list').click(async function () {
let result: InvalidResponse | GeneralListResponse;
$('#btn_load_general_list').on('click', async function () {
try {
const response = await axios({
url: "api.php",
method: "post",
responseType: "json",
data: {
path: "Global/GeneralList",
args: {
with_token: true,
},
},
const result = await SammoAPI.Global.GeneralList({
with_token: true,
});
result = response.data;
if (!result.result) {
throw result.reason;
}
printGeneralList(result);
} catch (e) {
console.error(e);
alert(`실패했습니다: ${e}`);
return;
}
printGeneralList(result);
});
$('#btn_print_more').click(function () {
$('#btn_print_more').on('click', function () {
_printGeneralList();
})