mirror of
https://github.com/rico-vz/HeimerdingerLoL.git
synced 2025-12-06 10:10:48 +01:00
feat: skin chroma data seeder
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('skin_chromas', function (Blueprint $table) {
|
||||
$table->string('chroma_id')->after('id')->unique();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('skin_chromas', function (Blueprint $table) {
|
||||
$table->dropColumn('chroma_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -15,6 +15,7 @@ class DatabaseSeeder extends Seeder
|
||||
{
|
||||
$this->call(ChampionSeeder::class);
|
||||
$this->call(ChampionSkinSeeder::class);
|
||||
$this->call(SkinChromaSeeder::class);
|
||||
|
||||
Log::info('Seeding complete at ' . date('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\SkinChroma;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class SkinChromaSeeder extends Seeder
|
||||
{
|
||||
@@ -12,6 +14,53 @@ class SkinChromaSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
$championDataUrl = "http://cdn.merakianalytics.com/riot/lol/resources/latest/en-US/champions.json";
|
||||
$championData = json_decode(file_get_contents($championDataUrl), true);
|
||||
|
||||
foreach ($championData as $champion) {
|
||||
foreach ($champion['skins'] as $skin) {
|
||||
if ($skin['name'] === "Original") {
|
||||
continue;
|
||||
}
|
||||
foreach ($skin['chromas'] as $chroma) {
|
||||
if ($chroma === null) continue; // To address: https://github.com/meraki-analytics/lolstaticdata/issues/71
|
||||
|
||||
$chromaId = $chroma['id'];
|
||||
|
||||
$chromaExists = SkinChroma::where('chroma_id', $chromaId)->first();
|
||||
$chromaAttributes = [
|
||||
'chroma_id' => $chromaId,
|
||||
'full_skin_id' => $skin['id'],
|
||||
'skin_name' => $skin['name'] . ' ' . $champion['name'],
|
||||
'chroma_name' => $chroma['name'],
|
||||
'chroma_colors' => $chroma['colors'],
|
||||
'chroma_image' => $chroma['chromaPath'],
|
||||
];
|
||||
|
||||
// Mundo is a special case, his skins often include his name in the skin name, so we need to remove it.
|
||||
if (strpos($chromaAttributes['skin_name'], 'Mundo Dr. Mundo') !== false) {
|
||||
$skinAttributes['skin_name'] = str_replace('Mundo Dr. Mundo', 'Mundo', $chromaAttributes['skin_name']);
|
||||
}
|
||||
|
||||
if ($chromaExists && $this->hasAttributesChanged($chromaExists, $chromaAttributes)) {
|
||||
Log::info('Updating chroma: ' . $chromaId);
|
||||
$chromaExists->update($chromaAttributes);
|
||||
} else if (!$chromaExists) {
|
||||
Log::info('Creating chroma: ' . $chromaId);
|
||||
SkinChroma::create($chromaAttributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function hasAttributesChanged($chroma, $attributes)
|
||||
{
|
||||
foreach ($attributes as $key => $value) {
|
||||
if ($chroma->{$key} != $value) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user