Skip to content
Open
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
82 changes: 2 additions & 80 deletions app/Filament/Resources/GameResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
use App\Models\Game;
use App\Models\System;
use App\Models\User;
use App\Rules\DisallowAnimatedImageRule;
use App\Rules\UploadedImageAspectRatioRule;
use BackedEnum;
use Filament\Actions;
use Filament\Actions\ActionGroup;
Expand Down Expand Up @@ -292,84 +290,6 @@ public static function form(Schema $schema): Schema
->disabled(!$user->can('updateField', [$schema->model, 'legacy_guide_url'])),
]),

Schemas\Components\Section::make('Media')
->icon('heroicon-s-photo')
->hidden(
!$user->can('updateField', [$schema->model, 'image_icon_asset_path'])
&& !$user->can('updateField', [$schema->model, 'image_box_art_asset_path'])
&& !$user->can('updateField', [$schema->model, 'image_title_asset_path'])
&& !$user->can('updateField', [$schema->model, 'image_ingame_asset_path'])
)
->schema([
// Store a temporary file on disk until the user submits.
// When the user submits, put in storage.
Forms\Components\FileUpload::make('image_icon_asset_path')
->label('Badge')
->disk('livewire-tmp') // Use Livewire's self-cleaning temporary disk
->image()
->rules([
'dimensions:width=96,height=96',
])
->acceptedFileTypes(['image/png', 'image/jpeg'])
->maxSize(1024)
->maxFiles(1)
->previewable(true)
->hidden(!$user->can('updateField', [$schema->model, 'image_icon_asset_path'])),

Forms\Components\FileUpload::make('image_box_art_asset_path')
->label('Box Art')
->disk('livewire-tmp') // Use Livewire's self-cleaning temporary disk
->image()
->acceptedFileTypes(['image/png', 'image/jpeg'])
->maxSize(1024)
->maxFiles(1)
->previewable(true)
->hidden(!$user->can('updateField', [$schema->model, 'image_box_art_asset_path'])),

Forms\Components\FileUpload::make('image_title_asset_path')
->label('Title')
->disk('livewire-tmp') // Use Livewire's self-cleaning temporary disk
->image()
->acceptedFileTypes(['image/png', 'image/jpeg'])
->maxSize(1024)
->maxFiles(1)
->previewable(true)
->hidden(!$user->can('updateField', [$schema->model, 'image_title_asset_path'])),

Forms\Components\FileUpload::make('image_ingame_asset_path')
->label('In Game')
->disk('livewire-tmp') // Use Livewire's self-cleaning temporary disk
->image()
->acceptedFileTypes(['image/png', 'image/jpeg'])
->maxSize(1024)
->maxFiles(1)
->previewable(true)
->hidden(!$user->can('updateField', [$schema->model, 'image_ingame_asset_path'])),

Forms\Components\SpatieMediaLibraryFileUpload::make('banner')
->label('Banner Image')
->collection('banner')
->conversion('desktop-xl-webp')
->disk('s3')
->visibility('public')
->image()
->rules([
'dimensions:min_width=1920,min_height=540',
new UploadedImageAspectRatioRule(32 / 9, 0.15), // 32:9 aspect ratio with a ±15% tolerance.
new DisallowAnimatedImageRule(),
])
->acceptedFileTypes(['image/png', 'image/jpeg', 'image/webp'])
->maxSize(5120)
->maxFiles(1)
->customProperties(['is_current' => true])
->filterMediaUsing(fn ($media) => $media->where('custom_properties.is_current', true))
->helperText(new HtmlString('Read: <a href="https://docs.retroachievements.org/guidelines/content/badge-and-icon-guidelines.html#game-page-banners" target="_blank" class="underline">banner rules and guidelines</a>. Upload a high-quality 32:9 ultra-wide banner image (minimum: 1920x540, recommended: 3200x900). The image must be approximately 32:9 aspect ratio (±15% tolerance). The image will be processed to multiple sizes for mobile and desktop. Your image should not include text of any kind.'))
->previewable(true)
->downloadable(false)
->hidden(!$user->can('updateField', [$schema->model, 'banner'])),
])
->columns(2),

Schemas\Components\Section::make('Rich Presence')
->icon('heroicon-s-chat-bubble-left-right')
->schema([
Expand Down Expand Up @@ -704,6 +624,7 @@ public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
Pages\Details::class,
Pages\Media::class,
Pages\Hubs::class,
Pages\SimilarGames::class,
Pages\Hashes::class,
Expand All @@ -717,6 +638,7 @@ public static function getPages(): array
'index' => Pages\Index::route('/'),
'view' => Pages\Details::route('/{record}'),
'edit' => Pages\Edit::route('/{record}/edit'),
'media' => Pages\Media::route('/{record}/media'),
'hubs' => Pages\Hubs::route('/{record}/hubs'),
'similar-games' => Pages\SimilarGames::route('/{record}/similar-games'),
'hashes' => Pages\Hashes::route('/{record}/hashes'),
Expand Down
42 changes: 0 additions & 42 deletions app/Filament/Resources/GameResource/Pages/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@
namespace App\Filament\Resources\GameResource\Pages;

use App\Connect\Actions\SubmitRichPresenceAction;
use App\Filament\Actions\ApplyUploadedImageToDataAction;
use App\Filament\Actions\ViewOnSiteAction;
use App\Filament\Concerns\HasFieldLevelAuthorization;
use App\Filament\Enums\ImageUploadType;
use App\Filament\Resources\GameResource;
use App\Models\Game;
use App\Models\User;
use App\Support\MediaLibrary\Actions\ExtractBannerEdgeColorsAction;
use Exception;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;

class Edit extends EditRecord
{
Expand Down Expand Up @@ -57,13 +52,6 @@ protected function mutateFormDataBeforeSave(array $data): array
}
}

$action = new ApplyUploadedImageToDataAction();

$action->execute($data, 'image_icon_asset_path', ImageUploadType::GameBadge);
$action->execute($data, 'image_title_asset_path', ImageUploadType::GameTitle);
$action->execute($data, 'image_ingame_asset_path', ImageUploadType::GameInGame);
$action->execute($data, 'image_box_art_asset_path', ImageUploadType::GameBoxArt);

// Handle trigger_definition separately to ensure trigger versioning is captured.
if (array_key_exists('trigger_definition', $data)) {
/** @var User $user */
Expand All @@ -79,42 +67,12 @@ protected function mutateFormDataBeforeSave(array $data): array
unset($data['trigger_definition']);
}

// Remove banner from the data array - it's handled by MediaLibrary, not a database column.
unset($data['banner']);

return $data;
}

protected function afterSave(): void
{
$this->record->refresh();
$this->refreshFormData(['sort_title']);

/** @var Game $game */
$game = $this->record;

$banner = $game->current_banner_media;

// Extract and store edge colors.
if ($banner && !$banner->getCustomProperty('left_edge_color')) {
try {
$action = new ExtractBannerEdgeColorsAction();

$fileContents = Storage::disk('s3')->get($banner->getPath());
$extension = $banner->extension;
$tempPath = tempnam(sys_get_temp_dir(), 'banner-') . '.' . $extension;
file_put_contents($tempPath, $fileContents);

$colors = $action->execute($tempPath);

unlink($tempPath);

$banner->setCustomProperty('left_edge_color', $colors['left_edge_color']);
$banner->setCustomProperty('right_edge_color', $colors['right_edge_color']);
$banner->save();
} catch (Exception $e) {
// Silently fail if color extraction fails - this isn't critical.
}
}
}
}
Loading