From 69824f28bd70c0731bc07ff0ea317df598cde66b Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 21 May 2012 16:56:50 -0600 Subject: [PATCH] progress --- lib/Lacuna/DB/Result/Glyph.pm | 1 + lib/Lacuna/DB/Result/Map/Body/Planet.pm | 6 ++++-- lib/Lacuna/RPC/Building/Archaeology.pm | 16 +++++++++------- lib/Lacuna/Web/Admin.pm | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/Lacuna/DB/Result/Glyph.pm b/lib/Lacuna/DB/Result/Glyph.pm index e7eb4af1..5e25405f 100644 --- a/lib/Lacuna/DB/Result/Glyph.pm +++ b/lib/Lacuna/DB/Result/Glyph.pm @@ -5,6 +5,7 @@ use utf8; no warnings qw(uninitialized); extends 'Lacuna::DB::Result'; +__PACKAGE__->load_components('DynamicSubclass'); __PACKAGE__->table('glyph'); __PACKAGE__->add_columns( body_id => { data_type => 'int', is_nullable => 0 }, diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 5dfd81d4..c8e9282a 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -94,7 +94,7 @@ sub add_glyph { return $self->glyph; } else { - return $self->glyphs->new({ + return $self->glyph->new({ type => $type, body_id => $self->id, quantity => $num_add, @@ -104,13 +104,15 @@ sub add_glyph { sub use_glyph { my ($self, $glyph_id, $type, $num_used) = @_; + + $num_used = 1 unless (defined($num_used)); my $glyph = Lacuna->db->resultset('Lacuna::DB::Result::Glyph')->search({ id => $glyph_id, type => $type, body_id => $self->id, })->single; return 0 unless defined($glyph); - if ($glyph->{quantity} > $num_used) { + if ($glyph->quantity > $num_used) { my $sum = $self->glyph->quantity - $num_used; $self->glyph->quantity($sum); } diff --git a/lib/Lacuna/RPC/Building/Archaeology.pm b/lib/Lacuna/RPC/Building/Archaeology.pm index 6740543a..977c0487 100644 --- a/lib/Lacuna/RPC/Building/Archaeology.pm +++ b/lib/Lacuna/RPC/Building/Archaeology.pm @@ -29,11 +29,12 @@ sub get_glyphs { my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id); my @out; - my $glyphs = $building->body->glyphs; + my $glyphs = $building->body->glyph; while (my $glyph = $glyphs->next) { push @out, { id => $glyph->id, type => $glyph->type, + quantity => $glyph->quantity, }; } return { @@ -47,14 +48,15 @@ sub get_glyph_summary { my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id); - my $glyphs = $building->body->glyphs; - - my $glyph_summary = {}; + my @out; + my $glyphs = $building->body->glyph; while (my $glyph = $glyphs->next) { - $glyph_summary->{$glyph->type}++; + push @out, { + id => $glyph->id, + type => $glyph->type, + quantity => $glyph->quantity, + }; } - # sort - my @out = map { {name => $_, quantity => $glyph_summary->{$_}}} sort {$a cmp $b} keys %$glyph_summary; return { glyphs => \@out, diff --git a/lib/Lacuna/Web/Admin.pm b/lib/Lacuna/Web/Admin.pm index 947f19f7..b5384224 100644 --- a/lib/Lacuna/Web/Admin.pm +++ b/lib/Lacuna/Web/Admin.pm @@ -424,7 +424,7 @@ sub www_add_resources { sub www_view_glyphs { my ($self, $request, $body_id) = @_; $body_id ||= $request->param('body_id'); - my $glyphs = Lacuna->db->resultset('Lacuna::DB::Result::Glyphs')->search({ body_id => $body_id }, {order_by => ['type'] }); + my $glyphs = Lacuna->db->resultset('Lacuna::DB::Result::Glyph')->search({ body_id => $body_id }, {order_by => ['type'] }); my $out = '

View Glyphs

'; $out .= sprintf('Back To Body', $body_id); $out .= ''; -- 2.51.2
IdTypeAction