]> git.example.dev Git - binbsis50.git/commitdiff
fixed #5; added a scrollable history (up and down arrows) of guesses and improved...
authorLuigi Pinca <luigipinca@gmail.com>
Fri, 27 Apr 2012 20:36:04 +0000 (22:36 +0200)
committerLuigi Pinca <luigipinca@gmail.com>
Fri, 27 Apr 2012 20:36:04 +0000 (22:36 +0200)
config.js
package.json
public/static/css/style.css
public/static/js/room.js
server.js
views/room.jade

index aa052b56ab44d72bfe7aab419ebbfba293e4e1da..fad7b5c1f18c4901515c1fed15b9ebd82bdbcd65 100644 (file)
--- a/config.js
+++ b/config.js
@@ -6,6 +6,7 @@ exports.configure = function() {
        this.usersdburl = '';
        this.sessionsecret = '';
        this.songsinarun = 15;
+       this.fifolength = this.songsinarun * 3; // 3 is the number of games with no repeats of songs
        this.threshold = 2; // Edit distance threshold
        this.rooms = ["pop", "rock", "rap", "80s", "mixed"];
        return this;
index e73d1191e234b8f736db46f889222ccadb04ea7b..f6eb75c79cdc4fa35c5630facc71c3cfcf9fe78c 100644 (file)
@@ -7,7 +7,7 @@
     "connect-redis": "1.3.x",
     "express": "2.5.x",
     "express-form": "0.6.x",
-    "jade": "0.24.x",
+    "jade": "0.25.x",
     "redis-url": "0.1.x",
     "socket.io": "0.9.x"
   },
@@ -18,5 +18,5 @@
   "engines": {
     "node": "0.6.x"
   },
-  "version": "0.3.0-5"
+  "version": "0.3.0-8"
 }
\ No newline at end of file
index ab0109ec69481527824ec1b8b8ff2beb96ae4123..ed69b9b359213ef8f1445087109559dc058cfef5 100644 (file)
@@ -476,24 +476,11 @@ input {
        height: 160px;
        background-color: white;
 }
-#chat-top, #chat-bottom {
-       background-color: white;
-       position: absolute;
-       left: 6px;
-       height: 4px;
-       width: 430px;
-       z-index: 1;
-}
-#chat-bottom {
-       bottom: 0;
-}
 #chat {
-       position:absolute;
        height: 152px;
        width: 446px;
-       padding: 4px 6px;
+       margin: 4px 6px;
        overflow: auto;
-       margin: 0;
 }
 .bordered {
        border: 1px solid #ccc;
index aeee36f4bdd61b842e0483fa249489d7b449ea80..976aa4ec69f08fb96c8f86d78df8190222256c7e 100644 (file)
@@ -19,6 +19,8 @@
        var nmstrings = ['Nope, sorry!', 'No way!', 'Fail', 'Nope', 'No', 'That\'s wrong', 'What?!',
                                        'Wrong', 'Haha, what?!', 'You kidding?', 'Don\'t make me laugh', 'You mad?',
                                        'Try again'];
+       var historyvalues = [];
+       var historycursor = 0;
        var DOM = {};
 
        String.prototype.encodeEntities = function() {
                addChatEntry(joinspan);
                updateUsers(data);
 
-               DOM.messagebox.keyup(function(event) {
+               DOM.messagebox.keydown(function(event) {
                        if (event.keyCode === 13) {
                                var val = $.trim(DOM.messagebox.val());
                                if (val !== "") {
                        }
                });
 
-               DOM.guessbox.keyup(function(event) {
-                       if (event.keyCode === 13) {
-                               var val = $.trim(DOM.guessbox.val().toLowerCase());
-                               if (val !== "") {
-                                       socket.emit('guess', val);
-                               }
-                               DOM.guessbox.val("");
+               DOM.guessbox.keydown(function(event) {
+                       switch (event.keyCode) {
+                               case 13: // return
+                                       var guess = $.trim(DOM.guessbox.val());
+                                       if (guess !== "") {
+                                               socket.emit('guess', guess.toLowerCase());
+                                               historyvalues.push(guess);
+                                               if (historyvalues.length > 20) {
+                                                       historyvalues.splice(0, 1);
+                                               }
+                                               historycursor = historyvalues.length;
+                                       }
+                                       DOM.guessbox.val("");
+                                       break;
+                               case 38: // up-arrow
+                                       if (historycursor > 0) {
+                                               DOM.guessbox.val(historyvalues[--historycursor]);
+                                       }
+                                       break;
+                               case 40: // down-arrow
+                                       if (historycursor < historyvalues.length - 1) {
+                                               DOM.guessbox.val(historyvalues[++historycursor]);
+                                       }
+                                       else {
+                                               historycursor = historyvalues.length;
+                                               DOM.guessbox.val("");
+                                       }
                        }
                });
+
                DOM.guessbox.focus();
                
                socket.on('newuser', userJoin);
index 5ef5fc5b3f19cbd1420bdb5fe93de96777a7ddfc..553e10539faa4f2ba2aae7a690385ef471b330b0 100644 (file)
--- a/server.js
+++ b/server.js
@@ -59,10 +59,10 @@ var Captcha = function() {
        ctx.save();
        this.getCode = function() {
                return code;
-       }
+       };
        this.toDataURL = function() {
                return _canvas.toDataURL();
-       }
+       };
 };
 
 http.get("/signup", function(req, res) {
@@ -425,6 +425,10 @@ var amatch = function(subject, guess, enableartistrules) {
                checkDistance(subject.replace(/\-/g, ""), guess, config.threshold)) {
                return true;
        }
+       if (subject.match(/\+/) && 
+               checkDistance(subject.replace(/\+/, "and"), guess, config.threshold)) {
+               return true;
+       }
        if (enableartistrules) {
                if (subject.match(/^the /)) {
                        var nothe = subject.replace(/^the /, "");
@@ -531,7 +535,7 @@ function Room(name) {
        var totusers = 0;
        
        var usersData = Object.create(null);
-       var playedtracks = Object.create(null); // Used to prevent the same song from playing twice in one game
+       var playedtracks = []; // The list of already played songs
        
        var artistName = null;
        var artistlcase = null;
@@ -594,7 +598,7 @@ function Room(name) {
                socket.roomname = roomname;
                socket.join(roomname);
                addUser(socket, true);
-       }
+       };
        
        // A user requested an invalid name
        var invalidNickName = function(socket, feedback) {
@@ -620,7 +624,7 @@ function Room(name) {
                var key = "user:"+data.nickname;
                usersdb.exists(key, function(err, resp) {
                        if (resp === 1) { // User already exists
-                               feedback = '<span class="label label-important">That name belongs '
+                               feedback = '<span class="label label-important">That name belongs ';
                                feedback += 'to a registered user.</span>';
                                return invalidNickName(socket, feedback);
                        }
@@ -815,10 +819,10 @@ function Room(name) {
                songsdb.srandmember(roomname, function(err, res) {
                        songsdb.hmget(res, "artistName", "trackName", "collectionName", "previewUrl",
                                                        "artworkUrl60", "trackViewUrl", function(e, replies) {
-                               if (playedtracks[res]) {
+                               if (playedtracks.indexOf(res) !== -1) {
                                        return sendLoadTrack();
                                }
-                               playedtracks[res] = true;
+                               playedtracks.push(res);
                                artistName = replies[0];
                                artistlcase = artistName.toLowerCase();
                                trackName = replies[1];
@@ -896,7 +900,9 @@ function Room(name) {
 
        var reset = function() {
                songcounter = 0;
-               playedtracks = Object.create(null);
+               if (playedtracks.length === config.fifolength) {
+                       playedtracks.splice(0, config.songsinarun);
+               }
                sendLoadTrack();
        };
 
index d611b37f5e8949f6c003a7adc14ebc48acd3a161..1f4d5f6011d4b79f222047ff561b6e32b9c2b649 100644 (file)
@@ -76,9 +76,7 @@ html
                                        .span8
                                                a#toggle-chat Hide chat
                                                #chat-outer-wrapper
-                                                       #chat-wrapper.bordered.relative
-                                                               #chat-top
-                                                               #chat-bottom
+                                                       #chat-wrapper.bordered
                                                                ul#chat.unstyled
                                                        #message-wrapper
                                                                span#recipient