Skip to content

Commit

Permalink
Merge pull request #446 from jackbayliss/hotfix/highscore-on-overview
Browse files Browse the repository at this point in the history
Add highscores on overview page
  • Loading branch information
lanedirt authored Nov 11, 2024
2 parents 28a284d + ce49966 commit 9625f4d
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions app/Http/Controllers/OverviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,16 +56,28 @@ 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();
});

$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(),
'planet_diameter' => $player->planets->current()->getPlanetDiameter(),
'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_rank' => 0, // @TODO
'max_rank' => 0, // @TODO
'user_points' => $user_score,
'user_rank' => $user_rank,
'max_rank' => $max_ranks,
'user_honor_points' => 0, // @TODO
'build_active' => $build_active,
'building_count' => $player->planets->current()->getBuildingCount(),
Expand Down

0 comments on commit 9625f4d

Please sign in to comment.