jargon

Linedancer :: "menuGenerator.php"

Sep 7th, 2024
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.54 KB | Gaming | 0 0
  1. <?php
  2. // Shared :: "menuGenerator.php"
  3.  
  4. include_once("{$GENERATOR_PATH}filter releases.php");
  5.  
  6. include_once("{$GENERATOR_PATH}iconGenerator.php");
  7.  
  8. foreach(['meta','css','js'] as $obj){
  9.     $$obj = "";
  10. }
  11.  
  12. $list = [];
  13. $allReleases = [];
  14. $allGames = [];
  15.  
  16. // Fetch the releases
  17. $releases = explode("\r\n", file_get_contents("http://{$_SERVER['HTTP_HOST']}/Shared/scripts/php/Generators/listGenerator.php?release="));
  18.  
  19. // Collect all games and releases
  20. foreach ($releases as $release) {
  21.    
  22.     $parts = uriParts($release);
  23.     $releaseName = isset($parts['release']) ? $parts['release'] : '';
  24.    
  25.     $js .= "console.log(`Processed: \"{$releaseName}\"`)";
  26.  
  27.     // Store release names
  28.     $allReleases[] = $releaseName;
  29.  
  30.     $games = explode("\r\n", file_get_contents("http://{$_SERVER['HTTP_HOST']}/Shared/scripts/php/Generators/listGenerator.php?release={$releaseName}"));
  31.  
  32.     foreach ($games as $game) {    
  33.         $parts = uriParts($game);
  34.         $gameName = isset($parts['game']) ? $parts['game'] : '';
  35.        
  36.         $js .= "console.log(`Processed: \"{$gameName} ({$releaseName})\"`)";
  37.  
  38.         // Store game names
  39.         $allGames[] = $gameName;
  40.  
  41.         // Structure list as [gameName => [release1, release2, ...]]
  42.         if (!isset($list[$gameName])) {
  43.             $list[$gameName] = [];
  44.         }
  45.         $list[$gameName][] = $releaseName;
  46.     }
  47. }
  48.  
  49. // Remove duplicates from releases and games arrays
  50. $allReleases = array_unique($allReleases);
  51. $allGames = array_unique($allGames);
  52.  
  53. $allReleases = filter($allReleases);
  54. $allGames = filter($allGames);
  55.  
  56. $menu = "";
  57. $xouterspan = 150;
  58. $youterspan = 100; // Increase this value to add more space between rows
  59. $xinnerspan = 128;
  60. $yinnerspan = 64;
  61. $ratio = 0.18;
  62.  
  63. $x = 0;
  64. $y = 0; // Start y-position at 0
  65.  
  66. // First row, first column should be "Main" with Main.png icon
  67. $mainIcon = "http://{$_SERVER['HTTP_HOST']}/Shared/assets/Sprites/generated/Main.png";
  68. $menu .= "<div style=\"position: absolute; left: 0px; top: 0px; width: {$xinnerspan}px; height: {$yinnerspan}px; display: flex; align-items: center; justify-content: center; text-align: center; font-family: Impact; font-size: calc({$xinnerspan}px * {$ratio});\">";
  69. $menu .= "<img style=\"max-width: 100%; max-height: 100%; object-fit: contain;\" src=\"{$mainIcon}\" alt=\"Main\">";
  70. $menu .= "</div>";
  71.  
  72. // Render release headers starting from the second column
  73. foreach ($allReleases as $releaseIndex => $releaseName) {
  74.     $x = ($releaseIndex + 1) * $xouterspan; // Position for each release
  75.  
  76.     $releaseIcon = "http://{$_SERVER['HTTP_HOST']}/Shared/assets/Sprites/generated/{$releaseName}.png";
  77.    
  78.     // Display release name and icon
  79.     $menu .= "<div style=\"position: absolute; left: {$x}px; top: {$y}px; width: {$xinnerspan}px; height: {$yinnerspan}px; display: flex; align-items: center; justify-content: center; text-align: center; font-family: Impact; font-size: calc({$xinnerspan}px * {$ratio});\">";
  80.     $menu .= "<img style=\"max-width: 100%; max-height: 100%; object-fit: contain;\" src=\"{$releaseIcon}\" alt=\"{$releaseName}\">";
  81.     $menu .= "</div>";
  82. }
  83.  
  84. $y += $youterspan; // Move down to start the game rows
  85.  
  86. // Render games and their presence under each release
  87. foreach ($allGames as $gameIndex => $gameName) {
  88.     $x = 0; // Reset x-position for each game row
  89.  
  90.     // Display the game name in the first column
  91.     $menu .= "<div style=\"position: absolute; left: {$x}px; top: {$y}px; width: {$xinnerspan}px; height: {$yinnerspan}px; display: flex; align-items: center; justify-content: center; text-align: center; font-family: Impact; font-size: calc({$xinnerspan}px * {$ratio});\">";
  92.     $menu .= "<div>{$gameName}</div></div>";
  93.  
  94.     foreach ($allReleases as $releaseIndex => $releaseName) {
  95.         $x = ($releaseIndex + 1) * $xouterspan; // Position for each release column
  96.  
  97.         // Check if this game = part of the current release
  98.         if (in_array($releaseName, $list[$gameName])) {
  99.            
  100.             $js .= "console.log(`Processed: \"{$gameName} ({$releaseName})\" (in Menu)`)";
  101.  
  102.             if(is_file("{$_SERVER['DOCUMENT_ROOT']}/Shared/assets/Sprites/icon/{$gameName}.png")){
  103.                 $icon = "/Shared/assets/Sprites/icon/{$gameName}.png";
  104.             }elseif($gameName!==""){
  105.                 $icon = "/Shared/assets/Sprites/generated/{$releaseName} {$gameName}.png";
  106.             }else{
  107.                 continue;
  108.             }
  109.            
  110.             $menu .= "<div style=\"position: absolute; left: {$x}px; top: {$y}px; width: {$xinnerspan}px; height: {$yinnerspan}px; display: flex; align-items: center; justify-content: center; text-align: center; font-family: Impact; font-size: calc({$xinnerspan}px * {$ratio});\">";
  111.             $menu .= "<a href=\"http://{$_SERVER['HTTP_HOST']}/?release={$releaseName}&game={$gameName}\">";
  112.            
  113.             $embedded = embedIcon($icon);
  114.            
  115.             $menu .= "<img style=\"max-width: 100%; max-height: 100%; object-fit: contain;\" src=\"{$embedded}\" alt=\"{$releaseName}: {$gameName}\">";
  116.             $menu .= "</a></div>";
  117.         }
  118.     }
  119.  
  120.     $y += $youterspan; // Move down for the next game row
  121. }
  122.  
  123. $pagedata = file_get_contents("{$_SERVER['DOCUMENT_ROOT']}/Shared/scripts/html/menu.html");
  124. include_once("{$GENERATOR_PATH}styles.php");
  125.  
  126. $pagedata = styles($pagedata);
  127.  
  128. $html = $menu;
  129.  
  130. foreach(['meta','css','js'] as $obj){
  131.     if(is_file("{$_SERVER['DOCUMENT_ROOT']}/Shared/scripts/{$obj}/menu.{$obj}")){
  132.         $$obj .= file_get_contents("{$_SERVER['DOCUMENT_ROOT']}/Shared/scripts/{$obj}/menu.{$obj}");
  133.     }
  134. }
  135.  
  136. foreach(['html','meta','css','js'] as $obj){
  137.     $pagedata = str_replace("{{ {$obj} }}", $$obj, $pagedata);
  138. }
  139.  
  140. echo $pagedata;
  141. exit;
  142.  
  143. function embedIcon($icon){
  144.    
  145.     return
  146.         "data:image/png;base64,".
  147.         str_replace("=","",
  148.         base64_encode(
  149.                 file_get_contents(
  150.                     $_SERVER["DOCUMENT_ROOT"].
  151.                     $icon
  152.                 )
  153.             )
  154.         );
  155. }
Add Comment
Please, Sign In to add comment