This commit is contained in:
Rico van Zelst
2024-05-02 01:37:39 +02:00
4 changed files with 15 additions and 16 deletions

View File

@@ -1,8 +1,8 @@
<?php <?php
use App\Models\ChampionImage;
use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\Drivers\Gd\Driver;
use Intervention\Image\ImageManager; use Intervention\Image\ImageManager;
use App\Models\ChampionImage;
function getRoleIcon($roleName): string function getRoleIcon($roleName): string
{ {
@@ -67,7 +67,7 @@ function getRoleIconSvg($roleName): string
} }
/** /**
* Get the champion image * Get the champion image.
* *
* @param string $full_id * @param string $full_id
* @param enum $type splash, uncentered_splash, loading, tile, icon, ability, video * @param enum $type splash, uncentered_splash, loading, tile, icon, ability, video
@@ -77,7 +77,7 @@ function getChampionImage($full_id, $type): string
{ {
$championImage = ChampionImage::where('full_id', $full_id)->where('type', $type)->first(); $championImage = ChampionImage::where('full_id', $full_id)->where('type', $type)->first();
if (!$championImage) { if (! $championImage) {
return ''; return '';
} }

View File

@@ -101,12 +101,12 @@ class Champion extends Model
public function getChampionImageAttribute(bool $uncentered = false): string public function getChampionImageAttribute(bool $uncentered = false): string
{ {
return getChampionImage($this->champion_id . '000', $uncentered ? 'uncentered_splash' : 'splash'); return getChampionImage($this->champion_id.'000', $uncentered ? 'uncentered_splash' : 'splash');
} }
public function getChampionImageTileAttribute(): string public function getChampionImageTileAttribute(): string
{ {
return getChampionImage($this->champion_id . '000', 'tile'); return getChampionImage($this->champion_id.'000', 'tile');
} }
public function getChampionSquareImageAttribute(): string public function getChampionSquareImageAttribute(): string

View File

@@ -2,10 +2,9 @@
namespace Database\Seeders; namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\ChampionImage;
use App\Models\Champion; use App\Models\Champion;
use App\Models\ChampionImage;
use Illuminate\Database\Seeder;
class ChampionImageSeeder extends Seeder class ChampionImageSeeder extends Seeder
{ {
@@ -16,7 +15,7 @@ class ChampionImageSeeder extends Seeder
{ {
// Loop over all champions // Loop over all champions
Champion::all()->each(function ($champion) { Champion::all()->each(function ($champion) {
$dataJson = 'https://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/v1/champions/' . $champion->champion_id . '.json'; $dataJson = 'https://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/v1/champions/'.$champion->champion_id.'.json';
$data = json_decode(file_get_contents($dataJson), true); $data = json_decode(file_get_contents($dataJson), true);
@@ -27,28 +26,28 @@ class ChampionImageSeeder extends Seeder
$splash->full_id = $skin['id']; $splash->full_id = $skin['id'];
$splash->champion_id = $champion->champion_id; $splash->champion_id = $champion->champion_id;
$splash->type = 'splash'; $splash->type = 'splash';
$splash->url = 'https://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/' . strtolower(substr($skin['splashPath'], strpos($skin['splashPath'], 'ASSETS'))); $splash->url = 'https://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/'.strtolower(substr($skin['splashPath'], strpos($skin['splashPath'], 'ASSETS')));
$splash->save(); $splash->save();
$uncenteredSplash = new ChampionImage(); $uncenteredSplash = new ChampionImage();
$uncenteredSplash->full_id = $skin['id']; $uncenteredSplash->full_id = $skin['id'];
$uncenteredSplash->champion_id = $champion->champion_id; $uncenteredSplash->champion_id = $champion->champion_id;
$uncenteredSplash->type = 'uncentered_splash'; $uncenteredSplash->type = 'uncentered_splash';
$uncenteredSplash->url = 'https://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/' . strtolower(substr($skin['uncenteredSplashPath'], strpos($skin['uncenteredSplashPath'], 'ASSETS'))); $uncenteredSplash->url = 'https://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/'.strtolower(substr($skin['uncenteredSplashPath'], strpos($skin['uncenteredSplashPath'], 'ASSETS')));
$uncenteredSplash->save(); $uncenteredSplash->save();
$loading = new ChampionImage(); $loading = new ChampionImage();
$loading->full_id = $skin['id']; $loading->full_id = $skin['id'];
$loading->champion_id = $champion->champion_id; $loading->champion_id = $champion->champion_id;
$loading->type = 'loading'; $loading->type = 'loading';
$loading->url = 'https://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/' . strtolower(substr($skin['loadScreenPath'], strpos($skin['loadScreenPath'], 'ASSETS'))); $loading->url = 'https://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/'.strtolower(substr($skin['loadScreenPath'], strpos($skin['loadScreenPath'], 'ASSETS')));
$loading->save(); $loading->save();
$tile = new ChampionImage(); $tile = new ChampionImage();
$tile->full_id = $skin['id']; $tile->full_id = $skin['id'];
$tile->champion_id = $champion->champion_id; $tile->champion_id = $champion->champion_id;
$tile->type = 'tile'; $tile->type = 'tile';
$tile->url = 'https://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/' . strtolower(substr($skin['tilePath'], strpos($skin['tilePath'], 'ASSETS'))); $tile->url = 'https://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/'.strtolower(substr($skin['tilePath'], strpos($skin['tilePath'], 'ASSETS')));
$tile->save(); $tile->save();
} }
}); });

View File

@@ -4,9 +4,9 @@ namespace Database\Seeders;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents; // use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Artisan;
class DatabaseSeeder extends Seeder class DatabaseSeeder extends Seeder
{ {