sc: read version number from data include
[sheet.git] / sc.plp
diff --git a/sc.plp b/sc.plp
index 71742280006ea0099aa6b83734bba153a15e7ac8..13248fbb256afea92f25b287db48f48b14e01bd5 100644 (file)
--- a/sc.plp
+++ b/sc.plp
@@ -1,36 +1,53 @@
 <(common.inc.plp)><:
 
-my $datafile = 'sc-units.inc.pl';
+my %scver = (
+       id => 'bw',
+       name => 'Brood War',
+       title => 'starcraft',
+       game => 'StarCraft',
+       major => 1,
+);
+
 if ($ENV{PATH_INFO} and $ENV{PATH_INFO} eq '/2') {
-       $datafile = 'sc2-units.inc.pl';
+       %scver = (
+               id => 'hots',
+               name => 'Heart of the Swarm',
+               title => 'starcraft2',
+               game => 'StarCraft II',
+               major => 2,
+       );
 }
+my $datafile = "sc-units-$scver{id}.inc.pl";
 
 Html({
-       title => 'starcraft unit cheat sheet',
-       version => 'v1.0',
+       title => "$scver{title} unit cheat sheet",
+       version => 'v1.1',
        description => [
-               'Reference of StarCraft unit properties,'
-               . ' comparing various statistics of all the units in Brood War'
+               "Reference of $scver{game} unit properties,"
+               . " comparing various statistics of all the units in $scver{name}"
                . ' including costs, damage, defense, speed, ranges, and abilities.',
        ],
-       keywords => [qw'
+       keywords => [
+               qw'
                starcraft game unit statistics stats comparison table sheet cheat
                reference software attributes properties
-       '],
+               ',
+               $scver{major} < 2 ? qw' bw broodwar brood war ' : qw' starcraft2 hots ',
+       ],
        stylesheet => [qw'light'],
        raw => '<link rel="stylesheet" type="text/css" media="all" href="/sc.css?1.1" title="light">',
        data => [$datafile],
 });
 
-:>
-<h1>StarCraft units</h1>
+print "<h1>$scver{game} units</h1>\n\n";
 
-<p>
-Unit properties as seen or measured in Brood War
-<span title="no known changes as of v1.16.1">versionā‰„1.08</span>.
-</p>
+my $units = do $datafile;
+die "Cannot open unit data: $_\n" for $@ || $! || ();
+my $patch = shift @{$units}
+       or die "Cannot open unit data: metadata not found\n";
+
+print "<p>Unit properties as seen or measured in $scver{name}\n$patch.\n</p>\n\n";
 
-<:
 sub coltoggle {
        my ($name, $id) = @_;
        return sprintf(
@@ -200,8 +217,6 @@ sub showval {
                );
        }
 
-       my $units = do $datafile;
-       die "Cannot open unit data: $_\n" for $@ || $! || ();
        my $grouped = 1;  # race headers
        if (exists $get{order}) {
                $grouped = 0;