From: Luigi Pinca Date: Fri, 27 Apr 2012 20:36:04 +0000 (+0200) Subject: fixed #5; added a scrollable history (up and down arrows) of guesses and improved... X-Git-Url: https://git.saalbach.dev/?a=commitdiff_plain;h=e1566e089f65eda14fd08383b10ecc9100d2ea9d;p=binbsis50.git fixed #5; added a scrollable history (up and down arrows) of guesses and improved the random song selection --- diff --git a/config.js b/config.js index aa052b5..fad7b5c 100644 --- 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; diff --git a/package.json b/package.json index e73d119..f6eb75c 100644 --- a/package.json +++ b/package.json @@ -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 diff --git a/public/static/css/style.css b/public/static/css/style.css index ab0109e..ed69b9b 100644 --- a/public/static/css/style.css +++ b/public/static/css/style.css @@ -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; diff --git a/public/static/js/room.js b/public/static/js/room.js index aeee36f..976aa4e 100644 --- a/public/static/js/room.js +++ b/public/static/js/room.js @@ -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() { @@ -106,7 +108,7 @@ 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 !== "") { @@ -117,15 +119,36 @@ } }); - 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); diff --git a/server.js b/server.js index 5ef5fc5..553e105 100644 --- 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 = 'That name belongs ' + feedback = 'That name belongs '; feedback += 'to a registered user.'; 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(); }; diff --git a/views/room.jade b/views/room.jade index d611b37..1f4d5f6 100644 --- a/views/room.jade +++ b/views/room.jade @@ -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