refac: sammoAPI 정의 방식 일부 변경
- defs/index.ts로 분리 - API/Nation/GeneralList 호출 재정의
This commit is contained in:
@@ -22,24 +22,10 @@ use function sammo\increaseRefresh;
|
|||||||
|
|
||||||
class GeneralList extends \sammo\BaseAPI
|
class GeneralList extends \sammo\BaseAPI
|
||||||
{
|
{
|
||||||
|
|
||||||
private int $reqType;
|
|
||||||
private bool $reqForce;
|
|
||||||
private int $permission;
|
private int $permission;
|
||||||
|
|
||||||
public function validateArgs(): ?string
|
public function validateArgs(): ?string
|
||||||
{
|
{
|
||||||
$v = new Validator($this->args);
|
|
||||||
$v
|
|
||||||
->rule('integer', 'req')
|
|
||||||
->rule('boolean', 'force');
|
|
||||||
|
|
||||||
|
|
||||||
if (!$v->validate()) {
|
|
||||||
return $v->errorStr();
|
|
||||||
}
|
|
||||||
$this->reqType = $this->args['req'] ?? 1;
|
|
||||||
$this->reqForce = $this->args['force'] ?? false;
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,11 +60,6 @@ class GeneralList extends \sammo\BaseAPI
|
|||||||
|
|
||||||
$nationID = $me['nation'];
|
$nationID = $me['nation'];
|
||||||
$this->permission = checkSecretPermission($me, true);
|
$this->permission = checkSecretPermission($me, true);
|
||||||
if ($this->reqForce && $this->reqType > $this->permission) {
|
|
||||||
return '권한이 부족합니다.';
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->permission = min($this->reqType, $this->permission);
|
|
||||||
|
|
||||||
$nationArr = getNationStaticInfo($nationID);
|
$nationArr = getNationStaticInfo($nationID);
|
||||||
|
|
||||||
@@ -123,12 +104,19 @@ class GeneralList extends \sammo\BaseAPI
|
|||||||
'connect' => 0
|
'connect' => 0
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$columnRemap = [
|
||||||
|
'special' => 'specialDomestic',
|
||||||
|
'special2' => 'specialWar',
|
||||||
|
];
|
||||||
|
|
||||||
$customViewColumns = [
|
$customViewColumns = [
|
||||||
'officerLevel' => 0,
|
'officerLevel' => 0,
|
||||||
'officerLevelText' => 0,
|
'officerLevelText' => 0,
|
||||||
|
'specialDomesticTest' => 0,
|
||||||
|
'specialWarText' => 0,
|
||||||
'lbonus' => 0,
|
'lbonus' => 0,
|
||||||
'ownerName' => 0,
|
'ownerName' => 0,
|
||||||
'honorText' => 0
|
'honorText' => 0,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
@@ -136,10 +124,14 @@ class GeneralList extends \sammo\BaseAPI
|
|||||||
'officerLevel' => function ($rawGeneral) {
|
'officerLevel' => function ($rawGeneral) {
|
||||||
return $this->getOfficerLevel($rawGeneral);
|
return $this->getOfficerLevel($rawGeneral);
|
||||||
},
|
},
|
||||||
'special' => function ($rawGeneral) {
|
'officerLevelText' => function ($rawGeneral) use ($nationArr) {
|
||||||
|
$level = $this->getOfficerLevel($rawGeneral);
|
||||||
|
return getOfficerLevelText($level, $nationArr['level']);
|
||||||
|
},
|
||||||
|
'specialDomesticTest' => function ($rawGeneral) {
|
||||||
return getGeneralSpecialDomesticName($rawGeneral['special']);
|
return getGeneralSpecialDomesticName($rawGeneral['special']);
|
||||||
},
|
},
|
||||||
'special2' => function ($rawGeneral) {
|
'specialWarText' => function ($rawGeneral) {
|
||||||
return getGeneralSpecialWarName($rawGeneral['special2']);
|
return getGeneralSpecialWarName($rawGeneral['special2']);
|
||||||
},
|
},
|
||||||
'personal' => function ($rawGeneral) {
|
'personal' => function ($rawGeneral) {
|
||||||
@@ -154,10 +146,6 @@ class GeneralList extends \sammo\BaseAPI
|
|||||||
}
|
}
|
||||||
return $rawGeneral['owner_name'];
|
return $rawGeneral['owner_name'];
|
||||||
},
|
},
|
||||||
'officerLevelText' => function ($rawGeneral) use ($nationArr) {
|
|
||||||
$level = $this->getOfficerLevel($rawGeneral);
|
|
||||||
return getOfficerLevelText($level, $nationArr['level']);
|
|
||||||
},
|
|
||||||
'honorText' => function ($rawGeneral) {
|
'honorText' => function ($rawGeneral) {
|
||||||
return getHonor($rawGeneral['experience']);
|
return getHonor($rawGeneral['experience']);
|
||||||
},
|
},
|
||||||
@@ -180,7 +168,12 @@ class GeneralList extends \sammo\BaseAPI
|
|||||||
if ($reqPermission > $this->permission) {
|
if ($reqPermission > $this->permission) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$resultColumns[] = $column;
|
if(key_exists($column, $columnRemap)){
|
||||||
|
$resultColumns[$columnRemap[$column]] = $column;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$resultColumns[$column] = $column;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($customViewColumns as $column => $reqPermission) {
|
foreach ($customViewColumns as $column => $reqPermission) {
|
||||||
@@ -209,11 +202,11 @@ class GeneralList extends \sammo\BaseAPI
|
|||||||
|
|
||||||
$result = [
|
$result = [
|
||||||
'result' => true,
|
'result' => true,
|
||||||
'column' => $resultColumns,
|
'permission' => $this->permission,
|
||||||
|
'column' => array_keys($resultColumns),
|
||||||
'list' => $generalList,
|
'list' => $generalList,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
|
||||||
|
import type { GameObjType, ValuesOf } from "@/defs";
|
||||||
|
import type { ValidResponse } from "@/SammoAPI";
|
||||||
|
|
||||||
|
export type GeneralListItemP0 = {
|
||||||
|
no: number,
|
||||||
|
name: string,
|
||||||
|
nation: number,
|
||||||
|
npc: number,
|
||||||
|
injury: number,
|
||||||
|
leadership: number,
|
||||||
|
strength: number,
|
||||||
|
intel: number,
|
||||||
|
explevel: number,
|
||||||
|
dedlevel: number,
|
||||||
|
gold: number,
|
||||||
|
rice: number,
|
||||||
|
killturn: number,
|
||||||
|
picture: string,
|
||||||
|
imgsvr: 0 | 1,
|
||||||
|
age: number,
|
||||||
|
special: GameObjType,
|
||||||
|
special2: GameObjType,
|
||||||
|
personal: GameObjType,
|
||||||
|
belong: number,
|
||||||
|
connect: number,
|
||||||
|
|
||||||
|
officerLevel: number, //권한에따라 태수,군사,시종 노출 여부가 다름
|
||||||
|
officerLevelText: string,
|
||||||
|
lbonus: number,
|
||||||
|
ownerName: string | null, //NPC 출력용에 따라 결과가 다름
|
||||||
|
honorText: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GeneralListItemP1 = {
|
||||||
|
city: number,
|
||||||
|
experience: number,
|
||||||
|
dedication: number,
|
||||||
|
} & GeneralListItemP0;
|
||||||
|
|
||||||
|
export type GeneralListItemP2 = GeneralListItemP1 & {
|
||||||
|
officer_level: number,
|
||||||
|
officer_city: number,
|
||||||
|
|
||||||
|
}
|
||||||
|
export type GeneralListItemP9 = GeneralListItemP2 & {
|
||||||
|
owner_name: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GeneralListItem =
|
||||||
|
({permission : 0} & GeneralListItemP0) |
|
||||||
|
({permission : 1} & GeneralListItemP1) |
|
||||||
|
({permission : 2} & GeneralListItemP2) |
|
||||||
|
({permission : 9} & GeneralListItemP9);
|
||||||
|
|
||||||
|
|
||||||
|
export type RawGeneralListP0 = ValidResponse & {
|
||||||
|
permission: 0,
|
||||||
|
column: keyof GeneralListItemP0[],
|
||||||
|
list: ValuesOf<GeneralListItemP0>[],
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RawGeneralListP1 = ValidResponse & {
|
||||||
|
permission: 1,
|
||||||
|
column: keyof GeneralListItemP1[],
|
||||||
|
list: ValuesOf<GeneralListItemP1>[][],
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RawGeneralListP2 = ValidResponse & {
|
||||||
|
permission: 2,
|
||||||
|
column: keyof GeneralListItemP2[],
|
||||||
|
list: ValuesOf<GeneralListItemP2>[][],
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RawGeneralListP9 = ValidResponse & {
|
||||||
|
permission: 9,
|
||||||
|
column: keyof GeneralListItemP9[],
|
||||||
|
list: ValuesOf<GeneralListItemP9>[][],
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GeneralListResponse = RawGeneralListP0 | RawGeneralListP1 | RawGeneralListP2 | RawGeneralListP9;
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
import type { ValuesOf } from "@/defs";
|
||||||
|
import { zip } from "lodash";
|
||||||
|
|
||||||
|
export function merge2DArrToObjectArr<T extends Record<string, unknown>>(column: (keyof T)[], list: ValuesOf<T>[][]): T[]{
|
||||||
|
const result: T[] = [];
|
||||||
|
for(const rawItem of list){
|
||||||
|
const item: Record<string, unknown> = {};
|
||||||
|
|
||||||
|
if(column.length != item.length){
|
||||||
|
throw `column과 item의 길이가 같지 않습니다: ${column.length} != ${list.length}, ${JSON.stringify(item)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(const [key, value] of zip(column, rawItem)){
|
||||||
|
item[key as string] = value;
|
||||||
|
}
|
||||||
|
result.push(item as T);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user