refactor: Update image URL generation logic

- Refactored the logic for generating image URLs for champions and champion skins to improve readability and maintainability.
This commit is contained in:
Rico van Zelst
2024-05-01 01:12:31 +02:00
parent c1c876b488
commit c69a5472aa
2 changed files with 9 additions and 6 deletions

View File

@@ -101,9 +101,12 @@ class Champion extends Model
public function getChampionImageAttribute(bool $uncentered = false): string public function getChampionImageAttribute(bool $uncentered = false): string
{ {
$baseUrl = 'https://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/v1/champion-splashes/'; $baseUrl = 'https://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/assets/characters/';
$imagePath = $uncentered ? 'uncentered/' : ''; $championName = strtolower(str_replace([' ', "'", '.'], ['', '', ''], $this->name));
$imageUrl = $baseUrl.$imagePath.$this->champion_id.'/'.$this->champion_id.'000.jpg'; $imagePath = 'base/images/';
$imageUrl = $baseUrl . $championName . '/skins/' . $imagePath . $championName . '_splash_';
$imageUrl .= $uncentered ? 'uncentered' : 'centered';
$imageUrl .= '_0.jpg';
return $imageUrl; return $imageUrl;
} }

View File

@@ -74,9 +74,9 @@ class ChampionSkin extends Model
public function getSkinImageAttribute(bool $uncentered = false): string public function getSkinImageAttribute(bool $uncentered = false): string
{ {
$baseUrl = 'https://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/v1/champion-splashes/'; $championName = strtolower(str_replace([' ', "'"], ['', ''], $this->champion->name));
$imagePath = $uncentered ? 'uncentered/' : ''; $imagePath = $uncentered ? 'uncentered_' : 'centered_';
$imageUrl = $baseUrl.$imagePath.$this->champion_id.'/'.$this->full_skin_id.'.jpg'; $imageUrl = 'https://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/assets/characters/' . $championName . '/skins/skin' . str_pad($this->skin_id, 2, '0', STR_PAD_LEFT) . '/images/' . $championName . '_splash_' . $imagePath . $this->skin_id . '.jpg';
return $imageUrl; return $imageUrl;
} }