app/assets/javascripts/presence_game.js.erb in social_stream-presence-0.10.2 vs app/assets/javascripts/presence_game.js.erb in social_stream-presence-0.10.3
- old
+ new
@@ -1,7 +1,8 @@
////////////////////
//Multiplayer Games Core based on XMPP
+//Version: 1.2
////////////////////
PRESENCE.GAME = (function(P,$,undefined){
/////////////////////////////////
@@ -43,10 +44,14 @@
P.GAME.COMUNICATION.init(myConnection);
};
var requestUserToPlay = function (slug,game){
+ if(game==null){
+ return;
+ }
+
if (slug in contactsInfo) {
var gameStatus = contactsInfo[slug].gameStatus;
} else {
var gameStatus = null;
}
@@ -100,17 +105,17 @@
contactsInfo[slug].gameStatus="disconnected";
PRESENCE.GAME.INTERFACE.updateInterfaceAfterFinishGame(slug);
}
}
- var sendAction = function(gameId,players,action){
- $.each(players, function(index, value) {
+ var sendAction = function(game,action){
+ $.each(game.players, function(index, value) {
var slug = value.id;
if(slug!=user_slug){
if(slug in contactsInfo){
var jid=slug+"@"+contactsInfo[slug].domain+"/"+contactsInfo[slug].resource;
- P.GAME.COMUNICATION.sendIQStanzaWithAction(jid,gameId,action);
+ P.GAME.COMUNICATION.sendIQStanzaWithAction(jid,game.id,action);
}
}
});
}
@@ -124,20 +129,20 @@
P.GAME.COMUNICATION.sendIQStanzaToResponseGameRequest(slug,"busy");
return true;
} else {
contactsInfo[slug].gameStatus="pending";
}
- P.GAME.INTERFACE.updateInterfaceAfterGameRequestReceived(slug)
+ P.GAME.INTERFACE.updateInterfaceAfterGameRequestReceived(slug,contactsInfo[slug].game)
}
var updateLogicAfterReceivedGameRequestResponse = function(slug,response){
if(contactsInfo[slug].gameStatus!="waiting"){
return true;
}
if(response=="yes"){
contactsInfo[slug].gameStatus = "playing";
- P.GAME.INTERFACE.updateInterfaceBeforeStartGame(slug)
+ P.GAME.INTERFACE.updateInterfaceBeforeStartGame(slug,contactsInfo[slug].game)
} else if (response=="no"){
P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug,I18n.t("chat.game.rejected", {name: getNameFromSlug(slug)}));
contactsInfo[slug].gameStatus="disconnected";
} else if (response=="busy"){
P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug,I18n.t("chat.game.rejectedBusy", {name: getNameFromSlug(slug)}));
@@ -265,10 +270,11 @@
var myplayer = new player(user_slug,user_name)
PRESENCE.GAME[game.id].init(myplayer,game,divID)
}
var finishGame = function (slug){
+ var game = null;
if(slug in contactsInfo){
var gameStatus = contactsInfo[slug].gameStatus;
if(gameStatus=="playing"){
var jid=slug+"@"+contactsInfo[slug].domain+"/"+contactsInfo[slug].resource;
P.GAME.COMUNICATION.sendIQStanzaToFinishGame(jid);
@@ -281,12 +287,13 @@
P.GAME.COMUNICATION.sendIQStanzaToFinishGame(jid);
} else if(gameStatus=="pending"){
P.GAME.COMUNICATION.sendIQStanzaToResponseGameRequest(slug,"no");
}
contactsInfo[slug].gameStatus="disconnected";
+ game = contactsInfo[slug].game
}
- PRESENCE.GAME.INTERFACE.updateInterfaceAfterFinishGame(slug)
+ PRESENCE.GAME.INTERFACE.updateInterfaceAfterFinishGame(slug,game)
}
var userDisconnected = function(slug){
finishGame(slug)
}