From b09f7425afebfe27dfa0f5de0ecb9d64a4ad959a Mon Sep 17 00:00:00 2001 From: Mark Lemming Date: Sat, 10 Jan 2015 12:13:48 -0700 Subject: [PATCH] Happiness detail in body list. --- lib/Lacuna/Util.pm | 51 ++++++++++++++++++++++++++++++++++++++++- lib/Lacuna/Web/Admin.pm | 4 ++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/lib/Lacuna/Util.pm b/lib/Lacuna/Util.pm index 6aae3b5b..f1f371b1 100644 --- a/lib/Lacuna/Util.pm +++ b/lib/Lacuna/Util.pm @@ -6,7 +6,7 @@ use DateTime::Format::Duration; use DateTime::Format::Strptime; require Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(randint format_date random_element commify consolidate_items); +@EXPORT_OK = qw(randint format_date random_element commify consolidate_items kmbtq); sub format_date { @@ -36,6 +36,55 @@ sub commify { return scalar reverse $text; } +sub kmbtq { + my ($numb) = @_; + + $numb =~ tr/0-9//cd; + + if ($numb >= 100_000_000_000_000_000 || $numb <= -100_000_000_000_000_000) { +# 101Q + return int($numb/1_000_000_000_000_000).'Q'; + } + elsif ($numb >= 1_000_000_000_000_000 || $numb <= -1_000_000_000_000_000) { +# 83.4Q + return (int($numb/100_000_000_000_000) / 10).'Q'; + } + elsif ($numb >= 100_000_000_000_000 || $numb <= -100_000_000_000_000) { +# 101T + return int( $numb/1_000_000_000_000).'T'; + } + elsif ( $numb >= 1_000_000_000_000 || $numb <= -1_000_000_000_000) { +# 75.3T + return (int( $numb/100_000_000_000) / 10).'T'; + } + elsif ( $numb >= 100_000_000_000 || $numb <= -100_000_000_000) { +# 101B + return int( $numb/1_000_000_000).'B'; + } + elsif ( $numb >= 1_000_000_000 || $numb <= -1_000_000_000) { +# 75.3B + return (int( $numb/100_000_000) / 10).'B'; + } + elsif ( $numb >= 100_000_000 || $numb <= -100_000_000) { +# 101M + return int( $numb/1000000).'M'; + } + elsif ( $numb >= 1_000_000 || $numb <= -1_000_000) { +# 75.3M + return (int( $numb/100_000) / 10).'M'; + } + elsif ( $numb >= 10_000 || $numb <= -10_000) { +# 123k + return int( $numb/1_000).'k'; + } + else { +# 8765 + return int( $numb); + } + + return $numb; +} + sub consolidate_items { my ($item_arr) = @_; diff --git a/lib/Lacuna/Web/Admin.pm b/lib/Lacuna/Web/Admin.pm index c9a74450..e570268f 100644 --- a/lib/Lacuna/Web/Admin.pm +++ b/lib/Lacuna/Web/Admin.pm @@ -8,7 +8,7 @@ use Lacuna::Constants qw(FOOD_TYPES ORE_TYPES); use feature "switch"; use Module::Find; use UUID::Tiny ':std'; -use Lacuna::Util qw(format_date commify); +use Lacuna::Util qw(format_date commify kmbtq); use List::Util qw(sum); use Data::Dumper; use LWP::UserAgent; @@ -326,7 +326,7 @@ sub www_search_bodies { $out .= ''; while (my $body = $bodies->next) { $out .= sprintf('', - $body->id, $body->id, $body->name, $body->x, $body->y, $body->orbit, $body->zone, $body->star_id, $body->image_name, commify($body->happiness), + $body->id, $body->id, $body->name, $body->x, $body->y, $body->orbit, $body->zone, $body->star_id, $body->image_name, kmbtq($body->happiness), $body->empire_id || '', $body->empire_id || ''); } $out .= '
IdNameXYOZoneStarTypeHappinessEmpire
%s%s%s%s%s%s%s%s%s%s
'; -- 2.54.0