+//make
+writeJson(
+ 'api/v1/discover-data/tutorials.json',
+ buildMakeCategory('Tutorials', filterByGenre($games, 'Tutorials'))
+);
+
+$searchLetters = 'abcdefghijklmnopqrstuvwxyz0123456789., ';
+foreach (str_split($searchLetters) as $letter) {
+ $letterGames = filterBySearchWord($games, $letter);
+ writeJson(
+ 'api/v1/search-data/' . $letter . '.json',
+ buildSearch($letterGames)
+ );
+}
+
+
+function buildDiscover(array $games)
+{
+ $games = removeMakeGames($games);
+ $data = [
+ 'title' => 'DISCOVER',
+ 'rows' => [],
+ 'tiles' => [],
+ ];
+
+ addDiscoverRow(
+ $data, 'Last Updated',
+ filterLastUpdated($games, 10)
+ );
+ addDiscoverRow(
+ $data, 'Best rated',
+ filterBestRated($games, 10)
+ );
+ addDiscoverRow(
+ $data, "cweiske's picks",
+ filterByPackageNames($games, $GLOBALS['packagelists']['cweiskepicks'])
+ );
+
+ addDiscoverRow(
+ $data, 'Special',
+ [
+ 'Best rated',
+ 'Most rated',
+ 'Random',
+ ]
+ );
+ writeJson(
+ 'api/v1/discover-data/' . categoryPath('Best rated') . '.json',
+ buildSpecialCategory('Best rated', filterBestRated($games, 99))
+ );
+ writeJson(
+ 'api/v1/discover-data/' . categoryPath('Most rated') . '.json',
+ buildSpecialCategory('Most rated', filterMostDownloaded($games, 99))
+ );
+ writeJson(
+ 'api/v1/discover-data/' . categoryPath('Random') . '.json',
+ buildSpecialCategory(
+ 'Random ' . date('Y-m-d H:i'),
+ filterRandom($games, 99)
+ )
+ );
+
+ $players = [
+ //1 => '1 player',
+ 2 => '2 players',
+ 3 => '3 players',
+ 4 => '4 players',
+ ];
+ addDiscoverRow($data, 'Multiplayer', $players);
+ foreach ($players as $num => $title) {
+ writeJson(
+ 'api/v1/discover-data/' . categoryPath($title) . '.json',
+ buildDiscoverCategory($title, filterByPlayers($games, $num))
+ );
+ }
+
+ $ages = getAllAges($games);
+ natsort($ages);
+ addDiscoverRow($data, 'Content rating', $ages);
+ foreach ($ages as $num => $title) {
+ writeJson(
+ 'api/v1/discover-data/' . categoryPath($title) . '.json',
+ buildDiscoverCategory($title, filterByAge($games, $title))
+ );
+ }
+
+ $genres = removeMakeGenres(getAllGenres($games));
+ sort($genres);
+ addChunkedDiscoverRows($data, $genres, 'Genres');
+
+ foreach ($genres as $genre) {
+ writeJson(
+ 'api/v1/discover-data/' . categoryPath($genre) . '.json',
+ buildDiscoverCategory($genre, filterByGenre($games, $genre))
+ );
+ }
+
+ $abc = array_merge(range('A', 'Z'), ['Other']);
+ addChunkedDiscoverRows($data, $abc, 'Alphabetical');
+ foreach ($abc as $letter) {
+ writeJson(
+ 'api/v1/discover-data/' . categoryPath($letter) . '.json',
+ buildDiscoverCategory($letter, filterByLetter($games, $letter))
+ );
+ }
+
+ return $data;
+}
+
+/**
+ * A genre category page
+ */
+function buildDiscoverCategory($name, $games)
+{
+ $data = [
+ 'title' => $name,
+ 'rows' => [],
+ 'tiles' => [],
+ ];
+ addDiscoverRow(
+ $data, 'Last Updated',
+ filterLastUpdated($games, 10)
+ );
+ addDiscoverRow(
+ $data, 'Best rated',
+ filterBestRated($games, 10)
+ );
+
+ $games = sortByTitle($games);
+ $chunks = array_chunk($games, 4);
+ foreach ($chunks as $chunkGames) {
+ addDiscoverRow($data, '', $chunkGames);
+ }
+
+ return $data;
+}
+
+function buildMakeCategory($name, $games)
+{
+ $data = [
+ 'title' => $name,
+ 'rows' => [],
+ 'tiles' => [],
+ ];
+
+ $games = sortByTitle($games);
+ addDiscoverRow($data, '', $games);
+
+ return $data;
+}
+
+function buildSpecialCategory($name, $games)
+{
+ $data = [
+ 'title' => $name,
+ 'rows' => [],
+ 'tiles' => [],
+ ];
+
+ $first3 = array_slice($games, 0, 3);
+ $chunks = array_chunk(array_slice($games, 3), 4);
+ array_unshift($chunks, $first3);
+
+ foreach ($chunks as $chunkGames) {
+ addDiscoverRow($data, '', $chunkGames);
+ }
+
+ return $data;
+}
+
+function buildDiscoverHome(array $games)
+{
+ //we do not want anything here for now
+ $data = [
+ 'title' => 'home',
+ 'rows' => [
+ [
+ 'title' => 'FEATURED',
+ 'showPrice' => false,
+ 'ranked' => false,
+ 'tiles' => [],
+ ]
+ ],
+ 'tiles' => [],
+ ];
+ return $data;
+}
+