Permalink
Browse files

advanced to cope with introduction of new games

  • Loading branch information...
1 parent 391aeb5 commit 1e1830237bd49ebbe5d079671fbee87bde7f0c4a @polettix committed Oct 1, 2012
Showing with 17 additions and 6 deletions.
  1. +13 −5 lib/Narsil/Frontend.pm
  2. +1 −0 views/index.tt
  3. +1 −1 views/match.tt
  4. +2 −0 views/mobile/index.tt
@@ -55,7 +55,7 @@ sub rest_uri_for {
sub rest_call {
my ($method, $path, $params) = @_;
my $is_get = uc($method) eq 'GET';
- my $uri = rest_uri_for($path, ($is_get ? $params : undef));
+ my $uri = $path =~ m{^http} ? $path : rest_uri_for($path, ($is_get ? $params : undef));
$params = undef if $is_get;
my $response = agent()->$method($uri, $params ? $params : ());
my $retval;
@@ -124,6 +124,7 @@ get '/' => sub {
availables => $availables,
waiting => $waiting,
string => to_json($waiting),
+ string => to_json($matches),
games => $games,
users => $users
};
@@ -218,18 +219,25 @@ get '/match/:id' => sub {
get => "/match/$matchid",
{user => $userid},
);
- (my $game = $match->{game}) =~ s{.*/}{}mxs;
- my $template = "games/$game";
+ warning Dumper($match);
+ my $game = rest_call(
+ get => $match->{game},
+ {user => $userid},
+ );
+ use Data::Dumper;
+ warning Dumper($game);
+ my $gameid = $game->{id};
+ my $template = "games/$gameid";
try {
- my $class = "Narsil::Frontend::$game";
+ my $class = "Narsil::Frontend::$gameid";
(my $package = $class . '.pm') =~ s{(?: :: | ')}{/}gmxs;
require $package;
($match, $template) = $class->adapt($match, $userid);
} ## end try
catch {
warning $_;
};
- template match => {string => to_json($match), subtemplate => $template , %$match};
+ template match => {string => to_json({ %$game, }), subtemplate => $template, %$match, game => $game};
};
post '/match' => sub {
View
@@ -1,3 +1,4 @@
+--- <% string %> ---
<h2>Active Matches</h2>
<% INCLUDE _matches.tt matches = matches %>
<h2>Waiting Matches</h2>
View
@@ -1,2 +1,2 @@
-<h2 class="gametitle">Battleship</h2>
+<h2 class="gametitle"><% game.name %></h2>
<% INCLUDE $subtemplate %>
@@ -1,3 +1,5 @@
+<pre><% string %></pre>
+
<% IF session.user %>
<div class="matches">
<% IF matches.matches.size %>

0 comments on commit 1e18302

Please sign in to comment.