Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Format resource quantities with commas.

  • Loading branch information...
commit cd04cea9cbbf7e5294f37f086e9ee03bf003b759 1 parent 00ccbfa
T. Alexander Popiel authored
Showing with 17 additions and 9 deletions.
  1. +8 −0 Client.pm
  2. +9 −9 show_planet.pl
View
8 Client.pm
@@ -92,6 +92,14 @@ sub format_time {
sprintf("%4d-%02d-%02d %02d:%02d:%02d", @elems);
}
+sub format_bignum {
+ my $num = shift;
+ my $str = sprintf("%0.0f ", $num);
+ 1 while $str =~ s/(\d)(\d\d\d)(\D)/$1,$2$3/;
+ chop $str;
+ return $str;
+}
+
sub log_call {
my $api = shift;
my $message = shift;
View
18 show_planet.pl
@@ -81,11 +81,11 @@
print "Invalid after ".format_time($result->{_invalid})."\n";
print "Builds complete at ".format_time($build_end)."\n" if $build_end;
print "\n";
-printf ("Food : %8d / %8d, %6d/hour => %5s at %s\n", resource_info($result->{status}, "food"));
-printf ("Ore : %8d / %8d, %6d/hour => %5s at %s\n", resource_info($result->{status}, "ore"));
-printf ("Water : %8d / %8d, %6d/hour => %5s at %s\n", resource_info($result->{status}, "water"));
-printf ("Energy: %8d / %8d, %6d/hour => %5s at %s\n", resource_info($result->{status}, "energy"));
-printf ("Waste : %8d / %8d, %6d/hour => %5s at %s\n", resource_info($result->{status}, "waste"));
+printf ("Food : %14s / %14s, %12s/hour => %5s at %s\n", resource_info($result->{status}, "food"));
+printf ("Ore : %14s / %14s, %12s/hour => %5s at %s\n", resource_info($result->{status}, "ore"));
+printf ("Water : %14s / %14s, %12s/hour => %5s at %s\n", resource_info($result->{status}, "water"));
+printf ("Energy: %14s / %14s, %12s/hour => %5s at %s\n", resource_info($result->{status}, "energy"));
+printf ("Waste : %14s / %14s, %12s/hour => %5s at %s\n", resource_info($result->{status}, "waste"));
print "\n";
print "Buildings ($body->{building_count} of $body->{size}, with $body->{plots_available} remaining):";
# print "\nStorage:\n";
@@ -159,9 +159,9 @@ sub resource_info {
my $body = $status->{body};
my @list;
- push(@list, $body->{"${resource}_stored"});
- push(@list, $body->{"${resource}_capacity"});
- push(@list, $body->{"${resource}_hour"});
+ push(@list, Client::format_bignum($body->{"${resource}_stored"}));
+ push(@list, Client::format_bignum($body->{"${resource}_capacity"}));
+ push(@list, Client::format_bignum($body->{"${resource}_hour"}));
if ($list[2] == 0) {
push(@list, "stable");
push(@list, format_time($status->{_time}));
@@ -176,7 +176,7 @@ sub resource_info {
my $current = $body->{"${resource}_stored"} + $body->{"${resource}_hour"} * (time() - $status->{_time}) / 3600;
$current = 0 if $current < 0;
$current = $body->{"${resource}_capacity"} if $current > $body->{"${resource}_capacity"};
- unshift(@list, $current);
+ unshift(@list, Client::format_bignum($current));
return @list;
}
Please sign in to comment.
Something went wrong with that request. Please try again.