diff --git a/TODO.md b/TODO.md index 1e4ad31..df7e531 100644 --- a/TODO.md +++ b/TODO.md @@ -41,3 +41,25 @@ Browser Server + +---- + +Decisions: + +Team A, B +Users can come and join at any point +Best of 5 (or x) rounds + + +Drawer +- sends instruction/s +- index, action, coords + +Server +- store the instructions into an array +- pump them out as and when to subscribers + + +Receiver +- on log in, subscribe to drawing stream +- maintain local array of drawing diff --git a/src/html/guess-word.html b/src/html/guess-word.html index 268586f..1fb38d4 100644 --- a/src/html/guess-word.html +++ b/src/html/guess-word.html @@ -1,5 +1,8 @@

Guess word

+ + +

Please enter a guess...

diff --git a/src/js/pictionary.js b/src/js/pictionary.js index 1bdae27..7583fe7 100644 --- a/src/js/pictionary.js +++ b/src/js/pictionary.js @@ -48,9 +48,9 @@ pages.add('/view-word', '/src/html/view-word.html', function() { $('.word').text(word); pad = PIC.createPad('#myCanvas'); - pad.onChange(function (move) { + pad.onStep(function (step) { comms.send({ - draw: move + step: step }); }) comms.connect(function () { @@ -65,7 +65,9 @@ }); pages.add('/guess-word', '/src/html/guess-word.html', function() { - $('#guess').val(guess); + pad = PIC.createPad('#myCanvas'); + + $('#guess').val(guess); $('#enterGuess').submit(function (e) { e.preventDefault(); guess = $('#guess').val(); @@ -76,6 +78,11 @@ $('#feedback').text('Please try again...'); } }); + + $('#fetchDrawing').click(function () { + comms.send('Can i have a drawing please?') + + }) }); pages.add('/watch-team', '/src/html/watch-team.html'); @@ -96,20 +103,21 @@ comms.message(function (data) { if (data.users) { - console.log('We got a message!', data) var users = ''; for (u in data.users) { users += data.users[u] + ' '; } $('#others').text(users) } - + if (data.step) { + pad.step(data.step); + } if (data.teams) { teams = data.teams; pages.open('/overview') } if (data.draw) { - pad.add(data.draw); + //pad.add(data.draw); } }) diff --git a/src/js/sketchpad.js b/src/js/sketchpad.js index cdade04..066a014 100644 --- a/src/js/sketchpad.js +++ b/src/js/sketchpad.js @@ -1,122 +1,126 @@ var PIC = window.PIC || {}; -PIC.createPad = function (padSelector) { +PIC.createPad = function (selector) { - var $canvas = $(padSelector), - $doc = $(document), - context = $canvas[0].getContext('2d'), - penX = 0, - penY = 0, - isPenDown = false, - path = {}, - onChangeCallbacks = []; - - $canvas.clear = function() { - context.clearRect(0,0,10000,10000); - }; + var pen, pad, callbacks; - // The path inst is the array that stores the pad's drawing history - path.inst = []; + callbacks = []; - // Add instruction to the pad. Accepted values: 'up', 'down', 'move, x, y' - path.add = function (word, x, y) { - var ins = {} - ins.ins = word; - if (x && y) { - ins.x = x; - ins.y = y; - } - this.inst.push(ins); - this.render(); + pen = (function () { - for (var i=0; i