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