From d910158a2a35dcc147e9597caffdb8edcc3979b5 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 10 Nov 2024 22:12:05 +0000 Subject: [PATCH 1/3] user rank and max rank on overview adds user and max rank on overview --- app/Http/Controllers/OverviewController.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/OverviewController.php b/app/Http/Controllers/OverviewController.php index 882534ea..0aa05795 100644 --- a/app/Http/Controllers/OverviewController.php +++ b/app/Http/Controllers/OverviewController.php @@ -2,10 +2,12 @@ namespace OGame\Http\Controllers; +use Cache; use Exception; use Illuminate\Support\Carbon; use Illuminate\View\View; use OGame\Facades\AppUtil; +use OGame\Models\Highscore; use OGame\Services\BuildingQueueService; use OGame\Services\HighscoreService; use OGame\Services\PlayerService; @@ -54,6 +56,14 @@ public function index(PlayerService $player, BuildingQueueService $building_queu $highscoreService = resolve(HighscoreService::class); + $user_rank = Cache::remember('player-rank-'.$player->getId(), now()->addMinutes(5), function () use ($highscoreService, $player) { + return $highscoreService->getHighscorePlayerRank($player); + }); + + $max_ranks = Cache::remember('highscore-player-count', now()->addMinutes(5), function () { + return Highscore::query()->validRanks()->count(); + }); + return view('ingame.overview.index')->with([ 'header_filename' => $player->planets->current()->getPlanetType(), 'planet_name' => $player->planets->current()->getPlanetName(), @@ -62,8 +72,8 @@ public function index(PlayerService $player, BuildingQueueService $building_queu 'planet_temp_max' => $player->planets->current()->getPlanetTempMax(), 'planet_coordinates' => $player->planets->current()->getPlanetCoordinates()->asString(), 'user_points' => AppUtil::formatNumber($highscoreService->getPlayerScore($player)), - 'user_rank' => 0, // @TODO - 'max_rank' => 0, // @TODO + 'user_rank' => $user_rank, + 'max_rank' => $max_ranks, // @TODO 'user_honor_points' => 0, // @TODO 'build_active' => $build_active, 'building_count' => $player->planets->current()->getBuildingCount(), From e176c535f852bf8ca5d726b176817919ed4a7c12 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 10 Nov 2024 22:12:22 +0000 Subject: [PATCH 2/3] remove todo --- app/Http/Controllers/OverviewController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/OverviewController.php b/app/Http/Controllers/OverviewController.php index 0aa05795..28c147c5 100644 --- a/app/Http/Controllers/OverviewController.php +++ b/app/Http/Controllers/OverviewController.php @@ -73,7 +73,7 @@ public function index(PlayerService $player, BuildingQueueService $building_queu 'planet_coordinates' => $player->planets->current()->getPlanetCoordinates()->asString(), 'user_points' => AppUtil::formatNumber($highscoreService->getPlayerScore($player)), 'user_rank' => $user_rank, - 'max_rank' => $max_ranks, // @TODO + 'max_rank' => $max_ranks, 'user_honor_points' => 0, // @TODO 'build_active' => $build_active, 'building_count' => $player->planets->current()->getBuildingCount(), From ce49966f93a276f81a7a29d6080f535d79677b10 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 10 Nov 2024 22:25:08 +0000 Subject: [PATCH 3/3] score addition --- app/Http/Controllers/OverviewController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/OverviewController.php b/app/Http/Controllers/OverviewController.php index 28c147c5..09b7e8b2 100644 --- a/app/Http/Controllers/OverviewController.php +++ b/app/Http/Controllers/OverviewController.php @@ -64,6 +64,10 @@ public function index(PlayerService $player, BuildingQueueService $building_queu return Highscore::query()->validRanks()->count(); }); + $user_score = Cache::remember('player-score-'.$player->getId(), now()->addMinutes(5), function () use ($player) { + return AppUtil::formatNumber(Highscore::where('player_id', $player->getId())->first()->general ?? 0); + }); + return view('ingame.overview.index')->with([ 'header_filename' => $player->planets->current()->getPlanetType(), 'planet_name' => $player->planets->current()->getPlanetName(), @@ -71,7 +75,7 @@ public function index(PlayerService $player, BuildingQueueService $building_queu 'planet_temp_min' => $player->planets->current()->getPlanetTempMin(), 'planet_temp_max' => $player->planets->current()->getPlanetTempMax(), 'planet_coordinates' => $player->planets->current()->getPlanetCoordinates()->asString(), - 'user_points' => AppUtil::formatNumber($highscoreService->getPlayerScore($player)), + 'user_points' => $user_score, 'user_rank' => $user_rank, 'max_rank' => $max_ranks, 'user_honor_points' => 0, // @TODO