Skip to content

Commit

Permalink
advanced to cope with introduction of new games
Browse files Browse the repository at this point in the history
  • Loading branch information
polettix committed Oct 1, 2012
1 parent 391aeb5 commit 1e18302
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
18 changes: 13 additions & 5 deletions lib/Narsil/Frontend.pm
Expand Up @@ -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;
Expand Down Expand Up @@ -124,6 +124,7 @@ get '/' => sub {
availables => $availables,
waiting => $waiting,
string => to_json($waiting),
string => to_json($matches),
games => $games,
users => $users
};
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions views/index.tt
@@ -1,3 +1,4 @@
--- <% string %> ---
<h2>Active Matches</h2>
<% INCLUDE _matches.tt matches = matches %>
<h2>Waiting Matches</h2>
Expand Down
2 changes: 1 addition & 1 deletion views/match.tt
@@ -1,2 +1,2 @@
<h2 class="gametitle">Battleship</h2>
<h2 class="gametitle"><% game.name %></h2>
<% INCLUDE $subtemplate %>
2 changes: 2 additions & 0 deletions views/mobile/index.tt
@@ -1,3 +1,5 @@
<pre><% string %></pre>

<% IF session.user %>
<div class="matches">
<% IF matches.matches.size %>
Expand Down

0 comments on commit 1e18302

Please sign in to comment.