Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(home): redesign achievement of the week #1658

Merged
merged 9 commits into from
Jul 15, 2023
40 changes: 39 additions & 1 deletion app/Site/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,50 @@
namespace App\Site\Controllers;

use App\Http\Controller;
use App\Platform\Models\Achievement;
use App\Platform\Models\Game;
use App\Platform\Models\System;
use App\Site\Models\StaticData;
use Illuminate\Contracts\View\View;

class HomeController extends Controller
{
public function __invoke(): View
{
return view('home');
$currentEventMetadata = $this->fetchCurrentEventMetadata();

if ($currentEventMetadata === null) {
return view('home');
}

return view('home', $currentEventMetadata);
}

// TODO: This should eventually support multiple different kinds of events.
private function fetchCurrentEventMetadata(): ?array
{
$staticData = StaticData::first();

if ($staticData === null) {
return null;
}

$aotwAchievementId = $staticData['Event_AOTW_AchievementID'];
$eventForumTopicId = $staticData['Event_AOTW_ForumID'];
$achievement = Achievement::find($aotwAchievementId);

if (!$achievement) {
return null;
}

$game = Game::find($achievement->GameID);
$consoleName = System::find($game->ConsoleID)->Name;

return [
'eventAchievement' => $achievement,
'eventGame' => $game,
'eventConsoleName' => $consoleName,
'eventForumTopicId' => $eventForumTopicId,
];
}
}
64 changes: 41 additions & 23 deletions resources/views/community/components/event/aotw.blade.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
@props([
'achievement' => [],
'game' => [],
'consoleName' => '',
'forumTopicId' => 0,
])

<?php
$achievementId = $achievement->ID;
$achievementName = $achievement->Title;
$achievementDescription = $achievement->Description;
$achievementPoints = $achievement->Points;
$achievementRetroPoints = $achievement->TrueRatio;
$achievementBadgeName = $achievement->BadgeName;

use App\Site\Models\StaticData;
$renderedGameTitle = renderGameTitle($game->Title);
$achievementIconSrc = media_asset("/Badge/$achievementBadgeName.png");
$gameSystemIconUrl = getSystemIconUrl($game->ConsoleID);
?>

$staticData = StaticData::first();
<div class="component">
<h3>Achievement of the Week</h3>

if ($staticData === null) {
return;
}
<div class="bg-embed p-4 rounded border border-embed-highlight">
<a href="{{ route('achievement.show', $achievement->ID) }}" class="group flex gap-x-2 mb-3 text-text transition-transform hover:-translate-y-0.5">
Jamiras marked this conversation as resolved.
Show resolved Hide resolved
<img src="{{ $achievementIconSrc }}" alt="Achievement of the week badge" width="64" height="64" class="w-16 h-16">
<div>
<p class="font-semibold leading-4 text-link group-hover:text-link-hover">{{ $achievement->Title }}</p>
Jamiras marked this conversation as resolved.
Show resolved Hide resolved
<p class="text-xs mb-1">5 <span class="TrueRatio">(12)</span> Points</p>
<p class="text-xs">{{ $achievement->Description }}</p>
luchaos marked this conversation as resolved.
Show resolved Hide resolved
</div>
</a>

$achID = $staticData['Event_AOTW_AchievementID'];
$forumTopicID = $staticData['Event_AOTW_ForumID'];
<hr class="border-embed-highlight mt-2 mb-3">

$achData = GetAchievementData($achID);
if (empty($achData)) {
return;
}
?>
<div class="component">
<h3>Achievement of the Week</h3>
<div class="text-center">
<div>
{!! achievementAvatar($achData) !!}
</div>
in
<div>
{!! gameAvatar($achData, iconSize: 24) !!}
</div>
<a class="btn mt-2" href="/viewtopic.php?t={{ $forumTopicID }}">Join this tournament!</a>
<a href="{{ route('game.show', $achievement->GameID) }}" class="group flex gap-x-2 text-text transition-transform hover:translate-x-0.5">
<img src="{{ media_asset($game->ImageIcon) }}" alt="Achievement of the week game badge" width="32" height="32" class="w-8 h-8">
<div class="-mt-1">
<p class="font-semibold mb-0.5 text-xs text-link group-hover:text-link-hover">{!! $renderedGameTitle !!}</p>
<div class="flex items-center gap-x-1">
<img src="{{ $gameSystemIconUrl }}" width="18" height="18" alt="Console icon">
<span class="block text-xs tracking-tighter">{{ $consoleName }}</span>
</div>
</div>
</a>
wescopeland marked this conversation as resolved.
Show resolved Hide resolved
</div>

<a class="btn text-center py-2 w-full mt-2" href="/viewtopic.php?t={{ $forumTopicId }}">Learn more about this event</a>
</div>
11 changes: 10 additions & 1 deletion resources/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@

@slot('sidebar')
@include('content.top-links')
<x-event.aotw />

@if(isset($eventAchievement))
<x-event.aotw
:achievement="$eventAchievement"
:game="$eventGame"
:consoleName="$eventConsoleName"
:forumTopicId="$eventForumTopicId"
/>
@endif

@include('content.static-data')
@endslot
</x-app-layout>
4 changes: 4 additions & 0 deletions tests/Feature/Site/HomeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Platform\Models\Achievement;
use App\Platform\Models\Game;
use App\Platform\Models\System;
use App\Site\Models\StaticData;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
Expand All @@ -23,9 +24,12 @@ public function testItRendersPageWithStaticData(): void
{
/** @var StaticData $staticData */
$staticData = StaticData::factory()->create();
/** @var System $system */
$system = System::factory()->create();
/** @var Game $game */
$game = Game::factory()->create([
'ID' => $staticData->LastCreatedGameID,
'ConsoleID' => $system->ID,
]);
/** @var Achievement $achievement */
$achievement = Achievement::factory()->create([
Expand Down