Skip to content

Commit

Permalink
Merge branch 'turn'
Browse files Browse the repository at this point in the history
  • Loading branch information
polettix committed Sep 27, 2012
2 parents dbfdc62 + c70378f commit 9489649
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 15 deletions.
30 changes: 30 additions & 0 deletions environments/local.yml
@@ -0,0 +1,30 @@
# configuration file for development environment

# the logger engine to use
# console: log messages to STDOUT (your console where you started the
# application server)
# file: log message to a file in log/
logger: "console"

# the log level for this environement
# core is the lowest, it shows Dancer's core log messages as well as yours
# (debug, warning and error)
log: "core"

# should Dancer consider warnings as critical errors?
warnings: 1

# should Dancer show a stacktrace when an error is caught?
show_errors: 1

# auto_reload is a development and experimental feature
# you should enable it by yourself if you want it
# Module::Refresh is needed
#
# Be aware it's unstable and may cause a memory leak.
# DO NOT EVER USE THAT FEATURE IN PRODUCTION
# OR TINY KITTENS SHALL DIE WITH LOTS OF SUFFERING
auto_reload: 0

# all local
'narsil-ws': 'http://localhost:3000/'
7 changes: 5 additions & 2 deletions lib/Narsil/Frontend.pm
Expand Up @@ -9,7 +9,7 @@ use Try::Tiny;
use Storable qw< dclone >;

BEGIN {
unshift @INC, qw< /home/poletti/sviluppo/perl/narsil/narsil-core/lib >
unshift @INC, qw< /home/poletti/sviluppo/perl/narsil/core/lib >
unless exists $ENV{DOTCLOUD_ENVIRONMENT};
}

Expand Down Expand Up @@ -88,6 +88,7 @@ get '/' => sub {
return template 'index',
{
matches => $matches,
string => to_json($matches),
availables => $availables,
waiting => $waiting,
games => $games,
Expand Down Expand Up @@ -157,17 +158,19 @@ sub get_matches_for {
my ($user, $phase) = @_;
return {} unless defined $user;
my $userid = $user->{username};
$phase //= 'active';
my $stuff = rest_call(
get => "/user/matches/$userid",
{
phase => $phase // 'active',
phase => $phase,
user => $userid,
}
);
for my $match (@{$stuff->{matches}}) {
($match->{id} = $match->{uri}) =~ s{.*/}{}mxs;
$match->{opponents} =
[grep { $_->[0] ne $userid } @{$match->{participants}}];
$match->{movers} = [map { $_->[0] } @{$match->{movers}}];
}
return $stuff;
} ## end sub get_matches_for
Expand Down
10 changes: 7 additions & 3 deletions lib/Narsil/Frontend/battleship.pm
Expand Up @@ -9,10 +9,12 @@ use Narsil::Game::BattleShip::Status;
sub adapt {
my ($package, $match, $user) = @_;
my $status = Narsil::Game::BattleShip::Status->new($match->{status});

$status->field_size_y();
my %retval = (%$status, match => $match, user => $user);

($retval{matchid} = $match->{uri}) =~ s{.*/}{}mxs;
my @players = @{$status->{players}};
my @players = map { $_->[0] } @{$match->{participants}};
push @players, '*undef' while scalar(@players) < 2;
if (grep { $_ eq $user } @players) { # user participates
($retval{upper}) = grep { $_ ne $user } @players;
Expand All @@ -22,8 +24,10 @@ sub adapt {
@retval{qw< upper lower >} = @players;
}

$retval{active_player} =
$status->{players}[$status->{current_player_id}];
my @movers = map { $_->[0] } @{$match->{movers}};
$retval{movers} = \@movers;
$retval{active_player} = $movers[0] if @movers == 1;
$retval{player_is_active} = grep { $_ eq $user } @movers;
delete $retval{active_player} if $match->{phase} eq 'terminated';

$retval{maxx} = $retval{field_size_x} - 1;
Expand Down
2 changes: 1 addition & 1 deletion public/css/style.css
Expand Up @@ -171,8 +171,8 @@ form.logout button {
}

table.battleboat td {
border: 1px solid #ddd;
border: 0;
border: 1px solid #777;
padding: 2px;
padding: 0;
}
Expand Down
8 changes: 7 additions & 1 deletion views/_matches.tt
Expand Up @@ -11,6 +11,12 @@
IF match.phase == 'gathering' && ! match.is_participant;
id = match.id;
uri = request.uri_for("/match/joins/$id");
%>(<form style="display:inline" action="<% uri %>" method="POST"><button class="aslink">join</button></form>)<% END %></li>
%>(<form style="display:inline" action="<% uri %>" method="POST"><button class="aslink">join</button></form>)<%
END;

IF match.movers && match.movers.size > 0;
%>(<% match.movers.join(", ") %> moving)<%
END
%></li>
<% END %>
</ul>
11 changes: 9 additions & 2 deletions views/games/battleship/setup.tt
@@ -1,7 +1,14 @@
<h1>Battleship</h1>
<p>It's <% active_player %>'s turn</p>

<% IF active_player == user %>
Match is in setup phase. The following users are setting up:

<ul>
<% FOR mover = movers %>
<li><% mover %></li>
<% END %>
</ul>

<% IF player_is_active %>
Setup it here...


Expand Down
6 changes: 0 additions & 6 deletions views/layouts/main.tt
Expand Up @@ -7,12 +7,6 @@
<link rel="stylesheet" href="<% request.uri_for('/css/style.css') %>" />
<link rel="shortcut icon" href="<% request.uri_for('/images/favicon.ico') %>" />

<!-- Grab Google CDN's jQuery. fall back to local if necessary -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">/* <![CDATA[ */
!window.jQuery && document.write('<script type="text/javascript" src="<% request.uri_base %>/javascripts/jquery.js"><\/script>')
/* ]]> */</script>

</head>
<body>
<div id="container">
Expand Down

0 comments on commit 9489649

Please sign in to comment.