From 43a95979e1181eb0412192f10c82c68d6a65cbd6 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sat, 16 Jul 2022 15:49:23 +0900 Subject: [PATCH] =?UTF-8?q?refac:=20=EA=B0=90=EC=B0=B0=EB=B6=80=20vue3=20?= =?UTF-8?q?=EC=9E=AC=20=EC=9E=91=EC=84=B1=20(#222)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 장수 정보, 추가 정보 vue3 component - b_battleCenter -> v_battleCenter Reviewed-on: https://storage.hided.net/gitea/devsam/core/pulls/222 --- hwe/func_history.php | 10 + hwe/sammo/API/General/GetGeneralLog.php | 4 +- hwe/sammo/API/Nation/GetGeneralLog.php | 15 +- hwe/sammo/API/Nation/GetNationInfo.php | 104 +++++++++ hwe/scss/battleLog.scss | 33 +++ hwe/templates/commandButton.php | 2 +- hwe/ts/PageBattleCenter.vue | 237 ++++++++++++++++++++ hwe/ts/PageNationGeneral.vue | 2 +- hwe/ts/SammoAPI.ts | 3 +- hwe/ts/build_exports.json | 1 + hwe/ts/components/GeneralBasicCard.vue | 93 +++++--- hwe/ts/components/GeneralSupplementCard.vue | 94 +++++--- hwe/ts/components/SammoBar.vue | 30 ++- hwe/ts/defs/API/Nation.ts | 28 ++- hwe/ts/v_battleCenter.ts | 20 ++ hwe/v_battleCenter.php | 43 ++++ 16 files changed, 632 insertions(+), 87 deletions(-) create mode 100644 hwe/sammo/API/Nation/GetNationInfo.php create mode 100644 hwe/scss/battleLog.scss create mode 100644 hwe/ts/PageBattleCenter.vue create mode 100644 hwe/ts/v_battleCenter.ts create mode 100644 hwe/v_battleCenter.php diff --git a/hwe/func_history.php b/hwe/func_history.php index 687e9e52..10ddbc07 100644 --- a/hwe/func_history.php +++ b/hwe/func_history.php @@ -254,6 +254,7 @@ function pushGeneralHistoryLog(int $generalID, ?array $history, $year=null, $mon } +/** @deprecated */ function getGeneralHistoryLogAll(int $generalID):array { $db = DB::db(); @@ -263,6 +264,15 @@ function getGeneralHistoryLogAll(int $generalID):array { ); } +function getGeneralHistoryLogWithLogID(int $generalID):array { + $db = DB::db(); + + return Util::convertPairArrayToDict($db->queryAllLists( + 'SELECT `id`, `text` from general_record WHERE general_id = %i AND log_type = "history" order by id desc', + $generalID + )); +} + function pushNationHistoryLog(int $nationID, ?array $history, ?int $year=null, ?int $month=null) { if(!$history){ diff --git a/hwe/sammo/API/General/GetGeneralLog.php b/hwe/sammo/API/General/GetGeneralLog.php index 4edbe965..2cbf2db3 100644 --- a/hwe/sammo/API/General/GetGeneralLog.php +++ b/hwe/sammo/API/General/GetGeneralLog.php @@ -18,12 +18,12 @@ class GetGeneralLog extends GetNationGeneralLog $v = new Validator($this->args); $v ->rule('required', [ - 'type', + 'reqType', ]) ->rule('int', [ 'reqTo', ]) - ->rule('in', 'type', [ + ->rule('in', 'reqType', [ self::GENERAL_HISTORY, self::GENERAL_ACTION, self::BATTLE_RESULT, diff --git a/hwe/sammo/API/Nation/GetGeneralLog.php b/hwe/sammo/API/Nation/GetGeneralLog.php index 857d0b61..7b1aa603 100644 --- a/hwe/sammo/API/Nation/GetGeneralLog.php +++ b/hwe/sammo/API/Nation/GetGeneralLog.php @@ -9,11 +9,12 @@ use sammo\Validator; use function sammo\checkLimit; use function sammo\checkSecretPermission; use function sammo\getBattleDetailLogMore; +use function sammo\getBattleDetailLogRecent; use function sammo\getBattleResultMore; use function sammo\getBattleResultRecent; use function sammo\getGeneralActionLogMore; use function sammo\getGeneralActionLogRecent; -use function sammo\getGeneralHistoryLogAll; +use function sammo\getGeneralHistoryLogWithLogID; class GetGeneralLog extends \sammo\BaseAPI { @@ -28,13 +29,13 @@ class GetGeneralLog extends \sammo\BaseAPI $v ->rule('required', [ 'generalID', - 'type', + 'reqType', ]) ->rule('integer', [ 'generalID', 'reqTo', ]) - ->rule('in', 'type', [ + ->rule('in', 'reqType', [ self::GENERAL_HISTORY, self::GENERAL_ACTION, self::BATTLE_RESULT, @@ -76,7 +77,7 @@ class GetGeneralLog extends \sammo\BaseAPI return '같은 나라의 장수가 아닙니다.'; } - $reqType = $this->args['type']; + $reqType = $this->args['reqType']; if ( $reqType === self::GENERAL_ACTION && $testGeneralNPCType < 2 && @@ -103,7 +104,7 @@ class GetGeneralLog extends \sammo\BaseAPI $userID = $session->userID; $targetGeneralID = $this->getTargetGeneralID($session); - $reqType = $this->args['type']; + $reqType = $this->args['reqType']; $reqTo = $this->args['reqTo'] ?? null; $db = DB::db(); @@ -124,7 +125,7 @@ class GetGeneralLog extends \sammo\BaseAPI 'result' => true, 'reqType' => $reqType, 'generalID' => $targetGeneralID, - 'log' => getGeneralHistoryLogAll($targetGeneralID) + 'log' => getGeneralHistoryLogWithLogID($targetGeneralID) ]; } @@ -156,7 +157,7 @@ class GetGeneralLog extends \sammo\BaseAPI 'reqType' => $reqType, 'generalID' => $targetGeneralID, 'log' => $reqTo === null - ? getBattleResultRecent($targetGeneralID, 30) + ? getBattleDetailLogRecent($targetGeneralID, 30) : getBattleDetailLogMore($targetGeneralID, $reqTo, 30) ]; } diff --git a/hwe/sammo/API/Nation/GetNationInfo.php b/hwe/sammo/API/Nation/GetNationInfo.php new file mode 100644 index 00000000..fe0c2fd0 --- /dev/null +++ b/hwe/sammo/API/Nation/GetNationInfo.php @@ -0,0 +1,104 @@ +args); + $v->rule('boolean', 'full'); + + if (!$v->validate()) { + return $v->errorStr(); + } + return null; + } + + public function getRequiredSessionMode(): int + { + return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY; + } + + public function launch(Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag) + { + $userID = $session->userID; + + $db = DB::db(); + $nationID = $db->queryFirstField('SELECT nation FROM general WHERE `owner` = %i', $userID); + + if (!$nationID) { + return [ + 'result' => true, + 'nation' => getNationStaticInfo(0) + ]; + } + + $isFull = $this->args['full'] ?? false; + + if(!$isFull){ + $nation = getNationStaticInfo($nationID); + return [ + 'result' => true, + 'nation' => $nation, + ]; + } + + $generalObj = General::createGeneralObjFromDB($session->generalID, null, 1); + + $gameStor = KVStorage::getStorage($db, 'game_env'); + $gameEnv = $gameStor->getValues(['year', 'month', 'startyear']); + + $nation = $db->queryFirstRow( + 'SELECT nation, `name`, color, capital, gennum, gold, rice, bill, rate, secretlimit, chief_set, scout, war, strategic_cmd_limit, surlimit, tech, `power`, `level`, `type` FROM nation WHERE id = %i', + $nationID + ); + $nationStor = \sammo\KVStorage::getStorage($db, $nationID, 'nation_env'); + $nationStor->cacheAll(); + + + //전략 정보를 매번 읽어와야하나? + $impossibleStrategicCommandLists = []; + $strategicCommandLists = GameConst::$availableChiefCommand['전략']; + $yearMonth = Util::joinYearMonth($gameEnv['year'], $gameEnv['month']); + foreach ($strategicCommandLists as $command) { + $cmd = buildNationCommandClass($command, $generalObj, $gameEnv, new LastTurn()); + $nextAvailableTurn = $cmd->getNextAvailableTurn(); + if ($nextAvailableTurn > $yearMonth) { + $impossibleStrategicCommandLists[] = [$cmd->getName(), $nextAvailableTurn - $yearMonth]; + } + } + + $troopName = []; + foreach ($db->queryAllLists('SELECT troop_leader, name FROM troop WHERE nation=%i', $nationID) as [$troopID, $tName]) { + $troopName[$troopID] = $tName; + } + + return [ + 'result' => true, + 'nation' => $nation, + 'impossibleStrategicCommandLists' => $impossibleStrategicCommandLists, + 'troops' => $troopName, + ]; + } +} diff --git a/hwe/scss/battleLog.scss b/hwe/scss/battleLog.scss new file mode 100644 index 00000000..8961a66c --- /dev/null +++ b/hwe/scss/battleLog.scss @@ -0,0 +1,33 @@ +.small_war_log { + display: inline-block; +} + +.small_war_log .war_type_attack { + color: cyan; +} + +.small_war_log .war_type_defense { + color: magenta; +} + +.small_war_log .war_type_siege { + color: white; +} + +.small_war_log .name_plate { + font-size: 0.75em; +} + +.small_war_log .name_plate_cover { + color: yellow; +} + +.small_war_log .crew_plate { + color: orangered; + font-size: 90%; +} + +.hidden_but_copyable { + color: rgba(0, 0, 0, 0); + font-size: 0; +} \ No newline at end of file diff --git a/hwe/templates/commandButton.php b/hwe/templates/commandButton.php index 2fc26597..29c513c7 100644 --- a/hwe/templates/commandButton.php +++ b/hwe/templates/commandButton.php @@ -13,7 +13,7 @@ '>세력 장수 중원 정보 현재 도시 -'>감 찰 부 +'>감 찰 부 유산 관리 내 정보&설정 diff --git a/hwe/ts/PageBattleCenter.vue b/hwe/ts/PageBattleCenter.vue new file mode 100644 index 00000000..b3849b61 --- /dev/null +++ b/hwe/ts/PageBattleCenter.vue @@ -0,0 +1,237 @@ + + + + + diff --git a/hwe/ts/PageNationGeneral.vue b/hwe/ts/PageNationGeneral.vue index 3c755198..4b528870 100644 --- a/hwe/ts/PageNationGeneral.vue +++ b/hwe/ts/PageNationGeneral.vue @@ -97,7 +97,7 @@ async function reload() { } function openBattleCenter(generalID: number){ - window.open(`b_battleCenter.php?gen=${generalID}`) + window.open(`v_battleCenter.php?gen=${generalID}`) } onMounted(async () => { diff --git a/hwe/ts/SammoAPI.ts b/hwe/ts/SammoAPI.ts index bf6e3a48..bf926c51 100644 --- a/hwe/ts/SammoAPI.ts +++ b/hwe/ts/SammoAPI.ts @@ -18,7 +18,7 @@ import type { BettingDetailResponse, BettingListResponse } from "./defs/API/Bett import type { ReserveBulkCommandResponse, ReserveCommandResponse, ReservedCommandResponse } from "./defs/API/Command"; import type { ChiefResponse } from "./defs/API/NationCommand"; import type { inheritBuffType, InheritLogResponse } from "./defs/API/InheritAction"; -import type { SetBlockWarResponse, GeneralListResponse as NationGeneralListResponse } from "./defs/API/Nation"; +import type { SetBlockWarResponse, GeneralListResponse as NationGeneralListResponse, NationInfoResponse } from "./defs/API/Nation"; import type { UploadImageResponse } from "./defs/API/Misc"; import type { GeneralLogType, GetGeneralLogResponse, JoinArgs } from "./defs/API/General"; import type { @@ -231,6 +231,7 @@ const apiRealPath = { troopID: number; troopName: string; }>, + GetNationInfo: GET as APICallT<{full?: boolean}, NationInfoResponse>, }, Vote: { AddComment: POST as APICallT<{ diff --git a/hwe/ts/build_exports.json b/hwe/ts/build_exports.json index 20065ecc..51550860 100644 --- a/hwe/ts/build_exports.json +++ b/hwe/ts/build_exports.json @@ -23,6 +23,7 @@ }, "ingame_vue": { "v_auction": "v_auction.ts", + "v_battleCenter": "v_battleCenter.ts", "v_inheritPoint": "v_inheritPoint.ts", "v_board": "v_board.ts", "v_cachedMap": "v_cachedMap", diff --git a/hwe/ts/components/GeneralBasicCard.vue b/hwe/ts/components/GeneralBasicCard.vue index d4304ae2..a0438ee9 100644 --- a/hwe/ts/components/GeneralBasicCard.vue +++ b/hwe/ts/components/GeneralBasicCard.vue @@ -1,5 +1,5 @@