From de64283eddcfa5e620386896983841f47b1de8d4 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Fri, 19 Jun 2015 02:23:59 +0200 Subject: [PATCH 1/1] sc: precalculate upgraded values Minimal change to prepare for code cleanup. --- sc.plp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/sc.plp b/sc.plp index 4fc00ba..45a9f7b 100644 --- a/sc.plp +++ b/sc.plp @@ -48,6 +48,31 @@ my $patch = shift @{$units} print "

Unit properties as seen or measured in $scver{name}\n$patch.\n

\n\n"; +for my $unit (@{$units}) { + for my $upgrade (@{ $unit->{upgrade} // $unit->{update} // [] }) { + while (my ($col, $increase) = each %{$upgrade}) { + defined $unit->{$col} or next; + + if (ref $increase eq 'ARRAY') { + for my $incrow (0 .. $#{$increase}) { + while (my ($inccol, $subinc) = each %{ $increase->[$incrow] }) { + $unit->{upgraded}->{$col}->[$incrow]->{$inccol} + //= ref $unit->{$col}->[$incrow]->{$inccol} + ? $unit->{$col}->[$incrow]->{$inccol}->[-1] + : $unit->{$col}->[$incrow]->{$inccol}; + $unit->{upgraded}->{$col}->[$incrow]->{$inccol} + += ref $subinc ? $subinc->[-1] : $subinc; + } + } + } + elsif ($increase =~ /^-?[0-9.]+/) { + $unit->{upgraded}->{$col} //= $unit->{$col}; + $unit->{upgraded}->{$col} += $increase; + } + } + } +} + sub coltoggle { my ($name, $id) = @_; return sprintf( @@ -97,14 +122,10 @@ sub showval { } defined $min or return ''; - if ($row->{upgrade}) { - for (@{ $row->{upgrade} }) { - my $increase = $_ or next; + if (my $increase = $row->{upgraded}) { $increase = ref $increase eq 'HASH' ? $increase->{$_} : ref $increase eq 'ARRAY' && $increase->[$_] or last for @elements; - $increase = $increase->[-1] if ref $increase eq 'ARRAY'; - $max += $increase if $increase; - } + $max = $increase if $increase; } if ($elements[0] eq 'attack' and $elements[2] eq 'dps') {{ -- 2.30.0