sc: precalculate upgraded values
[sheet.git] / sc.plp
diff --git a/sc.plp b/sc.plp
index 4fc00ba3241375c1178a9c4795e19eb38aa8e068..45a9f7b4a8c8fd79bf55a9260620f4b6f19b7829 100644 (file)
--- a/sc.plp
+++ b/sc.plp
@@ -48,6 +48,31 @@ my $patch = shift @{$units}
 
 print "<p>Unit properties as seen or measured in $scver{name}\n$patch.\n</p>\n\n";
 
 
 print "<p>Unit properties as seen or measured in $scver{name}\n$patch.\n</p>\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(
 sub coltoggle {
        my ($name, $id) = @_;
        return sprintf(
@@ -97,14 +122,10 @@ sub showval {
        }
        defined $min or return '';
 
        }
        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 = 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') {{
        }
 
        if ($elements[0] eq 'attack' and $elements[2] eq 'dps') {{