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
|
||||
{
|
||||
|
||||
private int $reqType;
|
||||
private bool $reqForce;
|
||||
private int $permission;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -74,11 +60,6 @@ class GeneralList extends \sammo\BaseAPI
|
||||
|
||||
$nationID = $me['nation'];
|
||||
$this->permission = checkSecretPermission($me, true);
|
||||
if ($this->reqForce && $this->reqType > $this->permission) {
|
||||
return '권한이 부족합니다.';
|
||||
}
|
||||
|
||||
$this->permission = min($this->reqType, $this->permission);
|
||||
|
||||
$nationArr = getNationStaticInfo($nationID);
|
||||
|
||||
@@ -123,12 +104,19 @@ class GeneralList extends \sammo\BaseAPI
|
||||
'connect' => 0
|
||||
];
|
||||
|
||||
$columnRemap = [
|
||||
'special' => 'specialDomestic',
|
||||
'special2' => 'specialWar',
|
||||
];
|
||||
|
||||
$customViewColumns = [
|
||||
'officerLevel' => 0,
|
||||
'officerLevelText' => 0,
|
||||
'specialDomesticTest' => 0,
|
||||
'specialWarText' => 0,
|
||||
'lbonus' => 0,
|
||||
'ownerName' => 0,
|
||||
'honorText' => 0
|
||||
'honorText' => 0,
|
||||
];
|
||||
|
||||
|
||||
@@ -136,10 +124,14 @@ class GeneralList extends \sammo\BaseAPI
|
||||
'officerLevel' => function ($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']);
|
||||
},
|
||||
'special2' => function ($rawGeneral) {
|
||||
'specialWarText' => function ($rawGeneral) {
|
||||
return getGeneralSpecialWarName($rawGeneral['special2']);
|
||||
},
|
||||
'personal' => function ($rawGeneral) {
|
||||
@@ -154,10 +146,6 @@ class GeneralList extends \sammo\BaseAPI
|
||||
}
|
||||
return $rawGeneral['owner_name'];
|
||||
},
|
||||
'officerLevelText' => function ($rawGeneral) use ($nationArr) {
|
||||
$level = $this->getOfficerLevel($rawGeneral);
|
||||
return getOfficerLevelText($level, $nationArr['level']);
|
||||
},
|
||||
'honorText' => function ($rawGeneral) {
|
||||
return getHonor($rawGeneral['experience']);
|
||||
},
|
||||
@@ -180,7 +168,12 @@ class GeneralList extends \sammo\BaseAPI
|
||||
if ($reqPermission > $this->permission) {
|
||||
continue;
|
||||
}
|
||||
$resultColumns[] = $column;
|
||||
if(key_exists($column, $columnRemap)){
|
||||
$resultColumns[$columnRemap[$column]] = $column;
|
||||
}
|
||||
else{
|
||||
$resultColumns[$column] = $column;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($customViewColumns as $column => $reqPermission) {
|
||||
@@ -209,11 +202,11 @@ class GeneralList extends \sammo\BaseAPI
|
||||
|
||||
$result = [
|
||||
'result' => true,
|
||||
'column' => $resultColumns,
|
||||
'permission' => $this->permission,
|
||||
'column' => array_keys($resultColumns),
|
||||
'list' => $generalList,
|
||||
];
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user