@@ -5,6 +5,7 @@ var socket = io();
5
5
6
6
7
7
// SAVING LOCAL STATE -- GLOBAL VARS (ugh)
8
+ var previousPlayerId ;
8
9
var currentPlayerId ;
9
10
var nextPlayerId ;
10
11
var animationId ;
@@ -284,34 +285,45 @@ function handleTurnChange (turnData) {
284
285
// Remove highlight from previous current player's name in playerListView
285
286
togglePlayerHighlight ( false ) ;
286
287
287
- // Temporarily save the previous player ID for later comparison
288
- var previousPlayerId = currentPlayerId ;
288
+ //console.log("********* **** handleTurnChange FIRST *** ********");
289
+ //console.log("previousPlayerId: " + previousPlayerId + "\n\tcurrentPlayerId: "+ currentPlayerId + "\n\tnextPlayerId: " + nextPlayerId, ) ;
289
290
290
- // Update local state
291
- currentPlayerId = turnData . current . id ;
292
- nextPlayerId = turnData . next . id ;
293
-
294
- // If user's turn is ending and a Gist exists, fork and/or edit the gist before passing control to next player!
295
- if ( socket . id === previousPlayerId && turnData . gist != null ) {
291
+ // If current user's turn is ending and a Gist exists, fork and/or edit the gist before passing control to next player!
292
+ if ( socket . id === currentPlayerId && turnData . gist != null ) {
296
293
console . log ( "User's turn is about to end." ) ;
297
294
298
295
// If the current player is about to change,
299
296
if ( currentPlayerId !== previousPlayerId ) {
300
297
298
+ console . log ( "> > > > > > currentPlayerId != previousPlayerId so fork/edit!" ) ;
299
+ console . log ( "\t\t prevPlayerId: " + previousPlayerId + ", currPlayerId: " + currentPlayerId ) ;
301
300
//console.log("handleTurnChange: now forking and editing gist " + turnData.gist.id);
302
301
303
302
// fork and edit the current gist on behalf of previous player and send new ID to server
304
303
forkAndEditGist ( turnData . gist . id , editor . getValue ( ) ) ;
305
304
306
305
// Otherwise, JUST EDIT the current gist on behalf of previous player and send new ID to server
307
306
} else {
308
-
307
+ console . log ( "< < < < < < currentPlayerId == previousPlayerId so only edit!" ) ;
308
+ console . log ( "\t\t prevPlayerId: " + previousPlayerId + ", currPlayerId: " + currentPlayerId ) ;
309
309
//console.log("handleTurnChange: now editing gist " + turnData.gist.id);
310
310
editGist ( turnData . gist . id , editor . getValue ( ) ) ;
311
311
312
312
}
313
313
}
314
+
315
+
316
+
317
+ // Update local state to reflect completed turn change!
318
+ previousPlayerId = turnData . previous . id ;
319
+ currentPlayerId = turnData . current . id ;
320
+ nextPlayerId = turnData . next . id ;
314
321
322
+
323
+ //console.log("********* **** handleTurnChange SECOND *** ********");
324
+ //console.log("previousPlayerId: " + previousPlayerId + "\n\tcurrentPlayerId: "+ currentPlayerId + "\n\tnextPlayerId: " + nextPlayerId, );
325
+ //console.dir(turnData);
326
+
315
327
// If user is no longer the current player, prevent them from typing/broadcasting!
316
328
if ( socket . id !== currentPlayerId ) {
317
329
console . log ( "User's turn is over." ) ;
@@ -342,10 +354,8 @@ function handleUpdateState (turnData) {
342
354
// Remove highlight from previous current player's name in playerListView
343
355
togglePlayerHighlight ( false ) ;
344
356
345
- // Temporarily save the previous player ID for later comparison
346
- var previousPlayerId = currentPlayerId ;
347
-
348
- // Update local state
357
+ // Update local state
358
+ previousPlayerId = turnData . previous . id ;
349
359
currentPlayerId = turnData . current . id ;
350
360
nextPlayerId = turnData . next . id ;
351
361
0 commit comments