Skip to content

Commit

Permalink
Add shuffle
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed May 9, 2023
1 parent dc3437c commit 747fab2
Show file tree
Hide file tree
Showing 7 changed files with 936 additions and 5 deletions.
4 changes: 3 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@
"moveCards": "Move cards",
"location": "Location",
"count": "Count",
"putCards": "Put cards"
"putCards": "Put cards",
"changeVisibility": "Change visibility",
"change": "Change"
}
9 changes: 9 additions & 0 deletions app/lib/logic/connection/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,13 @@ class ClientGameConnection with GameConnection, ConnectedGameConnection {
void removeDeck(int deckIndex, int? seatIndex) {
send(ServerConnectionMessage.removeDeck(deckIndex, seatIndex));
}

void changeVisibility(int index, int? seatIndex, DeckVisibility visibility) {
send(
ServerConnectionMessage.changeVisibility(index, seatIndex, visibility));
}

void shuffle(int index, int? seatIndex) {
send(ServerConnectionMessage.shuffle(index, seatIndex));
}
}
36 changes: 36 additions & 0 deletions app/lib/logic/connection/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class ServerConnectionMessage with _$ServerConnectionMessage {
const factory ServerConnectionMessage.leaveSeat(int index) =
LeaveSeatServerConnectionMessage;

const factory ServerConnectionMessage.shuffle(int deckIndex, int? seatIndex) =
ShuffleServerConnectionMessage;

const factory ServerConnectionMessage.changeVisibility(
int deckIndex, int? seatIndex, DeckVisibility visibility) =
ChangeVisibilityServerConnectionMessage;

factory ServerConnectionMessage.fromJson(Map<String, dynamic> json) =>
_$ServerConnectionMessageFromJson(json);
}
Expand Down Expand Up @@ -344,6 +351,35 @@ class ServerGameConnection with GameConnection {
}
_changeState(newState);
},
changeVisibility: (deckIndex, seatIndex, visibility) {
if (seatIndex != null) {
_changeState(state.copyWith(
seats: List<GameSeat>.from(state.seats)
..[seatIndex] = state.seats[seatIndex].copyWith(
decks: List<GameDeck>.from(state.seats[seatIndex].decks)
..[deckIndex] = state.seats[seatIndex].decks[deckIndex]
.copyWith(visibility: visibility))));
} else {
_changeState(state.copyWith(
decks: List<GameDeck>.from(state.decks)
..[deckIndex] =
state.decks[deckIndex].copyWith(visibility: visibility)));
}
},
shuffle: (deckIndex, seatIndex) {
if (seatIndex != null) {
_changeState(state.copyWith(
seats: List<GameSeat>.from(state.seats)
..[seatIndex] = state.seats[seatIndex].copyWith(
decks: List<GameDeck>.from(state.seats[seatIndex].decks)
..[deckIndex] =
state.seats[seatIndex].decks[deckIndex].shuffle())));
} else {
_changeState(state.copyWith(
decks: List<GameDeck>.from(state.decks)
..[deckIndex] = state.decks[deckIndex].shuffle()));
}
},
);
}
}
Expand Down
Loading

0 comments on commit 747fab2

Please sign in to comment.