diff --git a/hwe/ts/SammoAPI.ts b/hwe/ts/SammoAPI.ts index ebad9a55..927720e6 100644 --- a/hwe/ts/SammoAPI.ts +++ b/hwe/ts/SammoAPI.ts @@ -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, }, Global: { + GeneralList: GET as APICallT<{ + with_token?: boolean + }, GeneralListResponse>, GetConst: GET as APICallT, }, InheritAction: { diff --git a/hwe/ts/defs/index.ts b/hwe/ts/defs/index.ts index 36527788..d7b8b0bf 100644 --- a/hwe/ts/defs/index.ts +++ b/hwe/ts/defs/index.ts @@ -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, + token?: Record, } export type NationLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7; diff --git a/hwe/ts/select_npc.ts b/hwe/ts/select_npc.ts index dfea1e56..c3d13e47 100644 --- a/hwe/ts/select_npc.ts +++ b/hwe/ts/select_npc.ts @@ -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(); })