X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/de64283eddcfa5e620386896983841f47b1de8d4..84a63eb1d32b332d3b0b2cf290c35b2e0c8d8f07:/sc.plp diff --git a/sc.plp b/sc.plp index 45a9f7b..0a0f161 100644 --- a/sc.plp +++ b/sc.plp @@ -48,27 +48,22 @@ my $patch = shift @{$units} print "
Unit properties as seen or measured in $scver{name}\n$patch.\n
\n\n"; +sub addupgrade { + my ($ref, $increase) = @_; + if (ref $increase eq 'HASH') { + addupgrade(\${$ref}->{$_}, $increase->{$_}) for keys %{$increase}; + } + elsif (ref $increase eq 'ARRAY') { + addupgrade(\${$ref}->[$_], $increase->[$_]) for 0 .. $#{$increase}; + } + ${$ref} += $increase if $increase =~ /^-?[0-9.]+/; +} + for my $unit (@{$units}) { - for my $upgrade (@{ $unit->{upgrade} // $unit->{update} // [] }) { + for my $upgrade (@{ $unit->{upgrade} }) { 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; - } + addupgrade(\( $unit->{upgraded}->{$col} //= $unit->{$col} ), $increase); } } } @@ -102,43 +97,10 @@ sub coltoggle { <: sub showrange { my ($min, $max) = @_; - $_ = int($_ + .5) for $min, $max; # round halves up - return $min == $max ? $min : "$min-$max"; -} - -sub showval { - my ($row, @elements) = @_; - my ($min, $max); - - my $value = $row; - $value = ref $value eq 'HASH' ? $value->{$_} - : ref $value eq 'ARRAY' && $value->[$_] or last for @elements; - if (ref $value eq 'ARRAY') { - $min = $value->[0]; - $max = $value->[-1]; - } - else { - $min = $max = $value; - } - defined $min or return ''; - - if (my $increase = $row->{upgraded}) { - $increase = ref $increase eq 'HASH' ? $increase->{$_} - : ref $increase eq 'ARRAY' && $increase->[$_] or last for @elements; - $max = $increase if $increase; - } - - if ($elements[0] eq 'attack' and $elements[2] eq 'dps') {{ - my $attack = $row->{ $elements[0] }->[ $elements[1] ]; - my $type = $attack->{type} or next; - if ($type eq 'explosive') { - $min /= 2; - } - elsif ($type eq 'implosive') { - $min /= 4; - } - }} - return showrange($min, $max); + return '' if not defined $min; + $_ &&= int($_ + .5) for $min, $max; # round halves up + return $min if not defined $max or $min == $max; + return "$min-$max"; } sub showattack { @@ -146,32 +108,49 @@ sub showval { my $attack = $row->{attack}->[$area] or return '