Add a simple developer page that lists all games by this developer
authorChristian Weiske <cweiske@cweiske.de>
Sun, 27 Dec 2020 12:29:11 +0000 (13:29 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Sun, 27 Dec 2020 12:29:28 +0000 (13:29 +0100)
Resolves: https://github.com/ouya-saviors/ouya-game-data/issues/108

bin/build-html.php
bin/import-game-data.php
data/templates/game.tpl.php

index c00f811cef8a6ebbb65575d29830375a6ba6bba5..faefdb97d53b53163b9207c8f3005119b19690cf 100755 (executable)
@@ -167,6 +167,14 @@ function renderGameFile($gameDataFile)
         $apkDownloadUrl = null;
     }
     */
+    $developerDetailsUrl = null;
+    if (isset($json->developer->url) && $json->developer->url) {
+        $developerDetailsUrl = '../discover/' . str_replace(
+            'ouya://launcher/discover/',
+            '',
+            $json->developer->url
+        ) . '.htm';
+    }
 
     $internetArchiveUrl = $json->stouyapi->{'internet-archive'} ?? null;
     $developerUrl       = $json->stouyapi->{'developer-url'} ?? null;
index b6c1917783d428ebee19c714fb993301dcf44d35..c0b500c18198d86d22826a6344c319f122453b60 100755 (executable)
@@ -46,6 +46,8 @@ foreach (file($foldersFile) as $line) {
 $games = [];
 $count = 0;
 $developers = [];
+
+//load game data. doing early to collect a developer's games
 foreach ($gameFiles as $gameFile) {
     $game = json_decode(file_get_contents($gameFile));
     if ($game === null) {
@@ -54,18 +56,18 @@ foreach ($gameFiles as $gameFile) {
     addMissingGameProperties($game);
     $games[$game->packageName] = $game;
 
-    writeJson(
-        'api/v1/details-data/' . $game->packageName . '.json',
-        buildDetails($game)
-    );
-
     if (!isset($developers[$game->developer->uuid])) {
         $developers[$game->developer->uuid] = [
-            'info'     => $game->developer,
-            'products' => [],
+            'info'      => $game->developer,
+            'products'  => [],
+            'gameNames' => [],
         ];
     }
+    $developers[$game->developer->uuid]['gameNames'][] = $game->packageName;
+}
 
+//write json api files
+foreach ($games as $game) {
     $products = $game->products ?? [];
     foreach ($products as $product) {
         writeJson(
@@ -76,7 +78,14 @@ foreach ($gameFiles as $gameFile) {
         $developers[$game->developer->uuid]['products'][] = $product;
     }
 
-    /**/
+    writeJson(
+        'api/v1/details-data/' . $game->packageName . '.json',
+        buildDetails(
+            $game,
+            count($developers[$game->developer->uuid]['gameNames']) > 1
+        )
+    );
+
     writeJson(
         'api/v1/games/' . $game->packageName . '/purchases',
         buildPurchases($game)
@@ -116,6 +125,16 @@ foreach ($developers as $developer) {
         . '/current_gamer',
         buildDeveloperCurrentGamer()
     );
+
+    if (count($developer['gameNames']) > 1) {
+        writeJson(
+            'api/v1/discover-data/dev--' . $developer['info']->uuid . '.json',
+            buildSpecialCategory(
+                'Developer: ' . $developer['info']->name,
+                filterByPackageNames($games, $developer['gameNames'])
+            )
+        );
+    }
 }
 
 writeJson('api/v1/discover-data/discover.json', buildDiscover($games));
@@ -277,6 +296,11 @@ function buildMakeCategory($name, $games)
     return $data;
 }
 
+/**
+ * Category without the "Last updated" or "Best rated" top rows
+ *
+ * Used for "Best rated", "Most rated", "Random"
+ */
 function buildSpecialCategory($name, $games)
 {
     $data = [
@@ -412,7 +436,7 @@ function buildProduct($product)
 /**
  * Build /app/v1/details?app=org.example.game
  */
-function buildDetails($game)
+function buildDetails($game, $linkDeveloperPage = false)
 {
     $latestRelease = $game->latestRelease;
 
@@ -468,7 +492,7 @@ function buildDetails($game)
     }
 
     // http://cweiske.de/ouya-store-api-docs.htm#get-https-devs-ouya-tv-api-v1-details
-    return [
+    $data = [
         'type'             => 'Game',
         'title'            => $game->title,
         'description'      => $game->description,
@@ -531,6 +555,13 @@ function buildDetails($game)
             'developer-url'    => $game->developer->website ?? null,
         ]
     ];
+
+    if ($linkDeveloperPage) {
+        $data['developer']['url'] = 'ouya://launcher/discover/dev--'
+            . categoryPath($game->developer->uuid);
+    }
+
+    return $data;
 }
 
 function buildDeveloperCurrentGamer()
index 4f7779e2f4d13d0f6452440cb77683c53d1b3455..70c2a677e6afb58d30b0947da1a311c5315a3be7 100644 (file)
     <a href="<?= $internetArchiveUrl ?>">Internet Archive</a>
    </div>
    <?php endif ?>
+   <?php if ($developerDetailsUrl): ?>
+   <div>
+    <a href="<?= $developerDetailsUrl ?>">Developer page</a>
+   </div>
+   <?php endif ?>
    <?php if ($appsJson->app->website): ?>
    <div>
     <a href="<?= $appsJson->app->website ?>">Game website</a>