mirror of
https://github.com/rico-vz/HeimerdingerLoL.git
synced 2025-12-06 18:20:48 +01:00
feat: champion skin 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('champion_skins', function (Blueprint $table) {
|
||||||
|
$table->integer('rp_price')->change();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('champion_skins', function (Blueprint $table) {
|
||||||
|
$table->bigInteger('rp_price')->change();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
28
database/migrations/2023_10_31_085408_make_lore_nullable.php
Normal file
28
database/migrations/2023_10_31_085408_make_lore_nullable.php
Normal file
@@ -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('champion_skins', function (Blueprint $table) {
|
||||||
|
$table->text('lore')->nullable()->change();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('champion_skins', function (Blueprint $table) {
|
||||||
|
$table->text('lore')->nullable(false)->change();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -4,6 +4,7 @@ namespace Database\Seeders;
|
|||||||
|
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
use App\Models\Champion;
|
use App\Models\Champion;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class ChampionSeeder extends Seeder
|
class ChampionSeeder extends Seeder
|
||||||
{
|
{
|
||||||
@@ -38,8 +39,10 @@ class ChampionSeeder extends Seeder
|
|||||||
// Check if the champion already exists and if any attributes have changed, if so update the champion. If the champion doesn't exist, create it.
|
// Check if the champion already exists and if any attributes have changed, if so update the champion. If the champion doesn't exist, create it.
|
||||||
// This is to prevent the champion data from being updated every time the seeder is run. As I'll probably run this on a cron job.
|
// This is to prevent the champion data from being updated every time the seeder is run. As I'll probably run this on a cron job.
|
||||||
if ($championExists && $this->hasAttributesChanged($championExists, $championAttributes)) {
|
if ($championExists && $this->hasAttributesChanged($championExists, $championAttributes)) {
|
||||||
|
Log::info('Champion ' . $champion['name'] . ' has changed, updating...');
|
||||||
$championExists->update($championAttributes);
|
$championExists->update($championAttributes);
|
||||||
} elseif (!$championExists) {
|
} elseif (!$championExists) {
|
||||||
|
Log::info('New champion detected! Creating ' . $champion['name'] . '...');
|
||||||
Champion::create($championAttributes);
|
Champion::create($championAttributes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
use App\Models\Champion;
|
use App\Models\Champion;
|
||||||
|
use App\Models\ChampionSkin;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class ChampionSkinSeeder extends Seeder
|
class ChampionSkinSeeder extends Seeder
|
||||||
{
|
{
|
||||||
@@ -16,8 +18,54 @@ class ChampionSkinSeeder extends Seeder
|
|||||||
$championData = json_decode(file_get_contents($championDataUrl), true);
|
$championData = json_decode(file_get_contents($championDataUrl), true);
|
||||||
|
|
||||||
foreach ($championData as $champion) {
|
foreach ($championData as $champion) {
|
||||||
$championId = $champion['id'];
|
foreach ($champion['skins'] as $skin) {
|
||||||
$championExists = Champion::where('champion_id', $championId)->first();
|
$skinId = $skin['id'];
|
||||||
|
$skinExists = ChampionSkin::where('full_skin_id', $skinId)->first();
|
||||||
|
if ($skin['cost'] == "Special") {
|
||||||
|
$skin['cost'] = 99999;
|
||||||
|
}
|
||||||
|
|
||||||
|
$skinAttributes = [
|
||||||
|
'champion_id' => $champion['id'],
|
||||||
|
'full_skin_id' => $skin['id'],
|
||||||
|
'skin_id' => substr($skin['id'], 3),
|
||||||
|
'skin_name' => $skin['name'] . ' ' . $champion['name'],
|
||||||
|
'lore' => $skin['lore'],
|
||||||
|
'availability' => $skin['availability'],
|
||||||
|
'loot_eligible' => $skin['lootEligible'],
|
||||||
|
'rp_price' => $skin['cost'],
|
||||||
|
'rarity' => $skin['rarity'],
|
||||||
|
'release_date' => $skin['release'],
|
||||||
|
'associated_skinline' => $skin['set'],
|
||||||
|
'new_effects' => $skin['newEffects'],
|
||||||
|
'new_animations' => $skin['newAnimations'],
|
||||||
|
'new_recall' => $skin['newRecall'],
|
||||||
|
'new_voice' => $skin['newVoice'],
|
||||||
|
'new_quotes' => $skin['newQuotes'],
|
||||||
|
'voice_actor' => $skin['voiceActor'],
|
||||||
|
'splash_artist' => $skin['splashArtist'],
|
||||||
|
];
|
||||||
|
|
||||||
|
// Check if the skin already exists and if any attributes have changed, if so update the skin. If the skin doesn't exist, create it.
|
||||||
|
// This is to prevent the skin data from being updated every time the seeder is run. As I'll probably run this on a cron job.
|
||||||
|
if ($skinExists && $this->hasAttributesChanged($skinExists, $skinAttributes)) {
|
||||||
|
Log::info('Skin ' . $skin['name'] . ' ' . $champion['name'] . ' has changed, updating...');
|
||||||
|
$skinExists->update($skinAttributes);
|
||||||
|
} elseif (!$skinExists) {
|
||||||
|
Log::info('New skin detected! Creating ' . $skin['name'] . ' ' . $champion['name'] . '...');
|
||||||
|
ChampionSkin::create($skinAttributes);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function hasAttributesChanged($skin, $attributes)
|
||||||
|
{
|
||||||
|
foreach ($attributes as $key => $value) {
|
||||||
|
if ($skin->{$key} != $value) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,5 +12,7 @@ class DatabaseSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
|
$this->call(ChampionSeeder::class);
|
||||||
|
$this->call(ChampionSkinSeeder::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user