70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class ItemDataService
|
|
{
|
|
protected static bool $loaded = false;
|
|
|
|
protected static ?array $icons = null;
|
|
|
|
protected static ?array $descriptions = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->loadData();
|
|
}
|
|
|
|
protected function loadData()
|
|
{
|
|
if (self::$loaded) {
|
|
return;
|
|
}
|
|
|
|
if (Storage::has('item-data/item_list.txt')) {
|
|
self::$icons = collect(explode("\n", Storage::get('item-data/item_list.txt')))
|
|
->map(fn ($line) => str_getcsv($line, "\t"))
|
|
->filter(fn ($item) => isset($item[0], $item[2]))
|
|
->mapWithKeys(fn ($item) => [intval($item[0]) => str($item[2])->basename()->replaceMatches('/tga|dds/i', 'png')])
|
|
->toArray();
|
|
} else {
|
|
self::$icons = [];
|
|
}
|
|
|
|
if (Storage::has('item-data/itemdesc.txt')) {
|
|
self::$descriptions = collect(explode("\n", Storage::get('item-data/itemdesc.txt')))
|
|
->map(fn ($line) => str_getcsv($line, "\t"))
|
|
->filter(fn ($item) => isset($item[0], $item[2]))
|
|
->mapWithKeys(fn ($item) => [intval($item[0]) => $item[2]])
|
|
->toArray();
|
|
} else {
|
|
self::$descriptions = [];
|
|
}
|
|
|
|
self::$loaded = true;
|
|
}
|
|
|
|
public function getIcon(int $vnum): ?string
|
|
{
|
|
$this->loadData();
|
|
|
|
return self::$icons[$vnum] ?? null;
|
|
}
|
|
|
|
public function getDescription(int $vnum): ?string
|
|
{
|
|
$this->loadData();
|
|
|
|
return self::$descriptions[$vnum] ?? null;
|
|
}
|
|
|
|
public static function flush(): void
|
|
{
|
|
self::$loaded = false;
|
|
self::$icons = [];
|
|
self::$descriptions = [];
|
|
}
|
|
}
|