feat: 연감을 가져오는 API

- Global/GetHistory - 과거 기록. 캐싱 가능
- GetCurrentHistory - 현재 기록. 캐싱 불가
This commit is contained in:
2022-04-18 03:05:08 +09:00
parent eadbc774e3
commit c379ecf317
7 changed files with 289 additions and 23 deletions
+7 -2
View File
@@ -4,7 +4,7 @@ import {
type APITail, type APICallT, type RawArgType, type ValidResponse, type InvalidResponse
} from "./util/callSammoAPI";
export type { ValidResponse, InvalidResponse };
import { APIPathGen, NumVar } from "./util/APIPathGen.js";
import { APIPathGen, NumVar, StrVar } from "./util/APIPathGen.js";
import type { BettingDetailResponse, BettingListResponse } from "./defs/API/Betting";
import type { ReserveBulkCommandResponse, ReserveCommandResponse, ReservedCommandResponse } from "./defs/API/Command";
import type { ChiefResponse } from "./defs/API/NationCommand";
@@ -12,7 +12,7 @@ import type { inheritBuffType } from "./defs/API/InheritAction";
import type { SetBlockWarResponse, GeneralListResponse as NationGeneralListResponse } 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 { GetConstResponse, GetCurrentHistoryResponse, GetHistoryResponse } from "./defs/API/Global";
import type { GeneralListResponse } from "./defs";
const apiRealPath = {
@@ -54,6 +54,11 @@ const apiRealPath = {
with_token?: boolean
}, GeneralListResponse>,
GetConst: GET as APICallT<undefined, GetConstResponse>,
GetHistory: StrVar('serverID')(
NumVar('year',
NumVar('month', GET as APICallT<undefined, GetHistoryResponse>
))),
GetCurrentHistory: GET as APICallT<undefined, GetCurrentHistoryResponse>
},
InheritAction: {
BuyHiddenBuff: PUT as APICallT<{
+34
View File
@@ -1,4 +1,5 @@
import type { CityID, CrewTypeID, GameCityDefault, GameConstType, GameUnitType, GameIActionKey, GameIActionCategory, GameIActionInfo } from "@/defs/GameObj";
import type { MapResult } from "@/defs";
export interface GetConstResponse {
result: true;
@@ -33,4 +34,37 @@ export interface GetConstResponse {
allItems: "item";
};
};
}
export type HistoryObj = {
server_id: string,
year: number;
month: number;
map: MapResult,
global_history: string[],
global_action: string[],
nations: {
capital: number,
cities: string[],
color: string,
gennum: number,
level: number,
name: string,
nation: number,
power: number,
type: GameIActionKey
}[],
}
export type GetHistoryResponse = {
result: true;
data: HistoryObj & {
hash: string;
//no: number,
};
}
export type GetCurrentHistoryResponse = {
result: true;
data: HistoryObj;
}
+19
View File
@@ -228,4 +228,23 @@ export const diplomacyStateInfo: Record<diplomacyState, diplomacyInfo> = {
1: { name: '선포중', color: 'magenta' },
2: { name: '통상' },
7: { name: '불가침', color: 'green' },
}
//Map
type MapCityCompact = [number, number, number, number, number, number];
type MapNationCompact = [number, string, string, number];
export type MapResult = {
result: true,
startYear: number,
year: number,
month: number,
cityList: MapCityCompact[],
nationList: MapNationCompact[],
spyList: Record<number, number>,
shownByGeneralList: number[],
myCity?: number,
myNation?: number,
theme?: string,
history?: string[],
}
+3 -21
View File
@@ -2,7 +2,7 @@ import axios from 'axios';
import $ from 'jquery';
import { isNumber, merge } from 'lodash';
import { convColorValue, convertDictById, stringFormat } from '@/common_legacy';
import type { InvalidResponse } from '@/defs';
import type { InvalidResponse, MapResult } from '@/defs';
import { unwrap } from "@util/unwrap";
import { convertFormData } from '@util/convertFormData';
import { exportWindow } from '@util/exportWindow';
@@ -28,9 +28,6 @@ declare global {
}
}
type MapCityCompact = [number, number, number, number, number, number];
type MapNationCompact = [number, string, string, number];
type MapCityParsedRaw = {
id: number,
level: number,
@@ -77,21 +74,6 @@ type MapNationParsed = {
capital: number
}
type MapResult = {
result: true,
startYear: number,
year: number,
month: number,
cityList: MapCityCompact[],
nationList: MapNationCompact[],
spyList: Record<number, number>,
shownByGeneralList: number[],
myCity?: number,
myNation?: number,
theme?: string,
history?: string[],
}
type MapRawResult = InvalidResponse | MapResult;
function is_touch_device(): boolean {
@@ -285,7 +267,7 @@ export async function reloadWorldMap(option: loadMapOption, drawTarget = '.world
async function convertCityObjs(obj: MapResult): Promise<MapCityDrawable> {
//원본 Obj는 굉장히 간소하게 온다, Object 형태로 변환해서 사용한다.
function toCityObj([id, level, state, nationID, region, supply]: MapCityCompact): MapCityParsedRaw {
function toCityObj([id, level, state, nationID, region, supply]: MapResult['cityList'][0]): MapCityParsedRaw {
return {
id: id,
level: level,
@@ -296,7 +278,7 @@ export async function reloadWorldMap(option: loadMapOption, drawTarget = '.world
};
}
function toNationObj([id, name, color, capital]: MapNationCompact): MapNationParsed {
function toNationObj([id, name, color, capital]: MapResult['nationList'][0]): MapNationParsed {
return {
id,
name,