.json: the game's title and the data files loaded ON DEMAND in the browser (big films / maps, // uploaded as playground private files under lazy//), with their size and hash (cache key), and the ALIS sources // of its scripts when /src/ has them (uploaded under lazy// too, without the src/ folder). // php tools/catalog.php "" <full data folder> [pattern of lazy files, default *.dat] [$_, $game, $title, $dir] = $argv + [null, null, null, null]; $pattern = $argv[4] ?? '*.dat'; if (!$game || !$dir || !is_dir($dir)) { fwrite(STDERR, "usage: php tools/catalog.php <game> <title> <data folder> [pattern]\n"); exit(1); } $files = []; foreach (glob(rtrim($dir, '/') . '/' . $pattern) as $f) { // only the films (FLI/FLC: magic 0xaf11 / 0xaf12 at offset 4) are big: the maps stay preloaded files $magic = unpack('v', (string) file_get_contents($f, false, null, 4, 2))[1] ?? 0; if ($magic !== 0xaf11 && $magic !== 0xaf12) { continue; } $files[strtolower(basename($f))] = [filesize($f), substr(hash_file('sha256', $f), 0, 16)]; } // the ALIS sources (src/*.als + *.res, tools/lang/decompile.php): the source and HD editions, loaded on demand too $sources = glob(rtrim($dir, '/') . '/src/*.{als,res}', GLOB_BRACE) ?: []; foreach ($sources as $f) { $files[strtolower(basename($f))] = [filesize($f), substr(hash_file('sha256', $f), 0, 16)]; } ksort($files); @mkdir(__DIR__ . '/../catalog'); file_put_contents(__DIR__ . "/../catalog/$game.json", json_encode(['title' => $title, 'sources' => $sources !== [], 'lazy' => $files], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n"); printf("%s: %d lazy files, %.1f MB\n", $game, count($files), array_sum(array_column($files, 0)) / 1048576);