sc: rename showrange() to prepare for non-integer reuse
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 30 Jun 2015 18:47:09 +0000 (20:47 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 1 Jul 2015 17:32:34 +0000 (19:32 +0200)
sc.plp

diff --git a/sc.plp b/sc.plp
index a1dc143746ea42faa616059409d253a9793a4b90..5454b637d02d7e0f4f7d59d733df64d58ebdcc75 100644 (file)
--- a/sc.plp
+++ b/sc.plp
@@ -114,11 +114,15 @@ sub coltoggle {
 sub showrange {
        my ($min, $max) = @_;
        return '' if not defined $min;
 sub showrange {
        my ($min, $max) = @_;
        return '' if not defined $min;
-       $_ &&= int($_ + .5) for $min, $max;  # round halves up
        return $min || '-' if !$max or $min == $max;
        return "$min-$max";
 }
 
        return $min || '-' if !$max or $min == $max;
        return "$min-$max";
 }
 
+sub showrangeint {
+       $_ &&= int($_ + .5) for @_;  # round halves up
+       return showrange(@_);
+}
+
        sub showcost {
                my ($row, $unit) = @_;
                return join(' ',
        sub showcost {
                my ($row, $unit) = @_;
                return join(' ',
@@ -151,7 +155,7 @@ sub showrange {
                $out .= sprintf '<span title="%s">¤</span> ', showcost($attack, $row)
                        if $attack->{cost};
                $out .= sprintf('<small>%s× </small>',
                $out .= sprintf '<span title="%s">¤</span> ', showcost($attack, $row)
                        if $attack->{cost};
                $out .= sprintf('<small>%s× </small>',
-                       showrange($attack->{count}, $upattack->{count}),
+                       showrangeint($attack->{count}, $upattack->{count}),
                ) if $attack->{count} > 1;
                $out .= '<span class="unit-l" title="explosive">*</span>'
                        if $attack->{type} eq 'explosive';
                ) if $attack->{count} > 1;
                $out .= '<span class="unit-l" title="explosive">*</span>'
                        if $attack->{type} eq 'explosive';
@@ -169,7 +173,7 @@ sub showrange {
                        } join '_', @bonus),
                        join(', ', map {(
                                sprintf('+%s vs %s',
                        } join '_', @bonus),
                        join(', ', map {(
                                sprintf('+%s vs %s',
-                                       showrange(
+                                       showrangeint(
                                                $attack->{bonus}->{$_},
                                                $attack->{bonus}->{$_} + $attack->{bonus}->{"-$_"} * 3,
                                        ),
                                                $attack->{bonus}->{$_},
                                                $attack->{bonus}->{$_} + $attack->{bonus}->{"-$_"} * 3,
                                        ),
@@ -182,7 +186,7 @@ sub showrange {
                        if $attack->{type} eq 'projectile';
 
                $out .= sprintf '<span title="%s">', $attack->{name} if $attack->{name};
                        if $attack->{type} eq 'projectile';
 
                $out .= sprintf '<span title="%s">', $attack->{name} if $attack->{name};
-               $out .= showrange($damage, $maxdamage);
+               $out .= showrangeint($damage, $maxdamage);
                $out .= '</span>' if $attack->{name};
                $out .= sprintf('<span class="unit-splash" title="%s">%s</span>',
                        $attack->{splash} eq 'line' ? ('linear', '+') : ('splash', '⁜')
                $out .= '</span>' if $attack->{name};
                $out .= sprintf('<span class="unit-splash" title="%s">%s</span>',
                        $attack->{splash} eq 'line' ? ('linear', '+') : ('splash', '⁜')
@@ -191,7 +195,7 @@ sub showrange {
                $out .= '<td class="val hurt hurtrel">';
                if ($attack->{dps}) {
                        # precalculated dps, do not touch
                $out .= '<td class="val hurt hurtrel">';
                if ($attack->{dps}) {
                        # precalculated dps, do not touch
-                       $out .= showrange($attack->{dps}->[0],
+                       $out .= showrangeint($attack->{dps}->[0],
                                $upattack->{dps}->[-1] // $attack->{dps}->[-1]
                        );
                }
                                $upattack->{dps}->[-1] // $attack->{dps}->[-1]
                        );
                }
@@ -213,14 +217,14 @@ sub showrange {
                        }
                        $maxdamage *= ($upattack->{count} // $attack->{count} // 1)
                                    / ($upattack->{cooldown} // $attack->{cooldown});
                        }
                        $maxdamage *= ($upattack->{count} // $attack->{count} // 1)
                                    / ($upattack->{cooldown} // $attack->{cooldown});
-                       $out .= showrange($damage, $maxdamage);
+                       $out .= showrangeint($damage, $maxdamage);
                }
 
                $out .= '<td class="unit hurt-g">' . '▽' x !!($attack->{anti} & 1);
                $out .= '<td class="unit hurt-a">' . '△' x !!($attack->{anti} & 2);
 
                $out .= '<td class="val unit-range">' .
                }
 
                $out .= '<td class="unit hurt-g">' . '▽' x !!($attack->{anti} & 1);
                $out .= '<td class="unit hurt-a">' . '△' x !!($attack->{anti} & 2);
 
                $out .= '<td class="val unit-range">' .
-                       showrange($attack->{range}, $upattack->{range});
+                       showrangeint($attack->{range}, $upattack->{range});
 
                return $out;
        }
 
                return $out;
        }
@@ -303,14 +307,14 @@ sub showrange {
                                100 * $_->{shield} / $_->{hp}
                        ) : '<td colspan=2',
                        ' class="val unit-armor">' .
                                100 * $_->{shield} / $_->{hp}
                        ) : '<td colspan=2',
                        ' class="val unit-armor">' .
-                               showrange($_->{armor}, $_->{upgraded}->{armor}),
+                               showrangeint($_->{armor}, $_->{upgraded}->{armor}),
                        showattack($_, 0),
                        '<td class="val unit-sight">' . sprintf(
                                $_->{detect} ? '<strong class="unit-detect">%s</strong>' : '%s',
                        showattack($_, 0),
                        '<td class="val unit-sight">' . sprintf(
                                $_->{detect} ? '<strong class="unit-detect">%s</strong>' : '%s',
-                               showrange($_->{sight}, $_->{upgraded}->{sight})
+                               showrangeint($_->{sight}, $_->{upgraded}->{sight})
                        ),
                        '<td class="val unit-speed">' .
                        ),
                        '<td class="val unit-speed">' .
-                               showrange($_->{speed}, $_->{upgraded}->{speed}),
+                               showrangeint($_->{speed}, $_->{upgraded}->{speed}),
                        $_->{attr}->{jump}
                                && qq'<span class="unit unit-jump" title="$_->{attr}->{jump}">↕</span>',
                        '<td class="unit-magic">' . showmagic($_),
                        $_->{attr}->{jump}
                                && qq'<span class="unit unit-jump" title="$_->{attr}->{jump}">↕</span>',
                        '<td class="unit-magic">' . showmagic($_),