Skip to content

Commit 5e71e1a

Browse files
committed
Compat: Deduplicate changelog information on dropdown
1 parent 458b866 commit 5e71e1a

File tree

2 files changed

+40
-43
lines changed

2 files changed

+40
-43
lines changed

classes/class.Compat.php

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -529,68 +529,60 @@ public static function printTable() : void
529529
echo "<input type=\"checkbox\" id=\"compat-table-checkbox-{$game->key}\">";
530530
echo "<div class=\"compat-table-row compat-table-dropdown\">";
531531

532-
533-
// TODO: Better printing of dropdown contents
532+
// Update information
533+
$changelog = "";
534534
$has_updates = false;
535535

536536
foreach ($game->game_item as $item)
537537
{
538538
foreach ($item->tags as $tag)
539539
{
540540
if ($has_updates)
541-
echo "<hr>";
542-
543-
$has_updates = true;
544-
$patchset = substr($tag->tag_id, 10);
545-
546-
echo "<p>Available updates for <b>{$item->game_id}</b>, latest patchset {$patchset}:<br>";
541+
print("<hr>");
542+
else
543+
$has_updates = true;
544+
545+
printf("<p>Available updates for <b>%s</b>, latest patchset %s:<br>",
546+
$item->game_id,
547+
substr($tag->tag_id, 10));
547548

548549
foreach ($tag->packages as $package)
549550
{
550-
$size_mb = round($package->size / 1024 / 1024, 2);
551-
echo "- <b>Update v{$package->version}</b> ({$size_mb} MB)<br>";
551+
printf("- <b>Update v%s</b> (%.2f MB)<br>",
552+
$package->version,
553+
$package->get_size_mb());
552554

553-
$changelog = $package->get_main_changelog();
554-
555-
if (!is_null($changelog))
555+
if (!is_null($package->get_main_changelog()) &&
556+
!str_contains($changelog, $package->get_main_changelog()))
556557
{
557-
echo "<br>";
558-
echo "<i>";
559-
560-
$changelog = mb_ereg_replace("\r?\n|\r", '<br>', $changelog);
561-
562-
if (!$changelog)
563-
{
564-
continue;
565-
}
566-
567-
if (str_contains($changelog, "<br><br><br>"))
568-
{
569-
$changelog = mb_ereg_replace("<br><br><br>", "<br><br>", $changelog);
570-
571-
if (!$changelog)
572-
{
573-
continue;
574-
}
575-
}
576-
577-
if (substr($changelog, -4) === "<br>")
578-
{
579-
$changelog = substr($changelog, 0, -4);
580-
}
581-
582-
echo $changelog;
583-
echo "</i>";
558+
$changelog .= $package->get_main_changelog();
584559
}
585560
}
586561

587-
echo "</p>";
562+
print("</p>");
588563
}
589564
}
590565

591-
if (!$has_updates)
566+
if (!empty($changelog))
567+
{
568+
print("<br>");
569+
570+
// Replace DOS/Unix line-breaks with HTML line-breaks
571+
$changelog = mb_ereg_replace("\r?\n|\r", '<br>', $changelog);
572+
while (str_contains($changelog, "<br><br>"))
573+
{
574+
$changelog = mb_ereg_replace("<br><br>", "<br>", $changelog);
575+
}
576+
while (str_ends_with($changelog, "<br>"))
577+
{
578+
$changelog = substr($changelog, 0, -4);
579+
}
580+
581+
printf("<i>%s</i>", $changelog);
582+
}
583+
else if (!$has_updates)
592584
{
593-
echo "<p>This game entry contains no available game updates</p>";
585+
print("<p>This game entry contains no available game updates</p>");
594586
}
595587

596588
echo "</div>";

objects/GameUpdatePackage.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,9 @@ public function get_main_changelog() : ?string
6262
}
6363
return null;
6464
}
65+
66+
public function get_size_mb() : float
67+
{
68+
return $this->size / 1024 / 1024;
69+
}
6570
}

0 commit comments

Comments
 (0)