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: add patch download links to Supported Game Files #2329

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/Policies/GamePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Policies;

use App\Enums\Permissions;
use App\Models\Game;
use App\Models\Role;
use App\Models\User;
Expand Down Expand Up @@ -68,4 +69,18 @@ public function forceDelete(User $user, Game $game): bool
{
return false;
}

public function createForumTopic(User $user, Game $game): bool
{
if ($game->ForumTopicID) {
return false;
}

return $user->hasAnyRole([
Role::DEVELOPER_STAFF,
Role::DEVELOPER,
Role::FORUM_MANAGER,
])
|| $user->getAttribute('Permissions') >= Permissions::Developer;
}
}
5 changes: 5 additions & 0 deletions app/Policies/TicketPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public function manage(User $user): bool
|| $user->getAttribute('Permissions') >= Permissions::JuniorDeveloper;
}

public function viewAny(User $user): bool
{
return true;
}

public function view(User $user, Ticket $ticket): bool
{
return true;
Expand Down
2 changes: 1 addition & 1 deletion config/missing-page-redirector.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
'/gameList.php' => '/system/{c}/games',
'/gameSearch.php' => '/games',
'/codenotes.php' => '/game/{g}/notes',
'/linkedhashes.php' => '/game/{g}/assets',
'/linkedhashes.php' => '/game/{g}/hashes',
'/popularGames.php' => '/games/popular',

/*
Expand Down
43 changes: 20 additions & 23 deletions resources/views/components/game/breadcrumbs.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
?>

@props([
'targetConsoleId' => 1,
'targetConsoleName' => 'Mega Drive',
'targetGameId' => null, // int | null
'targetGameName' => null, // string | null,
'currentPageLabel' => null, // string | null
'game' => null, // Game
'currentPageLabel' => null, // ?string
])

<?php
$gameListHref = System::isGameSystem($targetConsoleId)
? route('system.game.index', ['system' => $targetConsoleId])
: '/gameList.php?c=' . $targetConsoleId;
$game->load('system');

$gameListHref = System::isGameSystem($game->system->id)
? route('system.game.index', ['system' => $game->system->id])
: '/gameList.php?c=' . $game->system->id;
?>

{{-- All Games >> Console Name >> Game Name >> Page Name --}}
Expand All @@ -24,25 +23,23 @@
&raquo;

{{-- If there's game metadata, then show console metadata as a URL. Otherwise, it's plain text. --}}
@if ($targetConsoleId && $targetConsoleName)
<a href="{{ $gameListHref }}">{{ $targetConsoleName }}</a>
@if ($gameListHref)
<a href="{{ $gameListHref }}">{{ $game->system->Name }}</a>
@else
<span class="font-bold">{{ $targetConsoleName }}</span>
<span class="font-bold">{{ $game->system->Name }}</span>
@endif

@if ($targetGameId && $targetGameName)
&raquo;
&raquo;

{{-- If there's a current page label, then show game metadata as a URL. Otherwise, it's plain text. --}}
@if ($currentPageLabel)
<a href="{{ route('game.show', $targetGameId) }}">
<x-game-title :rawTitle="$targetGameName" />
</a>
@else
<span class="font-bold">
<x-game-title :rawTitle="$targetGameName" />
</span>
@endif
{{-- If there's a current page label, then show game metadata as a URL. Otherwise, it's plain text. --}}
@if ($currentPageLabel)
<a href="{{ route('game.show', $game->id) }}">
<x-game-title :rawTitle="$game->Title" />
</a>
@else
<span class="font-bold">
<x-game-title :rawTitle="$game->Title" />
</span>
@endif

@if ($currentPageLabel)
Expand Down
1 change: 1 addition & 0 deletions resources/views/components/game/heading.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Enums\Permissions;
?>

{{-- TODO accept a Game model as a prop --}}
@props([
'gameId' => 0,
'gameTitle' => 'Unknown Game',
Expand Down
121 changes: 67 additions & 54 deletions resources/views/components/game/link-buttons/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,95 +1,106 @@
@props([
'allowedLinks' => ['forum-topic', 'game-files', 'guide', 'code-notes', 'tickets', 'set-requestors', 'suggested-games'],
'gameAchievementsCount' => 0,
'gameForumTopicId' => null, // ?int
'gameGuideUrl' => null, // ?string
'gameId' => 1,
'allowedLinks' => [
'code-notes',
'forum-topic',
'game-files',
'guide',
// 'manage-hashes', // supported, but is not a default
'set-requestors',
'suggested-games',
'tickets',
'view-hashes',
],
'isViewingOfficial' => false,
'variant' => 'stacked', // 'stacked' | 'row'
'game' => null, // Game
])

<?php

use App\Community\Enums\TicketFilters;
use App\Enums\Permissions;
use App\Models\ForumTopic;
use App\Models\Ticket;
use App\Platform\Enums\AchievementFlag;
use App\Enums\Permissions;
use Illuminate\Support\Facades\Auth;

$me = Auth::user();

$doesForumTopicExist = false;
if ($gameForumTopicId) {
$doesForumTopicExist = ForumTopic::where('ID', $gameForumTopicId)->exists();
}

$canCreateForumTopic = !$doesForumTopicExist && $me && $me->Permissions >= Permissions::Developer;

$canSeeForumLink = in_array('forum-topic', $allowedLinks);
$canSeeSupportedGameFiles = in_array('game-files', $allowedLinks) && $me && $me->Permissions >= Permissions::Registered;
$canSeeCodeNotes = in_array('code-notes', $allowedLinks) && $me && $me->Permissions >= Permissions::Registered;
$canSeeGuide = in_array('guide', $allowedLinks) && $gameGuideUrl;
$canSeeOpenTickets = in_array('tickets', $allowedLinks) && $me && $me->Permissions >= Permissions::Registered;
$canSeeSetRequestors = in_array('set-requestors', $allowedLinks) && $me && $me->Permissions >= Permissions::Registered && $gameAchievementsCount === 0;
$canSeeSuggestedGames = in_array('suggested-games', $allowedLinks) && $me && $me->Permissions >= Permissions::Registered;
$user = Auth::user();

$canSeeOpenTickets = in_array('tickets', $allowedLinks) && $user?->can('viewAny', Ticket::class);
if ($canSeeOpenTickets) {
$numOpenTickets = countOpenTickets(
!$isViewingOfficial,
TicketFilters::Default,
null,
null,
null,
$gameId,
$game->id,
);
}

$ticketManagerUrlParams = [
'g' => $gameId,
'g' => $game->id,
'f' => $isViewingOfficial ? null : AchievementFlag::Unofficial,
];
$ticketManagerUrl = url('/ticketmanager.php') . '?' . http_build_query($ticketManagerUrlParams);
?>

<ul class="flex @if ($variant === 'stacked') flex-col @endif gap-2">
@if ($canSeeForumLink)
@if ($doesForumTopicExist)
@if (in_array('forum-topic', $allowedLinks))
@if ($game->ForumTopicID)
<x-game.link-buttons.game-link-button
icon="💬"
href="{{ '/viewtopic.php?t=' . $gameForumTopicId }}"
href="{{ '/viewtopic.php?t=' . $game->ForumTopicID }}"
>
Official Forum Topic
</x-game.link-buttons.game-link-button>
@elseif ($canCreateForumTopic)
<x-game.link-buttons.create-forum-topic-button :gameId="$gameId" />
@else
@can('createForumTopic', App\Models\Game::class)
<x-game.link-buttons.create-forum-topic-button :gameId="$game->id" />
@endcan
@endif
@endif

@if ($canSeeGuide)
@if (in_array('guide', $allowedLinks) && $game->GuideURL)
<x-game.link-buttons.game-link-button
icon="📖"
href="{{ $gameGuideUrl }}"
href="{{ $game->GuideURL }}"
>
Guide
</x-game.link-buttons.game-link-button>
@endif

@if ($canSeeSupportedGameFiles)
<x-game.link-buttons.game-link-button
icon="💾"
href="{{ '/linkedhashes.php?g=' . $gameId }}"
>
Supported Game Files
</x-game.link-buttons.game-link-button>
@if (in_array('game-files', $allowedLinks))
@can('viewAny', App\Models\GameHash::class)
<x-game.link-buttons.game-link-button
icon="💾"
:href="route('game.hash', ['game' => $game])"
>
Supported Game Files
</x-game.link-buttons.game-link-button>
@endcan
@endif

@if ($canSeeCodeNotes)
<x-game.link-buttons.game-link-button
icon="📑"
href="{{ '/codenotes.php?g=' . $gameId }}"
>
Code Notes
</x-game.link-buttons.game-link-button>
@if (in_array('manage-hashes', $allowedLinks))
@can('manage', App\Models\GameHash::class)
<x-game.link-buttons.game-link-button
icon="💾"
:href="route('game.hash.manage', ['game' => $game])"
>
Manage Hashes
</x-game.link-buttons.game-link-button>
@endcan
@endif

@if (in_array('code-notes', $allowedLinks))
@can('viewAny', App\Models\MemoryNote::class)
<x-game.link-buttons.game-link-button
icon="📑"
href="{{ '/codenotes.php?g=' . $game->id }}"
>
Code Notes
</x-game.link-buttons.game-link-button>
@endcan
@endif

@if ($canSeeOpenTickets)
Expand All @@ -101,19 +112,21 @@
</x-game.link-buttons.game-link-button>
@endif

@if ($canSeeSetRequestors)
<x-game.link-buttons.game-link-button
icon="📜"
href="{{ '/setRequestors.php?g=' . $gameId }}"
>
Set Requestors
</x-game.link-buttons.game-link-button>
@if (in_array('set-requestors', $allowedLinks) && $game->achievements->isEmpty())
@can('viewAny', App\Models\Game::class)
<x-game.link-buttons.game-link-button
icon="📜"
href="{{ '/setRequestors.php?g=' . $game->id }}"
>
Set Requestors
</x-game.link-buttons.game-link-button>
@endcan
@endif

@if ($canSeeSuggestedGames)
@if (in_array('suggested-games', $allowedLinks) && $user)
<x-game.link-buttons.game-link-button
icon="🕹️"
href="{{ route('game.suggest', $gameId) }}"
href="{{ route('game.suggest', $game->id) }}"
>
Find Something Similar to Play
</x-game.link-buttons.game-link-button>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@props([
'hash' => null, // GameHash
])

<li>
<p>
@if ($hash->name)
<span class="font-bold">{{ $hash->name }}</span>
@endif

@if (!empty($hash->labels))
@foreach (explode(',', $hash->labels) as $label)
@if (empty($label))
@continue;
@endif

@php
$image = "/assets/images/labels/" . $label . '.png';
$publicPath = public_path($image);
@endphp

@if (file_exists($publicPath))
<img class="inline-image" src="{{ asset($image) }}">
@else
<span>[{{ $label }}]</span>
@endif
@endforeach
@endif
</p>

<div class="flex flex-col pl-2 border-l-2 border-neutral-700 black:border-neutral-700 light:border-embed-highlight">
<p class="font-mono text-neutral-200 light:text-neutral-700">
{{ $hash->md5 }}
</p>

@if ($hash->patch_url)
<a href="{{ $hash->patch_url }}" rel="noreferrer">Download Patch File</a>
@endif
</div>
Jamiras marked this conversation as resolved.
Show resolved Hide resolved
</li>
12 changes: 4 additions & 8 deletions resources/views/pages-legacy/gameInfo.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@
}

$numAchievements = getGameMetadata($gameID, $userModel, $achievementData, $gameData, $sortBy, null, $flagParam, metrics: true);
$gameModel = Game::find($gameID);

if (empty($gameData)) {
if (!$gameModel) {
abort(404);
}

Expand Down Expand Up @@ -921,8 +922,7 @@ function resize() {
?>
<x-game.link-buttons
:allowedLinks="['forum-topic']"
:gameForumTopicId="$forumTopicID"
:gameId="$gameID"
:game="$gameModel"
/>
<?php
echo "</div>";
Expand Down Expand Up @@ -955,10 +955,7 @@ function resize() {
echo "<div class='component'>";
?>
<x-game.link-buttons
:gameAchievementsCount="$numAchievements"
:gameForumTopicId="$forumTopicID"
:gameGuideUrl="$guideURL"
:gameId="$gameID"
:game="$gameModel"
:isViewingOfficial="$flagParam !== $unofficialFlag"
/>
<?php
Expand Down Expand Up @@ -1002,7 +999,6 @@ function resize() {
}

if ($user !== null && $numAchievements > 0) {
$gameModel = Game::find($gameID);
?>
<div class="mb-4">
<x-game.compare-progress
Expand Down
Loading
Loading