}/*.png. */ public function catalog(): array { if ($this->catalogCache !== null) return $this->catalogCache; $root = resource_path('games/olden-era'); $out = []; foreach (glob($root . '/factions/*.png') ?: [] as $factionPng) { $faction = pathinfo($factionPng, PATHINFO_FILENAME); $heroes = []; foreach (glob($root . '/heroes/' . $faction . '/*.png') ?: [] as $heroPng) { $name = pathinfo($heroPng, PATHINFO_FILENAME); $heroes[] = [ 'name' => $name, 'portrait' => self::URL . '/heroes/' . rawurlencode($faction) . '/' . rawurlencode($name) . '.png', ]; } usort($heroes, fn($a, $b) => strcasecmp($a['name'], $b['name'])); $out[$faction] = [ 'logo' => self::URL . '/factions/' . rawurlencode($faction) . '.png', 'heroes' => $heroes, ]; } ksort($out); return $this->catalogCache = $out; } public function manifest(): array { $path = $this->manifestPath(); if (!is_file($path)) return []; $parsed = json_decode((string) @file_get_contents($path), true); return is_array($parsed) ? $parsed : []; } public function writeManifest(array $data): string { $path = $this->manifestPath(); @mkdir(dirname($path), 0775, true); file_put_contents( $path, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . "\n" ); return $path; } public function manifestPath(): string { return rtrim(config('rig.storage_data'), '/') . '/olden-era-manifest.json'; } }