+
+function buildDiscover(array $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'])
+ );
+
+ $players = [
+ 1 => '1 player',
+ 2 => '2 players',
+ 3 => '3 players',
+ 4 => '4 players',
+ ];
+ addDiscoverRow($data, '# of players', $players);
+ foreach ($players as $num => $title) {
+ writeJson(
+ 'api/v1/discover-data/' . categoryPath($title) . '.json',
+ buildDiscoverCategory($title, filterByPlayers($games, $num))
+ );
+ }
+
+ $genres = getAllGenres($games);
+ sort($genres);
+ $genreChunks = array_chunk($genres, 4);
+ $first = true;
+ foreach ($genreChunks as $chunk) {
+ addDiscoverRow(
+ $data, $first ? 'Genres' : '',
+ $chunk
+ );
+ $first = false;
+ }
+
+ foreach ($genres as $genre) {
+ writeJson(
+ 'api/v1/discover-data/' . categoryPath($genre) . '.json',
+ buildDiscoverCategory($genre, filterByGenre($games, $genre))
+ );
+ }
+
+ 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)
+ );
+
+ usort(
+ $games,
+ function ($gameA, $gameB) {
+ return strcmp($gameB->title, $gameA->title);
+ }
+ );
+ $chunks = array_chunk($games, 4);
+ 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;
+}
+