Skip to content

Commit

Permalink
Configurable assets URL
Browse files Browse the repository at this point in the history
  • Loading branch information
bpierre committed Apr 29, 2012
1 parent c71676e commit 6a52ee3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -13,7 +13,7 @@ function assetsServer() {
server = connect();
server.use(connect.static('public'));
server.listen(3001);
conf.assetsUrl = 'http://localhost:3001/';
conf.assetsUrl = 'http://localhost:3001';
}

function main() {
Expand Down
5 changes: 3 additions & 2 deletions lib/views/http.js
Expand Up @@ -32,7 +32,7 @@ var HttpView = function() {
};
util.inherits(HttpView, events.EventEmitter);

HttpView.prototype.start = function(gamesManager) {
HttpView.prototype.start = function(gamesManager, conf) {
var self = this;

if (init) return;
Expand All @@ -55,7 +55,8 @@ HttpView.prototype.start = function(gamesManager) {
player1: game.player1,
player2: game.player2,
turn: game.turn,
terrain: game.terrain.map
terrain: game.terrain.map,
assetsUrl: conf.assetsUrl
});
res.writeHead(200, { 'Content-Type': 'text/html; charset=UTF-8' });
res.end(body);
Expand Down
13 changes: 7 additions & 6 deletions lib/views/mail.js
Expand Up @@ -40,13 +40,14 @@ function renderTpl(tplname, opts) {
return ejs.render(template, opts);
}

function getHtmlBody(game, activePlayer) {
function getHtmlBody(game, activePlayer, assetsUrl) {
return renderTpl('game', {
player1: game.player1,
player2: game.player2,
activePlayer: game.player1,
turn: game.turn,
terrain: game.terrain.map
terrain: game.terrain.map,
assetsUrl: assetsUrl
});
}

Expand Down Expand Up @@ -92,8 +93,8 @@ SmtpView.prototype.start = function(gamesManager, conf) {
if (lastCommandStatus) {
// New turn
if (game.commandsEnd(player)) {
var body1 = getHtmlBody(game, game.player1),
body2 = getHtmlBody(game, game.player2);
var body1 = getHtmlBody(game, game.player1, conf.assetsUrl),
body2 = getHtmlBody(game, game.player2, conf.assetsUrl);
sendMessage(game.player1.email, game, body1);
sendMessage(game.player2.email, game, body2);
};
Expand All @@ -114,8 +115,8 @@ SmtpView.prototype.start = function(gamesManager, conf) {
// The game does not exists, try to create a new game.
} else if (addresses.length === 2) {
gamesManager.addGame(addresses[0], addresses[1], function(game) {
var body1 = getHtmlBody(game, game.player1),
body2 = getHtmlBody(game, game.player2);
var body1 = getHtmlBody(game, game.player1, conf.assetsUrl),
body2 = getHtmlBody(game, game.player2, conf.assetsUrl);
sendMessage(addresses[0], game, body1);
sendMessage(addresses[1], game, body2);
});
Expand Down
20 changes: 10 additions & 10 deletions tpl/game.html
Expand Up @@ -78,15 +78,15 @@
<table class="margin" <%- tablereset %>>
<tr>
<td width="600" height="20">
<img src="http://localhost:3001/transparent.gif" width="600" height="1" alt="">
<img src="<%- assetsUrl %>/transparent.gif" width="600" height="1" alt="">
</td>
</tr>
</table>

<table <%- tablereset %>>
<tr>
<td width="600" height="164" align="center">
<img src="http://localhost:3001/logo.gif" width="290" height="157" alt="Cursendus">
<img src="<%- assetsUrl %>/logo.gif" width="290" height="157" alt="Cursendus">
</td>
</tr>
</table>
Expand Down Expand Up @@ -123,31 +123,31 @@
<% var letters = 'ABCDEFGHIJKLMNOPQRSTUVW'.split(''); %>
<td width="26"></td>
<% for (var i=0; i < terrain[0].length; i++) { %>
<td width="40" height="20" background="http://localhost:3001/tabletab-north.gif" style="<%= fontserif %>text-align:center;"><b><%= letters[i] %></b></td>
<td width="40" height="20" background="<%- assetsUrl %>/tabletab-north.gif" style="<%= fontserif %>text-align:center;"><b><%= letters[i] %></b></td>
<% } %>
<td width="26"></td>
</tr>
<% for (var i=0; i < terrain.length; i++) { %>
<tr>
<td width="26" height="30" background="http://localhost:3001/tabletab-west.gif" style="<%= fontserif %>text-align:center;"><b><%=i+1 %></b></td>
<td width="26" height="30" background="<%- assetsUrl %>/tabletab-west.gif" style="<%= fontserif %>text-align:center;"><b><%=i+1 %></b></td>
<% for (var j=0; j < terrain[i].length; j++) { %>
<% if (!terrain[i][j].occupied) { %>
<td width="40" <% if (terrain[i+1] && terrain[i+1][j].occupied) { %>rowspan="2" height="60"<% } else { %>height="30"<% } %>
background="http://localhost:3001/terrain-<%= terrain[i][j].skin %>.gif">
background="<%- assetsUrl %>/terrain-<%= terrain[i][j].skin %>.gif">
<% if (terrain[i+1] && terrain[i+1][j].occupied) { %>
<img src="http://localhost:3001/sorcerer-<%= terrain[i+1][j].occupied.skin %>.gif" width="40" height="60" alt="" style="display:block">
<img src="<%- assetsUrl %>/sorcerer-<%= terrain[i+1][j].occupied.skin %>.gif" width="40" height="60" alt="" style="display:block">
<% } %>
</td>
<% } %>
<% } %>
<td width="26" height="30" background="http://localhost:3001/tabletab-est.gif" style="<%= fontserif %>text-align:center;"><b><%=i+1 %></b></td>
<td width="26" height="30" background="<%- assetsUrl %>/tabletab-est.gif" style="<%= fontserif %>text-align:center;"><b><%=i+1 %></b></td>
</tr>
<% } %>
<tr>
<% var letters = 'ABCDEFGHIJKLMNOPQRSTUVW'.split(''); %>
<td width="26"></td>
<% for (var i=0; i < terrain[0].length; i++) { %>
<td width="40" height="20" background="http://localhost:3001/tabletab-south.gif" style="<%= fontserif %>text-align:center;"><b><%= letters[i] %></b></td>
<td width="40" height="20" background="<%- assetsUrl %>/tabletab-south.gif" style="<%= fontserif %>text-align:center;"><b><%= letters[i] %></b></td>
<% } %>
<td width="26"></td>
</tr>
Expand Down Expand Up @@ -182,7 +182,7 @@
<table <%- tablereset %>>
<tr>
<td width="320" height="70" valign="bottom">
<img src="http://localhost:3001/hat-1-large.gif" width="53" height="47" alt="Amthyst’s hat">
<img src="<%- assetsUrl %>/hat-1-large.gif" width="53" height="47" alt="Amthyst’s hat">
</td>
</tr>
<tr>
Expand Down Expand Up @@ -210,7 +210,7 @@
<table <%- tablereset %>>
<tr>
<td width="260" height="70" valign="bottom" align="center">
<img src="http://localhost:3001/hat-2-large.gif" width="53" height="23" alt="Dr. Black’s hat">
<img src="<%- assetsUrl %>/hat-2-large.gif" width="53" height="23" alt="Dr. Black’s hat">
</td>
</tr>
<tr>
Expand Down

0 comments on commit 6a52ee3

Please sign in to comment.