forked from muldjord/skyscraper
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmap_screenscraper_cpp_to_json.php
More file actions
17 lines (17 loc) · 965 Bytes
/
map_screenscraper_cpp_to_json.php
File metadata and controls
17 lines (17 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
/**
* Parses the src/screenscraper.cpp file building a list of platforms with thie r corrisponding screenscraper id
* It then writes a screenscraper.json to replace the existing one for the JSON backed list+options instead of CPP hardcoded list
*/
$platforms = [];
preg_match_all('/if\s*\(\s*platform\s*==\s*"(?P<platform>[^"]*)"\s*\)\s*\{\n\s*return\s+"(?P<id>[^"]*)"\s*;/msuU', file_get_contents(__DIR__.'/../src/screenscraper.cpp'), $matches);
foreach ($matches['platform'] as $idx => $platform) {
$id = $matches['id'][$idx];
$platforms[] = json_encode(['name' => $platform, 'id' => is_numeric($id) ? (int)$id : $id], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
usort($platforms, function ($a, $b) {
return json_decode($a, true)['name'] <=> json_decode($b, true)['name'];
});
$json = "{\n\t\"platforms\":\n\t[\n\t\t".implode(",\n\t\t", $platforms)."\n\t]\n}";
echo $json;
file_put_contents(__DIR__.'/../screenscraper_new.json', $json);