package] = $gameData; } return $games; } /** * Convert a meta data game info into a structure that is suitable * for http://l2.gamestickservices.net/api/rest/connect/stick/stick/xxx/view.json */ function convertGameDataForConnect($gameData): array { $userCurrency = 'EUR'; $connectData = [ 'id' => $gameData->id, 'package' => $gameData->package, 'name' => $gameData->name, 'description' => $gameData->description, 'minAge' => $gameData->minAge, 'genre' => current($gameData->genres), 'genres' => $gameData->genres, 'version' => '', 'gameversion' => '0', 'size' => 0, 'download' => [ 'url' => '', 'version' => 0, ], 'popular' => 0, 'featured' => 0, 'bought' => true, 'downloadedfree' => false, 'pricing' => [ 'buy' => [ 'price' => $userCurrency . ' ' . $gameData->prices->buy->$userCurrency->amount, ], 'rent' => [], ], 'multipricing' => [ 'buy' => [], 'rent' => [], ], 'images' => [], 'videos' => [], 'social' => [], 'companyname' => $gameData->companyname, 'companylogofile' => '', 'companyiconsize' => 0, ]; //multipricing foreach ($gameData->prices->buy as $currencySymbol => $price) { $connectData['multipricing']['buy'][] = [ 'amount' => $price->amount, 'isocurrency' => $currencySymbol, 'symbol' => $price->symbol, 'symbolpostindex' => $price->symbolpostindex, 'formattedcurrency' => $price->formattedcurrency, ]; } //download $highestVersionCode = 0; $highestVersionKey = null; foreach ($gameData->releases as $releaseKey => $release) { if (isset($release->broken) && $release->broken === true) { continue; } if ($release->versionCode > $highestVersionCode) { $highestVersionKey = $releaseKey; } } if ($highestVersionKey !== null) { $release = $gameData->releases[$highestVersionKey]; $connectData['version'] = $release->uuid; $connectData['gameversion'] = $release->gsName ?? $release->name; $connectData['size'] = round($release->size / 1024 / 1024 * 1000); $connectData['download'] = [ 'url' => $release->url, 'version' => $release->gsVersion, ]; } foreach ($gameData->videos as $videoNum => $video) { $connectData['videos'][] = [ 'version' => $video->version, 'url' => $video->url, ]; $connectData['images'][] = [ 'urls' => [ [ 'url' => $video->thumb, 'version' => 1, ] ], 'name' => 'STICK_VIDEO' . ($videoNum + 1) . '_SCREENSHOT', 'width' => 350, 'height' => 160, ]; } $imageNameMap = [ 'logo-1' => [ 'name' => 'STICK_THUMBNAIL1', 'width' => 350, 'height' => 400, ], 'logo-2' => [ 'name' => 'STICK_THUMBNAIL4', 'width' => 350, 'height' => 400, ], 'logo-3' => [ 'name' => 'STICK_THUMBNAIL4', 'width' => 350, 'height' => 400, ], 'logo-4' => [ 'name' => 'STICK_THUMBNAIL4', 'width' => 350, 'height' => 400, ], 'logo-1-big' => [ 'name' => 'STICK_THUMBNAIL1_1080', 'width' => 525, 'height' => 240, ], 'logo-2-big' => [ 'name' => 'STICK_THUMBNAIL2_1080', 'width' => 525, 'height' => 240, ], 'logo-3-big' => [ 'name' => 'STICK_THUMBNAIL3_1080', 'width' => 525, 'height' => 240, ], 'logo-4-big' => [ 'name' => 'STICK_THUMBNAIL4_1080', 'width' => 525, 'height' => 240, ], 'icon-registration' => [ 'name' => 'STICK_REGISTRATION_GAME_ICON', 'width' => 200, 'height' => 200, ], 'icon' => [ 'name' => 'STICK_ICON', 'width' => 85, 'height' => 48, ], 'screenshots' => [ 'name' => 'STICK_SCREENSHOT', 'width' => 350, 'height' => 160, ], 'screenshots-big' => [ 'name' => 'STICK_SCREENSHOT_1080', 'width' => 525, 'height' => 240, ], ]; foreach ($gameData->images as $imageKey => $imageData) { if (!isset($imageNameMap[$imageKey])) { throw new \Exception('Unknown image key: ' . $imageKey); } if ($imageData === null) { continue; } $connectImage = [ 'name' => $imageNameMap[$imageKey]['name'], 'width' => $imageNameMap[$imageKey]['width'], 'height' => $imageNameMap[$imageKey]['height'], ]; $urls = (array) $imageData; foreach ($urls as $imageUrl) { $connectImage['urls'][] = [ 'url' => $imageUrl, 'version' => 1, ]; } $connectData['images'][] = $connectImage; } return $connectData; }