feat: champ information, style improvement

This commit is contained in:
Rico van Zelst
2023-11-08 14:12:51 +01:00
parent b0a88ba3b9
commit 149174ebc3
11 changed files with 299 additions and 24 deletions

View File

@@ -1,5 +1,7 @@
<?php
use Intervention\Image\ImageManagerStatic as Image;
function getRoleIcon($roleName)
{
$roleIcons = [
@@ -12,3 +14,46 @@ function getRoleIcon($roleName)
return asset('img/' . $roleIcons[$roleName]);
}
function getAverageColorFromImageUrl($imageUrl): string
{
$img = Image::make($imageUrl);
$img->resize(24, 24);
$totalR = 0;
$totalG = 0;
$totalB = 0;
$width = $img->width();
$height = $img->height();
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $height; $y++) {
$color = $img->pickColor($x, $y);
$totalR += $color[0];
$totalG += $color[1];
$totalB += $color[2];
}
}
$pixelCount = $width * $height;
$avgR = $totalR / $pixelCount;
$avgG = $totalG / $pixelCount;
$avgB = $totalB / $pixelCount;
return sprintf("#%02x%02x%02x", $avgR, $avgG, $avgB);
}
function getRoleIconSvg($roleName): string
{
$roleIcons = [
'Toplane' => 'icon-position-top',
'Jungle' => 'icon-position-jungle',
'Midlane' => 'icon-position-middle',
'Botlane' => 'icon-position-bottom',
'Support' => 'icon-position-utility',
];
return $roleIcons[$roleName];
}

View File

@@ -51,6 +51,12 @@ class ChampionController extends Controller
return $champion->load('skins', 'lanes');
});
$splashColor = Cache::remember('championSplashColorCache' . $champion->slug, 60 * 60 * 24, function () use ($champion) {
return getAverageColorFromImageUrl($champion->getChampionImageAttribute());
});
$champion->splash_color = $splashColor;
return view('champions.show', compact('champion'));
}

View File

@@ -33,6 +33,40 @@ class Champion extends Model
'roles' => 'array',
];
public function getResourceTypeAttribute($value): string
{
$resourceTypes = [
'BLOOD_WELL' => "Blood",
"MANA" => "Mana",
"ENERGY" => "Energy",
"NONE" => "None",
"HEALTH" => "Health",
"RAGE" => "Rage",
"COURAGE" => "Courage",
"SHIELD" => "Shield",
"FURY" => "Fury",
"FEROCITY" => "Ferocity",
"HEAT" => "Heat",
"GRIT" => "Grit",
"BLOODTHIRST" => "Bloodthirst",
"FLOW" => "Flow",
"SOUL_UNBOUND" => "Soul Unbound",
];
return $resourceTypes[$value];
}
public function getAdaptiveTypeAttribute($value): string
{
$adaptiveTypes = [
'ADAPTIVE_DAMAGE' => 'Adaptive',
'MAGIC_DAMAGE' => 'Magical',
'PHYSICAL_DAMAGE' => 'Physical',
];
return $adaptiveTypes[$value];
}
public function sluggable(): array
{
return [

View File

@@ -47,4 +47,6 @@ class ChampionRoles extends Model
return $transformedRoles;
}
}