feat: GlobalMenu API
- GlobalMenu 작성용 DTO(MenuItem, MenuMulti, MenuSplit) - d_setting에 GlobalMenu를 직접 작성 가능하도록 제공
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace sammo;
|
||||
|
||||
use sammo\DTO\MenuItem;
|
||||
use sammo\DTO\MenuMulti;
|
||||
use sammo\DTO\MenuSplit;
|
||||
|
||||
//변경을 원한다면 파일을 복제 후 수정
|
||||
|
||||
class GlobalMenu {
|
||||
/** @var (MenuItem|MenuMulti|MenuSplit)[] */
|
||||
|
||||
const version = 3;
|
||||
static ?array $menu = null;
|
||||
public static function getMenu(): array{
|
||||
if(static::$menu !== null){
|
||||
return static::$menu;
|
||||
}
|
||||
static::$menu = [
|
||||
new MenuItem('천통국 베팅', 'v_nationBetting.php', condHighlightVar: 'nationBetting'),
|
||||
new MenuMulti([
|
||||
new MenuItem('세력일람', 'a_kingdomList.php', newTab: true),
|
||||
new MenuItem('장수일람', 'a_genList.php', newTab: true),
|
||||
new MenuItem('명장일람', 'a_bestGeneral.php', newTab: true),
|
||||
new MenuItem('명예의전당', 'a_hallOfFame.php', newTab: true),
|
||||
new MenuItem('왕조일람', 'a_emperior.php', newTab: true),
|
||||
]),
|
||||
new MenuItem('연감', 'v_history.php', newTab: true),
|
||||
new MenuSplit(
|
||||
new MenuItem('게시판', '/board/community', newTab: true),
|
||||
[
|
||||
new MenuItem('건의/제안', '/board/request', newTab: true),
|
||||
new MenuItem('팁/강좌', '/board/tip', newTab: true),
|
||||
new MenuItem('패치 내역', '/board/patch', newTab: true),
|
||||
]
|
||||
),
|
||||
new MenuSplit(
|
||||
new MenuItem('공식 오픈 톡', 'https://open.kakao.com/o/', newTab: true),
|
||||
[
|
||||
new MenuItem('잡담 오픈 톡', 'https://open.kakao.com/o/', newTab: true)
|
||||
],
|
||||
),
|
||||
new MenuItem('전투 시뮬레이터', 'battle_simulator.php', newTab: true),
|
||||
new MenuMulti([
|
||||
new MenuItem('접속량정보', 'a_traffic.php', newTab: true),
|
||||
new MenuItem('빙의일람', 'a_npcList', newTab: true, condShowVar: 'npcMode'),
|
||||
]),
|
||||
new MenuItem('설문조사', 'v_vote.php', newTab: true, condHighlightVar: 'vote'),
|
||||
];
|
||||
return static::$menu;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\API\Global;
|
||||
|
||||
use LDTO\DTO;
|
||||
use sammo\APICacheResult;
|
||||
use sammo\BaseAPI;
|
||||
use sammo\GlobalMenu;
|
||||
use sammo\Session;
|
||||
|
||||
class GetGlobalMenu extends BaseAPI
|
||||
{
|
||||
public function getRequiredSessionMode(): int
|
||||
{
|
||||
return self::NO_SESSION;
|
||||
}
|
||||
function validateArgs(): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
function launch(Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||
{
|
||||
if ($reqEtag !== null) {
|
||||
$version = GlobalMenu::version;
|
||||
if ($reqEtag == "v{$version}") {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return [
|
||||
'result' => true,
|
||||
'menu' => array_map(function (DTO $dto) {
|
||||
return $dto->toArray();
|
||||
}, GlobalMenu::getMenu()),
|
||||
];
|
||||
}
|
||||
public function tryCache(): ?APICacheResult
|
||||
{
|
||||
$version = GlobalMenu::version;
|
||||
return new APICacheResult(
|
||||
null,
|
||||
"v{$version}",
|
||||
60 * 60 * 6,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\DTO;
|
||||
|
||||
use LDTO\Attr\NullIsUndefined;
|
||||
use LDTO\DTO;
|
||||
|
||||
class MenuItem extends DTO{
|
||||
public readonly string $type;
|
||||
|
||||
public function __construct(
|
||||
public readonly string $name,
|
||||
public readonly string $url,
|
||||
|
||||
#[NullIsUndefined]
|
||||
public ?string $icon = null,
|
||||
#[NullIsUndefined]
|
||||
public ?bool $newTab = false,
|
||||
#[NullIsUndefined]
|
||||
public ?string $condHighlightVar = null,
|
||||
#[NullIsUndefined]
|
||||
public ?string $condShowVar = null,
|
||||
){
|
||||
$this->type = 'item';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\DTO;
|
||||
|
||||
use LDTO\Attr\Convert;
|
||||
use LDTO\DTO;
|
||||
use LDTO\Converter\ArrayConverter;
|
||||
|
||||
class MenuMulti extends DTO{
|
||||
public readonly string $type;
|
||||
|
||||
/** @param MenuItem[] $subMenu */
|
||||
public function __construct(
|
||||
#[Convert(ArrayConverter::class, [DTO::class])]
|
||||
public array $subMenu,
|
||||
){
|
||||
$this->type = 'multi';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\DTO;
|
||||
|
||||
use LDTO\Attr\Convert;
|
||||
use LDTO\Converter\ArrayConverter;
|
||||
use LDTO\DTO;
|
||||
|
||||
class MenuSplit extends DTO{
|
||||
public readonly string $type;
|
||||
|
||||
/** @param MenuItem[] $subMenu */
|
||||
public function __construct(
|
||||
public MenuItem $main,
|
||||
#[Convert(ArrayConverter::class, [DTO::class])]
|
||||
public array $subMenu,
|
||||
){
|
||||
$this->type = 'split';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace sammo;
|
||||
|
||||
use sammo\DTO\MenuItem;
|
||||
use sammo\DTO\MenuMulti;
|
||||
use sammo\DTO\MenuSplit;
|
||||
|
||||
//변경을 원한다면 d_setting/GlobalMenu.orig.php 파일을 복제 후 수정
|
||||
|
||||
class GlobalMenu {
|
||||
/** @var (MenuItem|MenuMulti|MenuSplit)[] */
|
||||
|
||||
const version = 1;
|
||||
static ?array $menu = null;
|
||||
public static function getMenu(): array{
|
||||
if(static::$menu !== null){
|
||||
return static::$menu;
|
||||
}
|
||||
static::$menu = [
|
||||
new MenuItem('천통국 베팅', 'v_nationBetting.php', condHighlightVar: 'nationBetting'),
|
||||
new MenuMulti([
|
||||
new MenuItem('세력일람', 'a_kingdomList.php', newTab: true),
|
||||
new MenuItem('장수일람', 'a_genList.php', newTab: true),
|
||||
new MenuItem('명장일람', 'a_bestGeneral.php', newTab: true),
|
||||
new MenuItem('명예의전당', 'a_hallOfFame.php', newTab: true),
|
||||
new MenuItem('왕조일람', 'a_emperior.php', newTab: true),
|
||||
]),
|
||||
new MenuItem('연감', 'v_history.php', newTab: true),
|
||||
new MenuSplit(
|
||||
new MenuItem('게시판', '/board/community', newTab: true),
|
||||
[
|
||||
new MenuItem('건의/제안', '/board/request', newTab: true),
|
||||
new MenuItem('팁/강좌', '/board/tip', newTab: true),
|
||||
new MenuItem('패치 내역', '/board/patch', newTab: true),
|
||||
]
|
||||
),
|
||||
new MenuSplit(
|
||||
new MenuItem('공식 오픈 톡', 'https://open.kakao.com/o/', newTab: true),
|
||||
[
|
||||
new MenuItem('잡담 오픈 톡', 'https://open.kakao.com/o/', newTab: true)
|
||||
],
|
||||
),
|
||||
new MenuItem('전투 시뮬레이터', 'battle_simulator.php', newTab: true),
|
||||
new MenuMulti([
|
||||
new MenuItem('접속량정보', 'a_traffic.php', newTab: true),
|
||||
new MenuItem('빙의일람', 'a_npcList', newTab: true, condShowVar: 'npcMode'),
|
||||
]),
|
||||
new MenuItem('설문조사', 'v_vote.php', newTab: true, condHighlightVar: 'vote'),
|
||||
];
|
||||
return static::$menu;
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import type {
|
||||
GetDiplomacyResponse,
|
||||
GetFrontInfoResponse,
|
||||
GetHistoryResponse,
|
||||
GetMenuResponse,
|
||||
GetRecentRecordResponse,
|
||||
} from "./defs/API/Global";
|
||||
import type { CachedMapResult, CommandTableResponse, GeneralListResponse, ItemTypeKey, MapResult } from "./defs";
|
||||
@@ -158,6 +159,7 @@ const apiRealPath = {
|
||||
lastGeneralRecordID: number;
|
||||
lastWorldHistoryID: number;
|
||||
} | undefined, GetRecentRecordResponse>,
|
||||
GetGlobalMenu: GET as APICallT<undefined, GetMenuResponse>,
|
||||
},
|
||||
InheritAction: {
|
||||
BuyHiddenBuff: PUT as APICallT<{
|
||||
|
||||
@@ -218,3 +218,29 @@ export type GetFrontInfoResponse = {
|
||||
>;
|
||||
};
|
||||
};
|
||||
|
||||
export type MenuItem = {
|
||||
type: 'item';
|
||||
name: string;
|
||||
url: string;
|
||||
icon?: string;
|
||||
newTab?: boolean;
|
||||
condHightlightVar?: string;
|
||||
condShowVar?: string;
|
||||
}
|
||||
|
||||
export type MenuSplit = {
|
||||
type: 'split';
|
||||
main: MenuItem;
|
||||
subMenu: MenuItem[];
|
||||
}
|
||||
|
||||
export type MenuMulti = {
|
||||
type: 'multi';
|
||||
subMenu: MenuItem[];
|
||||
}
|
||||
|
||||
export type GetMenuResponse = {
|
||||
result: true;
|
||||
menu: (MenuItem | MenuSplit | MenuMulti)[];
|
||||
}
|
||||
Reference in New Issue
Block a user