social_stream-presence 0.8.6 → 0.8.7
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/images/games/ter/classic_aspa.png +0 -0
- data/app/assets/images/games/ter/classic_board.png +0 -0
- data/app/assets/images/games/ter/classic_circle.png +0 -0
- data/app/assets/images/games/ter/modern_aspa.png +0 -0
- data/app/assets/images/games/ter/modern_board.png +0 -0
- data/app/assets/images/games/ter/modern_circle.png +0 -0
- data/app/assets/javascripts/jquery.ui.chatbox.sstreampresence.js +25 -1
- data/app/assets/javascripts/presence.js.erb +4 -0
- data/app/assets/javascripts/{xmpp_client_management.js.erb → presence_XmppClient.js.erb} +81 -23
- data/app/assets/javascripts/{chat_audio.js.erb → presence_audio.js.erb} +0 -0
- data/app/assets/javascripts/presence_game.js.erb +76 -0
- data/app/assets/javascripts/presence_game_ter.js.erb +384 -0
- data/app/assets/javascripts/{notifications.js → presence_notifications.js} +0 -0
- data/app/assets/javascripts/{chat_parser.js → presence_parser.js} +0 -0
- data/app/assets/javascripts/{chat_persistence.js → presence_persistence.js} +0 -0
- data/app/assets/javascripts/{store.js → presence_store.js} +0 -0
- data/app/assets/javascripts/{chat_interface_manager.js.erb → presence_uiManager.js.erb} +0 -0
- data/app/assets/javascripts/{chat_utilities.js → presence_utilities.js} +2 -3
- data/app/assets/javascripts/{videochat.js.erb → presence_videochat.js.erb} +0 -0
- data/app/assets/javascripts/{chat_window_manager.js → presence_windowManager.js} +0 -0
- data/app/assets/javascripts/social_stream-presence.js +0 -2
- data/app/assets/stylesheets/chat.css.scss +11 -0
- data/config/locales/en.yml +1 -1
- data/config/locales/es.yml +1 -1
- data/lib/social_stream/presence/version.rb +1 -1
- metadata +43 -14
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -40,7 +40,12 @@
|
|
40
40
|
var self = this;
|
41
41
|
var box = self.elem.uiChatboxLog;
|
42
42
|
var e = document.createElement('div');
|
43
|
-
|
43
|
+
if((peer==null)||($(peer).html()=="")){
|
44
|
+
var fContent = msg
|
45
|
+
} else {
|
46
|
+
var fContent = "<b>" + peer +":</b> " + msg
|
47
|
+
}
|
48
|
+
$(e).html(fContent)
|
44
49
|
.addClass("ui-chatbox-msg");
|
45
50
|
box.append(e);
|
46
51
|
self._scrollToBottom();
|
@@ -209,6 +214,25 @@
|
|
209
214
|
.appendTo(uiChatboxTitlebarVideoChange),
|
210
215
|
|
211
216
|
|
217
|
+
//Games Menu button
|
218
|
+
uiChatboxTitlebarGames = (self.uiChatboxTitlebarGames = $('<a href="#"></a>'))
|
219
|
+
.addClass('ui-corner-all ' +
|
220
|
+
'ui-chatbox-icon' + ' ui-games-icon'
|
221
|
+
)
|
222
|
+
.attr('role', 'button')
|
223
|
+
.hover(function() {uiChatboxTitlebarGames.addClass('ui-state-hover');},
|
224
|
+
function() {uiChatboxTitlebarGames.removeClass('ui-state-hover');})
|
225
|
+
.click(function(event) {
|
226
|
+
pickGamesButton(self)
|
227
|
+
return false;
|
228
|
+
})
|
229
|
+
.appendTo(uiChatboxTitlebar),
|
230
|
+
uiChatboxTitlebarGamesText = $('<span></span>')
|
231
|
+
.addClass('ui-icon-star ' + 'chat-thick ' + ' chat-gamesthick' )
|
232
|
+
.text('')
|
233
|
+
.appendTo(uiChatboxTitlebarGames),
|
234
|
+
|
235
|
+
|
212
236
|
// content
|
213
237
|
uiChatboxContent = (self.uiChatboxContent = $('<div></div>'))
|
214
238
|
.addClass('ui-widget-content ' +
|
@@ -65,7 +65,8 @@ function chatRoom() {
|
|
65
65
|
this.joined = false;
|
66
66
|
this.affiliation = "none";
|
67
67
|
this.role = "none";
|
68
|
-
|
68
|
+
this.nick = getBaseNickFromUserName();
|
69
|
+
}
|
69
70
|
|
70
71
|
|
71
72
|
//IQsIDs
|
@@ -316,7 +317,7 @@ function onMessage(msg) {
|
|
316
317
|
var from_slug = getSlugFromJid(from)
|
317
318
|
|
318
319
|
if(isChatRoomJid(from)){
|
319
|
-
return
|
320
|
+
return true
|
320
321
|
} else {
|
321
322
|
var from_slug = getSlugFromJid(from)
|
322
323
|
afterReceivedChatMessage(from_slug,msg,null)
|
@@ -718,11 +719,11 @@ function sendStatus(status){
|
|
718
719
|
var muc_host = "conference";
|
719
720
|
|
720
721
|
function joinRoom(roomName){
|
721
|
-
return strophe_connection.muc.join(getRoomJidFromRoomName(roomName),
|
722
|
+
return strophe_connection.muc.join(getRoomJidFromRoomName(roomName), getRoomNickForRoom(roomName), null, null, null, null)
|
722
723
|
}
|
723
724
|
|
724
725
|
function leaveRoom(roomName){
|
725
|
-
return strophe_connection.muc.leave(getRoomJidFromRoomName(roomName),
|
726
|
+
return strophe_connection.muc.leave(getRoomJidFromRoomName(roomName), getRoomNickForRoom(roomName), null, null)
|
726
727
|
}
|
727
728
|
|
728
729
|
function sendGroupMessageToRoomWithName(roomName,msg){
|
@@ -747,7 +748,6 @@ function queryChatRoomOccupantsSuccess(iqResponse){
|
|
747
748
|
}
|
748
749
|
|
749
750
|
function queryChatRoomOccupantsFail(){
|
750
|
-
//log("queryChatRoomOccupantsFail")
|
751
751
|
return true;
|
752
752
|
}
|
753
753
|
|
@@ -781,11 +781,15 @@ function accessRoom(roomName,open){
|
|
781
781
|
return true
|
782
782
|
}
|
783
783
|
|
784
|
+
function resetRoomConfig(roomName){
|
785
|
+
storeRoomInformation(roomName)
|
786
|
+
var room = new chatRoom()
|
787
|
+
roomsInfo[roomName]=room
|
788
|
+
}
|
789
|
+
|
784
790
|
function updateRoomsInfoAfterUserDisconnect(){
|
785
791
|
$.each(getAllSlugsWithVisibleGroupBoxes(), function(index, value) {
|
786
|
-
|
787
|
-
var room = new chatRoom();
|
788
|
-
roomsInfo[value]=room;
|
792
|
+
resetRoomConfig(value)
|
789
793
|
initialNotificationInGroup(value,I18n.t('chat.muc.offline'))
|
790
794
|
});
|
791
795
|
}
|
@@ -794,10 +798,32 @@ function getRoomJidFromRoomName(roomName){
|
|
794
798
|
return roomName + "@" + muc_host + "." + domain;
|
795
799
|
}
|
796
800
|
|
797
|
-
function
|
801
|
+
function getRoomNickForRoom(roomName){
|
802
|
+
if(roomName in roomsInfo){
|
803
|
+
return roomsInfo[roomName].nick;
|
804
|
+
} else {
|
805
|
+
return getBaseNickFromUserName();
|
806
|
+
}
|
807
|
+
}
|
808
|
+
|
809
|
+
function getBaseNickFromUserName(){
|
798
810
|
return user_name.split(" ")[0];
|
799
811
|
}
|
800
812
|
|
813
|
+
function changeRoomNickNameAndJoinAgain(roomName){
|
814
|
+
var old_nick = getRoomNickForRoom(roomName)
|
815
|
+
|
816
|
+
if(old_nick.split("_").length > 4){
|
817
|
+
//Bucle prevention...
|
818
|
+
return false;
|
819
|
+
}
|
820
|
+
|
821
|
+
storeRoomInformation(roomName)
|
822
|
+
roomsInfo[roomName].nick = old_nick + "_"
|
823
|
+
joinRoom(roomName)
|
824
|
+
return true;
|
825
|
+
}
|
826
|
+
|
801
827
|
|
802
828
|
////////
|
803
829
|
//MUC Stanzas
|
@@ -824,11 +850,12 @@ function onRoomMessage(msg) {
|
|
824
850
|
function onRoomPresence(presence) {
|
825
851
|
var from = $(presence).attr('from');
|
826
852
|
var to = $(presence).attr('to')
|
853
|
+
var room_slug = getSlugFromJid(from);
|
827
854
|
var nick = getNickFromChatRoomJid(from)
|
828
855
|
var ptype = $(presence).attr('type')
|
829
|
-
|
856
|
+
|
830
857
|
//Join or Leave room stanzas of self user
|
831
|
-
if((nick ==
|
858
|
+
if((nick == getRoomNickForRoom(room_slug))&&(getSlugFromJid(to) == user_slug)){
|
832
859
|
switch (ptype){
|
833
860
|
case undefined:
|
834
861
|
processJoinRoomPresenceStanza(presence);
|
@@ -839,6 +866,9 @@ function onRoomPresence(presence) {
|
|
839
866
|
case "unavailable":
|
840
867
|
processLeaveRoomPresenceStanza(presence);
|
841
868
|
break;
|
869
|
+
case "error":
|
870
|
+
processJoinErrorRoomPresenceStanza(presence);
|
871
|
+
break;
|
842
872
|
}
|
843
873
|
return true;
|
844
874
|
}
|
@@ -892,22 +922,51 @@ function processJoinRoomPresenceStanza(presence){
|
|
892
922
|
function processLeaveRoomPresenceStanza(presence){
|
893
923
|
var from = $(presence).attr('from');
|
894
924
|
var room_slug = getSlugFromJid(from);
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
925
|
+
resetRoomConfig(room_slug)
|
926
|
+
changeInitialNotificationInGroup(room_slug,"")
|
927
|
+
}
|
928
|
+
|
929
|
+
function processJoinErrorRoomPresenceStanza(presence){
|
930
|
+
var from = $(presence).attr('from')
|
931
|
+
var room_slug = getSlugFromJid(from)
|
932
|
+
var errorMsg = "Error";
|
933
|
+
|
934
|
+
var eElements = presence.getElementsByTagName('error')
|
935
|
+
if (eElements.length == 1) {
|
936
|
+
var error = eElements[0];
|
937
|
+
var code = $(error).attr("code")
|
938
|
+
var type = $(error).attr("type")
|
939
|
+
errorMsg = errorMsg + " with code:" + code + " and type:" + type
|
940
|
+
var textElements = error.getElementsByTagName('text')
|
941
|
+
if (textElements.length == 1) {
|
942
|
+
var text = $(textElements[0]).text()
|
943
|
+
errorMsg = errorMsg + "\n" + text
|
944
|
+
}
|
945
|
+
|
946
|
+
//Try to fix errors!
|
947
|
+
if(code==409){
|
948
|
+
//Case: Nickname already in use
|
949
|
+
if (changeRoomNickNameAndJoinAgain(room_slug)){
|
950
|
+
return;
|
951
|
+
}
|
952
|
+
}
|
953
|
+
//if(code==403){
|
954
|
+
//Case: Auth Denied
|
955
|
+
//}
|
956
|
+
|
957
|
+
//[...]
|
958
|
+
|
902
959
|
}
|
960
|
+
|
961
|
+
resetRoomConfig(room_slug)
|
962
|
+
initialNotificationInGroup(room_slug,I18n.t("chat.muc.joinError", {errorMsg: errorMsg}))
|
903
963
|
}
|
904
964
|
|
905
965
|
function processAvailableRoomPresenceStanza(presence){
|
906
966
|
var from = $(presence).attr('from');
|
907
967
|
var nick = getNickFromChatRoomJid(from)
|
908
968
|
var room_slug = getSlugFromJid(from)
|
909
|
-
|
910
|
-
storeRoomInformation(room_slug)
|
969
|
+
storeRoomInformation(room_slug);
|
911
970
|
|
912
971
|
if (roomsInfo[room_slug].occupants.indexOf(nick)==-1){
|
913
972
|
roomsInfo[room_slug].occupants.push(nick)
|
@@ -920,9 +979,8 @@ function processUnavailableRoomPresenceStanza(presence){
|
|
920
979
|
var from = $(presence).attr('from');
|
921
980
|
var nick = getNickFromChatRoomJid(from)
|
922
981
|
var room_slug = getSlugFromJid(from)
|
923
|
-
|
924
|
-
|
925
|
-
|
982
|
+
storeRoomInformation(room_slug);
|
983
|
+
|
926
984
|
if (roomsInfo[room_slug].occupants.indexOf(nick)!=-1){
|
927
985
|
roomsInfo[room_slug].occupants.splice(roomsInfo[room_slug].occupants.indexOf(nick),1)
|
928
986
|
removeNickFromNotificationInGroup(room_slug,nick)
|
File without changes
|
@@ -0,0 +1,76 @@
|
|
1
|
+
////////////////////
|
2
|
+
//Multiplayer Games Core based on XMPP
|
3
|
+
////////////////////
|
4
|
+
|
5
|
+
PRESENCE.GAME = (function(P,$,undefined){
|
6
|
+
|
7
|
+
//Gamecore variables
|
8
|
+
var connection = null;
|
9
|
+
iqStanzaID['gameRequest'] = "gameRequestID";
|
10
|
+
|
11
|
+
var init = function(myConnection){
|
12
|
+
connection = myconnection;
|
13
|
+
};
|
14
|
+
|
15
|
+
|
16
|
+
var sendIQStanzaToRequestGame = function (slug,players,options){
|
17
|
+
|
18
|
+
if (slug in contactsInfo) {
|
19
|
+
var jid=slug+"@"+contactsInfo[slug].domain+"/"+contactsInfo[slug].resource;
|
20
|
+
|
21
|
+
var iq = $iq({to: jid, type: "get", id: iqStanzaID['gameRequest']})
|
22
|
+
.c("query", {xmlns: "urn:ietf:params:xml:ns:xmpp-stanzas"})
|
23
|
+
.c("game", {name: "gameName"})
|
24
|
+
.c("players", {})
|
25
|
+
.c("player1").t("player1value").up()
|
26
|
+
.c("player2").t("player2value").up()
|
27
|
+
.c("options", {})
|
28
|
+
.c("options1").t("options1value").up()
|
29
|
+
.c("options2").t("options2value").up()
|
30
|
+
strophe_connection.sendIQ(iq);
|
31
|
+
}
|
32
|
+
};
|
33
|
+
|
34
|
+
//Getters
|
35
|
+
var getDummy = function(){
|
36
|
+
return param;
|
37
|
+
};
|
38
|
+
|
39
|
+
|
40
|
+
return {
|
41
|
+
init: init,
|
42
|
+
sendIQStanzaToRequestGame: sendIQStanzaToRequestGame,
|
43
|
+
getDummy: getDummy
|
44
|
+
};
|
45
|
+
|
46
|
+
}) (PRESENCE, jQuery);
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
////////////////////
|
63
|
+
//Interface Events
|
64
|
+
////////////////////
|
65
|
+
var global;
|
66
|
+
|
67
|
+
function play(){
|
68
|
+
$(".chat-gamesthick").css("display","block");
|
69
|
+
}
|
70
|
+
|
71
|
+
function pickGamesButton(uiElement){
|
72
|
+
var slug = $(uiElement.element).attr("id");
|
73
|
+
//clickGamesButton(slug);
|
74
|
+
log("clickGamesButton(slug)" + slug)
|
75
|
+
}
|
76
|
+
|
@@ -0,0 +1,384 @@
|
|
1
|
+
////////////////////
|
2
|
+
//Tres en Raya
|
3
|
+
////////////////////
|
4
|
+
|
5
|
+
PRESENCE.GAME.TER = (function(P,$,undefined){
|
6
|
+
|
7
|
+
//Game core
|
8
|
+
var core = P.GAME
|
9
|
+
|
10
|
+
//Game variables
|
11
|
+
var players = null;
|
12
|
+
var player = null;
|
13
|
+
var currentPlayer = null;
|
14
|
+
var options = null;
|
15
|
+
function action(player,square) {
|
16
|
+
this.player = player;
|
17
|
+
this.square = square;
|
18
|
+
}
|
19
|
+
var playing=true;
|
20
|
+
|
21
|
+
//Html Divs
|
22
|
+
var divID = null;
|
23
|
+
var containerDivId = 'tresEnRayaContainerDivID';
|
24
|
+
var messageDivId = 'tresEnRayaMessageDivID';
|
25
|
+
|
26
|
+
//Boardgame
|
27
|
+
var board = [];
|
28
|
+
var boardDimension = null;
|
29
|
+
var squareDimension = null;
|
30
|
+
var middleSquareDimension = null;
|
31
|
+
|
32
|
+
var init = function(myPlayers,myPlayer,myOptions,myDivID){
|
33
|
+
if (!validateParams(myPlayers,myPlayer,myOptions,myDivID)){
|
34
|
+
showMessage("Invalid parameters");
|
35
|
+
return;
|
36
|
+
}
|
37
|
+
players = myPlayers;
|
38
|
+
player = myPlayer;
|
39
|
+
options = settingOptions(myOptions);
|
40
|
+
divID = myDivID;
|
41
|
+
drawBoard();
|
42
|
+
settingBoard();
|
43
|
+
setBoardEvents();
|
44
|
+
currentPlayer = players[0];
|
45
|
+
if(player==currentPlayer){
|
46
|
+
showMessage("You start!")
|
47
|
+
} else {
|
48
|
+
showMessage(currentPlayer + " starts!")
|
49
|
+
}
|
50
|
+
};
|
51
|
+
|
52
|
+
var validateParams = function(myPlayers,myPlayer,myOptions,myDivID){
|
53
|
+
|
54
|
+
if ((typeof myPlayers=="undefined")||(typeof myPlayer=="undefined")||(typeof myOptions=="undefined")||(typeof myDivID=="undefined")){
|
55
|
+
return false;
|
56
|
+
}
|
57
|
+
|
58
|
+
//Check if myPlayers is an Array
|
59
|
+
if (myPlayers.constructor.toString().indexOf("Array") == -1){
|
60
|
+
return false;
|
61
|
+
}
|
62
|
+
|
63
|
+
//2 players at least
|
64
|
+
if(myPlayers.lenght < 2){
|
65
|
+
return false;
|
66
|
+
}
|
67
|
+
|
68
|
+
//Check if myOptions is an Array
|
69
|
+
if (myOptions.constructor.toString().indexOf("Array") == -1){
|
70
|
+
return false;
|
71
|
+
}
|
72
|
+
|
73
|
+
//Check that myPlayer is contained on myPlayers
|
74
|
+
if(myPlayers.indexOf(myPlayer)==-1){
|
75
|
+
return false;
|
76
|
+
}
|
77
|
+
|
78
|
+
return true;
|
79
|
+
}
|
80
|
+
|
81
|
+
var settingOptions = function(myOptions){
|
82
|
+
|
83
|
+
if (!('theme' in myOptions)){
|
84
|
+
myOptions['theme'] = "Modern"
|
85
|
+
}
|
86
|
+
|
87
|
+
if (!('rounds' in myOptions)){
|
88
|
+
myOptions['rounds'] = "1"
|
89
|
+
}
|
90
|
+
|
91
|
+
//Apply default options for non specified opts.
|
92
|
+
return myOptions;
|
93
|
+
};
|
94
|
+
|
95
|
+
var drawBoard = function(){
|
96
|
+
var containerDiv = document.createElement('div');
|
97
|
+
containerDiv.setAttribute('id', containerDivId);
|
98
|
+
containerDiv.setAttribute('class', 'tresEnRayaContainerDivClass');
|
99
|
+
$("#" + divID).append(containerDiv);
|
100
|
+
|
101
|
+
var messageDiv = document.createElement('div');
|
102
|
+
messageDiv.setAttribute('id', messageDivId);
|
103
|
+
$(messageDiv).addClass('tresEnRayaMessageDivClass')
|
104
|
+
$(messageDiv).addClass('tresEnRayaMessageTheme' + options['theme'])
|
105
|
+
$("#" + divID).append(messageDiv);
|
106
|
+
|
107
|
+
var p = document.createElement('p');
|
108
|
+
p.setAttribute('id', messageDivId + "p");
|
109
|
+
$(p).addClass('tresEnRayaMessagePTheme' + options['theme'])
|
110
|
+
$("#" + messageDivId).append(p);
|
111
|
+
|
112
|
+
|
113
|
+
//Adjust dimensions
|
114
|
+
var parentWidth = $("#" + divID).width();
|
115
|
+
var parentHeight = $("#" + divID).height();
|
116
|
+
var maxDimension = 300;
|
117
|
+
var minDimension = 100;
|
118
|
+
|
119
|
+
var dimension = Math.min(parentWidth,parentHeight,maxDimension)
|
120
|
+
boardDimension = Math.max(dimension,minDimension)
|
121
|
+
|
122
|
+
$("#" + containerDivId).height(boardDimension)
|
123
|
+
$("#" + containerDivId).width(boardDimension);
|
124
|
+
|
125
|
+
//Apply Theme
|
126
|
+
$("#" + containerDivId).addClass('tresEnRayaContainerTheme' + options['theme'])
|
127
|
+
};
|
128
|
+
|
129
|
+
var settingBoard = function(){
|
130
|
+
squareDimension = boardDimension/3;
|
131
|
+
middleSquareDimension = squareDimension/2;
|
132
|
+
//board[squareID] = [x,y,ElementInSquare {0=none,1=circle,2=aspa}]
|
133
|
+
board[0] = [middleSquareDimension,middleSquareDimension,0]
|
134
|
+
board[1] = [middleSquareDimension+squareDimension,middleSquareDimension,0]
|
135
|
+
board[2] = [boardDimension-middleSquareDimension,middleSquareDimension,0]
|
136
|
+
board[3] = [middleSquareDimension,middleSquareDimension+squareDimension,0]
|
137
|
+
board[4] = [middleSquareDimension+squareDimension,middleSquareDimension+squareDimension,0]
|
138
|
+
board[5] = [boardDimension-middleSquareDimension,middleSquareDimension+squareDimension,0]
|
139
|
+
board[6] = [middleSquareDimension,boardDimension-middleSquareDimension,0]
|
140
|
+
board[7] = [middleSquareDimension+squareDimension,boardDimension-middleSquareDimension,0]
|
141
|
+
board[8] = [boardDimension-middleSquareDimension,boardDimension-middleSquareDimension,0]
|
142
|
+
};
|
143
|
+
|
144
|
+
var setBoardEvents = function(){
|
145
|
+
$("#" + containerDivId).click(function (event) {
|
146
|
+
|
147
|
+
var offsetX = event.pageX - $("#" + containerDivId).offset().left
|
148
|
+
var offsetY = event.pageY - $("#" + containerDivId).offset().top
|
149
|
+
|
150
|
+
if($(event.target).is('img')){
|
151
|
+
return;
|
152
|
+
}
|
153
|
+
|
154
|
+
if(currentPlayer!=player){
|
155
|
+
//return;
|
156
|
+
}
|
157
|
+
square = getSquare(offsetX,offsetY)
|
158
|
+
var actionNew = new action(currentPlayer,square);
|
159
|
+
processAction(actionNew)
|
160
|
+
});
|
161
|
+
};
|
162
|
+
|
163
|
+
var getSquare = function(x,y){
|
164
|
+
for(var i=0; i<board.length; i++){
|
165
|
+
if((Math.abs(x-board[i][0])<middleSquareDimension)&&(Math.abs(y-board[i][1])<middleSquareDimension)){
|
166
|
+
return i;
|
167
|
+
}
|
168
|
+
}
|
169
|
+
return 0;
|
170
|
+
}
|
171
|
+
|
172
|
+
|
173
|
+
var processAction = function(action){
|
174
|
+
|
175
|
+
if(playing==false){
|
176
|
+
return;
|
177
|
+
}
|
178
|
+
|
179
|
+
//Check if the action is legal
|
180
|
+
if(!checkAction(action)){
|
181
|
+
showMessage("Ilegal action");
|
182
|
+
return false;
|
183
|
+
}
|
184
|
+
|
185
|
+
if(player==currentPlayer){
|
186
|
+
//Notify action
|
187
|
+
sendAction(action);
|
188
|
+
}
|
189
|
+
|
190
|
+
|
191
|
+
//Update logic
|
192
|
+
updateLogic(action);
|
193
|
+
|
194
|
+
//Update interface
|
195
|
+
updateInterface(action);
|
196
|
+
|
197
|
+
//Check for winner
|
198
|
+
var winner = checkWinner()
|
199
|
+
if(winner!=null){
|
200
|
+
if(winner!="finish"){
|
201
|
+
if(player==winner){
|
202
|
+
showMessage("You have won the game")
|
203
|
+
} else {
|
204
|
+
showMessage(winner + " has won the game")
|
205
|
+
}
|
206
|
+
} else {
|
207
|
+
showMessage("Finished game");
|
208
|
+
}
|
209
|
+
finishGame();
|
210
|
+
return
|
211
|
+
}
|
212
|
+
|
213
|
+
nextTurn();
|
214
|
+
}
|
215
|
+
|
216
|
+
|
217
|
+
var showMessage = function(msg){
|
218
|
+
$("#" + messageDivId + "p").html(msg)
|
219
|
+
}
|
220
|
+
|
221
|
+
var finishGame = function(){
|
222
|
+
playing = false;
|
223
|
+
}
|
224
|
+
|
225
|
+
var checkAction = function(action){
|
226
|
+
if(board[action.square][2]!=0){
|
227
|
+
return false;
|
228
|
+
}
|
229
|
+
|
230
|
+
return true;
|
231
|
+
}
|
232
|
+
|
233
|
+
var updateLogic = function(action){
|
234
|
+
board[action.square][2]=players.indexOf(action.player)+1;
|
235
|
+
}
|
236
|
+
|
237
|
+
var updateInterface = function(action){
|
238
|
+
var img = document.createElement('img');
|
239
|
+
|
240
|
+
if(action.player==players[0]){
|
241
|
+
var figure = "circle";
|
242
|
+
} else {
|
243
|
+
var figure = "aspa";
|
244
|
+
}
|
245
|
+
|
246
|
+
$(img).attr("src","themes/" + options['theme'].toLowerCase() + "_" + figure + ".png");
|
247
|
+
|
248
|
+
$("#" + containerDivId).append(img);
|
249
|
+
$(img).addClass('tresEnRayaImgTheme' + options['theme'])
|
250
|
+
$(img).width(squareDimension*0.8)
|
251
|
+
$(img).height(squareDimension*0.8)
|
252
|
+
var x = $("#" + containerDivId).offset().left
|
253
|
+
var y = $("#" + containerDivId).offset().top
|
254
|
+
$(img).css("top",y+board[action.square][1]-middleSquareDimension*0.8)
|
255
|
+
$(img).css("left",x+board[action.square][0]-middleSquareDimension*0.8)
|
256
|
+
return;
|
257
|
+
}
|
258
|
+
|
259
|
+
var sendAction = function(action){
|
260
|
+
//Notify action to other players
|
261
|
+
//[...]
|
262
|
+
return;
|
263
|
+
}
|
264
|
+
|
265
|
+
var onActionReceived = function(action){
|
266
|
+
processAction(action);
|
267
|
+
return;
|
268
|
+
}
|
269
|
+
|
270
|
+
//Return winner's name if exists and null if dont exits.
|
271
|
+
//Return "finish" when the game is blocked.
|
272
|
+
var checkWinner = function(){
|
273
|
+
|
274
|
+
//Check for finish game without winner.
|
275
|
+
var finish=true;
|
276
|
+
for(var i=0; i<board.length; i++){
|
277
|
+
if(board[i][2]==0){
|
278
|
+
finish = false;
|
279
|
+
break;
|
280
|
+
}
|
281
|
+
}
|
282
|
+
if(finish){
|
283
|
+
return "finish";
|
284
|
+
}
|
285
|
+
|
286
|
+
//Check winner
|
287
|
+
//Check if exists three squares with the same symbol consecutively
|
288
|
+
|
289
|
+
//Check horizontal
|
290
|
+
if((board[0][2]==board[1][2])&&(board[1][2]==board[2][2])&&(board[2][2]!=0)){
|
291
|
+
return players[board[0][2]-1];
|
292
|
+
}
|
293
|
+
if((board[3][2]==board[4][2])&&(board[4][2]==board[5][2])&&(board[5][2]!=0)){
|
294
|
+
return players[board[3][2]-1];
|
295
|
+
}
|
296
|
+
if((board[6][2]==board[7][2])&&(board[7][2]==board[8][2])&&(board[8][2]!=0)){
|
297
|
+
return players[board[6][2]-1];
|
298
|
+
}
|
299
|
+
|
300
|
+
//Check vertical
|
301
|
+
if((board[0][2]==board[3][2])&&(board[3][2]==board[6][2])&&(board[6][2]!=0)){
|
302
|
+
return players[board[0][2]-1];
|
303
|
+
}
|
304
|
+
if((board[1][2]==board[4][2])&&(board[4][2]==board[7][2])&&(board[7][2]!=0)){
|
305
|
+
return players[board[1][2]-1];
|
306
|
+
}
|
307
|
+
if((board[2][2]==board[5][2])&&(board[5][2]==board[8][2])&&(board[8][2]!=0)){
|
308
|
+
return players[board[2][2]-1];
|
309
|
+
}
|
310
|
+
|
311
|
+
//Check diagonals
|
312
|
+
if((board[0][2]==board[4][2])&&(board[4][2]==board[8][2])&&(board[8][2]!=0)){
|
313
|
+
return players[board[0][2]-1];
|
314
|
+
}
|
315
|
+
if((board[6][2]==board[4][2])&&(board[4][2]==board[2][2])&&(board[2][2]!=0)){
|
316
|
+
return players[board[6][2]-1];
|
317
|
+
}
|
318
|
+
|
319
|
+
return null;
|
320
|
+
}
|
321
|
+
|
322
|
+
var nextTurn = function(){
|
323
|
+
var playersQuantity = players.length;
|
324
|
+
var indexActualPlayer = players.indexOf(currentPlayer);
|
325
|
+
if(indexActualPlayer==(playersQuantity-1)){
|
326
|
+
currentPlayer=players[0];
|
327
|
+
} else {
|
328
|
+
currentPlayer=players[indexActualPlayer+1];
|
329
|
+
}
|
330
|
+
if(player==currentPlayer){
|
331
|
+
showMessage("Is your turn!")
|
332
|
+
} else {
|
333
|
+
showMessage(currentPlayer + " turn")
|
334
|
+
}
|
335
|
+
}
|
336
|
+
|
337
|
+
var getRandomPlayer = function(){
|
338
|
+
var playersQuantity = players.length;
|
339
|
+
var randomIndex = Math.round(Math.random()*(players.length-1))
|
340
|
+
return players[randomIndex]
|
341
|
+
}
|
342
|
+
|
343
|
+
//Getters
|
344
|
+
var getPlayers = function(){
|
345
|
+
return players;
|
346
|
+
}
|
347
|
+
|
348
|
+
var getOptions = function(){
|
349
|
+
return options;
|
350
|
+
}
|
351
|
+
|
352
|
+
var getDummy = function(){
|
353
|
+
return core;
|
354
|
+
}
|
355
|
+
|
356
|
+
|
357
|
+
return {
|
358
|
+
init: init,
|
359
|
+
getDummy: getDummy,
|
360
|
+
onActionReceived: onActionReceived
|
361
|
+
};
|
362
|
+
|
363
|
+
}) (PRESENCE, jQuery);
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
|
372
|
+
////////////////////
|
373
|
+
//Interface Events
|
374
|
+
////////////////////
|
375
|
+
function play(){
|
376
|
+
$(".chat-gamesthick").css("display","block");
|
377
|
+
}
|
378
|
+
|
379
|
+
function pickGamesButton(uiElement){
|
380
|
+
var slug = $(uiElement.element).attr("id");
|
381
|
+
//clickGamesButton(slug);
|
382
|
+
log("clickGamesButton(slug)" + slug)
|
383
|
+
}
|
384
|
+
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -180,6 +180,17 @@ p.ui-chatbox-notify-text{
|
|
180
180
|
padding: 0px 9px 0px 9px;
|
181
181
|
}
|
182
182
|
|
183
|
+
.chat-gamesthick{
|
184
|
+
/*display: block; */
|
185
|
+
display: none;
|
186
|
+
padding: 0px 1px 0px 1px;
|
187
|
+
}
|
188
|
+
|
189
|
+
div.ui-games-icon{
|
190
|
+
/*width: 100px;
|
191
|
+
height: 100px;*/
|
192
|
+
}
|
193
|
+
|
183
194
|
/* Presence Partial */
|
184
195
|
|
185
196
|
#chat_connecting{
|
data/config/locales/en.yml
CHANGED
data/config/locales/es.yml
CHANGED
metadata
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: social_stream-presence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 8
|
8
|
+
- 7
|
9
|
+
version: 0.8.7
|
6
10
|
platform: ruby
|
7
11
|
authors:
|
8
12
|
- Aldo Gordillo
|
@@ -10,7 +14,7 @@ autorequire:
|
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
16
|
|
13
|
-
date: 2012-03-
|
17
|
+
date: 2012-03-06 00:00:00 +01:00
|
14
18
|
default_executable:
|
15
19
|
dependencies:
|
16
20
|
- !ruby/object:Gem::Dependency
|
@@ -21,6 +25,10 @@ dependencies:
|
|
21
25
|
requirements:
|
22
26
|
- - ~>
|
23
27
|
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 16
|
31
|
+
- 2
|
24
32
|
version: 0.16.2
|
25
33
|
type: :runtime
|
26
34
|
version_requirements: *id001
|
@@ -32,6 +40,8 @@ dependencies:
|
|
32
40
|
requirements:
|
33
41
|
- - ">="
|
34
42
|
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 0
|
35
45
|
version: "0"
|
36
46
|
type: :runtime
|
37
47
|
version_requirements: *id002
|
@@ -43,6 +53,8 @@ dependencies:
|
|
43
53
|
requirements:
|
44
54
|
- - ">="
|
45
55
|
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
46
58
|
version: "0"
|
47
59
|
type: :runtime
|
48
60
|
version_requirements: *id003
|
@@ -54,6 +66,8 @@ dependencies:
|
|
54
66
|
requirements:
|
55
67
|
- - ">="
|
56
68
|
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
57
71
|
version: "0"
|
58
72
|
type: :runtime
|
59
73
|
version_requirements: *id004
|
@@ -65,6 +79,8 @@ dependencies:
|
|
65
79
|
requirements:
|
66
80
|
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 0
|
68
84
|
version: "0"
|
69
85
|
type: :development
|
70
86
|
version_requirements: *id005
|
@@ -97,24 +113,33 @@ files:
|
|
97
113
|
- app/assets/images/emoticons/present.png
|
98
114
|
- app/assets/images/emoticons/rain.png
|
99
115
|
- app/assets/images/emoticons/sun.png
|
116
|
+
- app/assets/images/games/ter/classic_aspa.png
|
117
|
+
- app/assets/images/games/ter/classic_board.png
|
118
|
+
- app/assets/images/games/ter/classic_circle.png
|
119
|
+
- app/assets/images/games/ter/modern_aspa.png
|
120
|
+
- app/assets/images/games/ter/modern_board.png
|
121
|
+
- app/assets/images/games/ter/modern_circle.png
|
100
122
|
- app/assets/images/status/available.png
|
101
123
|
- app/assets/images/status/away.png
|
102
124
|
- app/assets/images/status/chat.png
|
103
125
|
- app/assets/images/status/dnd.png
|
104
126
|
- app/assets/images/status/offline.png
|
105
|
-
- app/assets/javascripts/chat_audio.js.erb
|
106
|
-
- app/assets/javascripts/chat_interface_manager.js.erb
|
107
|
-
- app/assets/javascripts/chat_parser.js
|
108
|
-
- app/assets/javascripts/chat_persistence.js
|
109
|
-
- app/assets/javascripts/chat_utilities.js
|
110
|
-
- app/assets/javascripts/chat_window_manager.js
|
111
127
|
- app/assets/javascripts/jquery.flexselect.sstreampresence.js
|
112
128
|
- app/assets/javascripts/jquery.ui.chatbox.sstreampresence.js
|
113
|
-
- app/assets/javascripts/
|
129
|
+
- app/assets/javascripts/presence.js.erb
|
130
|
+
- app/assets/javascripts/presence_XmppClient.js.erb
|
131
|
+
- app/assets/javascripts/presence_audio.js.erb
|
132
|
+
- app/assets/javascripts/presence_game.js.erb
|
133
|
+
- app/assets/javascripts/presence_game_ter.js.erb
|
134
|
+
- app/assets/javascripts/presence_notifications.js
|
135
|
+
- app/assets/javascripts/presence_parser.js
|
136
|
+
- app/assets/javascripts/presence_persistence.js
|
137
|
+
- app/assets/javascripts/presence_store.js
|
138
|
+
- app/assets/javascripts/presence_uiManager.js.erb
|
139
|
+
- app/assets/javascripts/presence_utilities.js
|
140
|
+
- app/assets/javascripts/presence_videochat.js.erb
|
141
|
+
- app/assets/javascripts/presence_windowManager.js
|
114
142
|
- app/assets/javascripts/social_stream-presence.js
|
115
|
-
- app/assets/javascripts/store.js
|
116
|
-
- app/assets/javascripts/videochat.js.erb
|
117
|
-
- app/assets/javascripts/xmpp_client_management.js.erb
|
118
143
|
- app/assets/stylesheets/chat.css.scss
|
119
144
|
- app/assets/stylesheets/social_stream-presence.css
|
120
145
|
- app/controllers/xmpp_controller.rb
|
@@ -244,17 +269,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
244
269
|
requirements:
|
245
270
|
- - ">="
|
246
271
|
- !ruby/object:Gem::Version
|
272
|
+
segments:
|
273
|
+
- 0
|
247
274
|
version: "0"
|
248
275
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
249
276
|
none: false
|
250
277
|
requirements:
|
251
278
|
- - ">="
|
252
279
|
- !ruby/object:Gem::Version
|
280
|
+
segments:
|
281
|
+
- 0
|
253
282
|
version: "0"
|
254
283
|
requirements: []
|
255
284
|
|
256
285
|
rubyforge_project: social_stream-presence
|
257
|
-
rubygems_version: 1.
|
286
|
+
rubygems_version: 1.3.7
|
258
287
|
signing_key:
|
259
288
|
specification_version: 3
|
260
289
|
summary: Presence capabilities for Social Stream, the core for building social network websites.
|