@@ -5,6 +5,7 @@ var socket = io();
55
66
77// SAVING LOCAL STATE -- GLOBAL VARS (ugh)
8+ var previousPlayerId ;
89var currentPlayerId ;
910var nextPlayerId ;
1011var animationId ;
@@ -284,34 +285,45 @@ function handleTurnChange (turnData) {
284285 // Remove highlight from previous current player's name in playerListView
285286 togglePlayerHighlight ( false ) ;
286287
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, ) ;
289290
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 ) {
296293 console . log ( "User's turn is about to end." ) ;
297294
298295 // If the current player is about to change,
299296 if ( currentPlayerId !== previousPlayerId ) {
300297
298+ console . log ( "> > > > > > currentPlayerId != previousPlayerId so fork/edit!" ) ;
299+ console . log ( "\t\t prevPlayerId: " + previousPlayerId + ", currPlayerId: " + currentPlayerId ) ;
301300 //console.log("handleTurnChange: now forking and editing gist " + turnData.gist.id);
302301
303302 // fork and edit the current gist on behalf of previous player and send new ID to server
304303 forkAndEditGist ( turnData . gist . id , editor . getValue ( ) ) ;
305304
306305 // Otherwise, JUST EDIT the current gist on behalf of previous player and send new ID to server
307306 } else {
308-
307+ console . log ( "< < < < < < currentPlayerId == previousPlayerId so only edit!" ) ;
308+ console . log ( "\t\t prevPlayerId: " + previousPlayerId + ", currPlayerId: " + currentPlayerId ) ;
309309 //console.log("handleTurnChange: now editing gist " + turnData.gist.id);
310310 editGist ( turnData . gist . id , editor . getValue ( ) ) ;
311311
312312 }
313313 }
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 ;
314321
322+
323+ //console.log("********* **** handleTurnChange SECOND *** ********");
324+ //console.log("previousPlayerId: " + previousPlayerId + "\n\tcurrentPlayerId: "+ currentPlayerId + "\n\tnextPlayerId: " + nextPlayerId, );
325+ //console.dir(turnData);
326+
315327 // If user is no longer the current player, prevent them from typing/broadcasting!
316328 if ( socket . id !== currentPlayerId ) {
317329 console . log ( "User's turn is over." ) ;
@@ -342,10 +354,8 @@ function handleUpdateState (turnData) {
342354 // Remove highlight from previous current player's name in playerListView
343355 togglePlayerHighlight ( false ) ;
344356
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 ;
349359 currentPlayerId = turnData . current . id ;
350360 nextPlayerId = turnData . next . id ;
351361
0 commit comments