Skip to content

Commit edc488b

Browse files
committed
a
1 parent dada6cb commit edc488b

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

source/games/uno/HandSwapSubstate.hx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,12 @@ class HandSwapSubstate extends MusicBeatSubstate {
429429
});
430430
shouldBeClosed = true;
431431
close();
432+
meantToClose = true;
432433
}
434+
var meantToClose:Bool = false;
433435

434436
private function selectPlayer(index:Int):Void {
435-
if (!animationComplete || index < 0 || index >= availablePlayers.length) return;
437+
if (!animationComplete || index < 0 || index >= availablePlayers.length || meantToClose) return;
436438

437439
try {
438440
var selectedPlayer = availablePlayers[index];

source/games/uno/UnoTestState.hx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,9 @@ class UnoTestState extends MusicBeatState {
390390

391391
// Open the hand swap substate for player selection
392392
var handSwapSubstate = new HandSwapSubstate(currentPlayer, availablePlayers, function(selectedPlayer:UnoPlayer) {
393-
// Reset waiting flag first
394-
waitingForHandSwap = false;
393+
try {
394+
// Reset waiting flag first
395+
waitingForHandSwap = false;
395396

396397
// Perform the actual hand swap through the rules system
397398
if (performHandSwap != null)
@@ -408,6 +409,7 @@ class UnoTestState extends MusicBeatState {
408409
performHandSwap = null;
409410
unoGame.onSevenRuleHandSwap = null; // Clear the handler to prevent reuse
410411
return;
412+
}
411413
}, function(selectedPlayer:UnoPlayer) {
412414
// Reset waiting flag first
413415
waitingForHandSwap = false;
@@ -1288,7 +1290,7 @@ class UnoTestState extends MusicBeatState {
12881290
}
12891291
isPlayingCard = false;
12901292
resetCardSelection();
1291-
} private function updateInstructionText(text:String, ?doFade:Bool = false):Void {
1293+
} private function updateInstructionText(text:String, ?doFade:Bool = false):Void {
12921294
var originalText = instructionText.text;
12931295
if (instructionText != null) {
12941296
instructionText.text = text;
@@ -1328,6 +1330,14 @@ class UnoTestState extends MusicBeatState {
13281330
override function update(elapsed:Float) {
13291331
super.update(elapsed);
13301332

1333+
// Safety check: Reset stuck hand swap flag after 10 seconds
1334+
if (waitingForHandSwap && haxe.Timer.stamp() - lastHandSwapTime > 10.0 && subState == null) {
1335+
trace("Hand swap taking too long, resetting flags");
1336+
waitingForHandSwap = false;
1337+
UnoRules.resetHandSwapFlag();
1338+
updateInstructionText("Hand swap timeout - continuing game", true);
1339+
}
1340+
13311341
// Handle CPU turns
13321342
if (unoGame != null && unoGame.turnManager != null && unoGame.turnManager.getCurrentPlayer() != null) {
13331343
var currentPlayer = unoGame.turnManager.getCurrentPlayer();

source/games/uno/backend/UnoGame.hx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ class UnoGame {
138138
roundNumber++;
139139
isRoundActive = true;
140140
drawStack = 0;
141+
handSwapProcessed = false; // Reset hand swap flag for new round
142+
UnoRules.resetHandSwapFlag(); // Reset static flag as well
141143

142144
// Reset deck and hands
143145
deck.reset(customColors, customCards);
@@ -244,8 +246,7 @@ class UnoGame {
244246
// After eveything is done
245247
afterCardPlayed(player, playedCard);
246248

247-
// Next turn
248-
handSwapProcessed = false; // Reset for next turn
249+
// Next turn (handSwapProcessed will be reset when turn actually starts)
249250
turnManager.nextTurn();
250251
updateGameState();
251252

source/games/uno/backend/UnoRules.hx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ class UnoRules {
157157
(playerCard.type != NUMBER || playerCard.value == topCard.value);
158158
}
159159

160+
// Static flag to prevent multiple simultaneous hand swaps
161+
private static var handSwapInProgress:Bool = false;
162+
160163
/**
161164
* Apply seven-zero rule effects
162165
*/
@@ -165,7 +168,8 @@ class UnoRules {
165168

166169
if (card.value == 7) {
167170
// Player who played 7 swaps hands with another player of their choice
168-
if (onSevenRuleHandSwap != null) {
171+
if (onSevenRuleHandSwap != null && !handSwapInProgress) {
172+
handSwapInProgress = true; // Set flag to prevent concurrent swaps
169173
var currentPlayer = players[currentPlayerIndex];
170174
var availablePlayers = players.filter(p -> p != currentPlayer);
171175

@@ -190,6 +194,9 @@ class UnoRules {
190194
} else {
191195
trace('Hand swap cancelled or invalid selection');
192196
}
197+
198+
// Always reset the flag when swap is complete (or cancelled)
199+
handSwapInProgress = false;
193200
};
194201

195202
// Call the UI callback with our swap function
@@ -210,6 +217,13 @@ class UnoRules {
210217
}
211218
}
212219

220+
/**
221+
* Reset hand swap progress flag (for recovery from errors)
222+
*/
223+
public static function resetHandSwapFlag():Void {
224+
handSwapInProgress = false;
225+
}
226+
213227
/**
214228
* Check if card being played is a +2 during a stack (Allows any color for any plus stack)
215229
*/

0 commit comments

Comments
 (0)