From dc3437c6266cfbba1206002a22022d76fa4705a3 Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Tue, 9 May 2023 12:27:17 +0200 Subject: [PATCH] Finish functionality --- app/lib/l10n/app_en.arb | 5 +- app/lib/logic/connection/client.dart | 16 + app/lib/logic/connection/server.dart | 62 ++- app/lib/logic/connection/server.freezed.dart | 489 +++++++++++++++++++ app/lib/logic/connection/server.g.dart | 30 ++ app/lib/logic/state.dart | 43 +- app/lib/pages/game/card.dart | 129 ----- app/lib/pages/game/cards.dart | 332 +++++++++++++ app/lib/pages/game/deck.dart | 116 ++++- app/lib/pages/game/view.dart | 24 +- 10 files changed, 1093 insertions(+), 153 deletions(-) create mode 100644 app/lib/pages/game/cards.dart diff --git a/app/lib/l10n/app_en.arb b/app/lib/l10n/app_en.arb index 8fa19f1..05869b6 100644 --- a/app/lib/l10n/app_en.arb +++ b/app/lib/l10n/app_en.arb @@ -32,5 +32,8 @@ "remove": "Remove", "move": "Move", "deck": "Deck", - "moveCards": "Move cards" + "moveCards": "Move cards", + "location": "Location", + "count": "Count", + "putCards": "Put cards" } diff --git a/app/lib/logic/connection/client.dart b/app/lib/logic/connection/client.dart index 203baf7..19f4da3 100644 --- a/app/lib/logic/connection/client.dart +++ b/app/lib/logic/connection/client.dart @@ -118,4 +118,20 @@ class ClientGameConnection with GameConnection, ConnectedGameConnection { void removeCards(List cards) { send(ServerConnectionMessage.removeCards(cards)); } + + void putCards(int deckIndex, int? seatIndex, PickLocation location, int count, + int movedDeckIndex, int? movedSeatIndex) { + send(ServerConnectionMessage.putCards( + deckIndex, + seatIndex, + location, + count, + movedDeckIndex, + movedSeatIndex, + )); + } + + void removeDeck(int deckIndex, int? seatIndex) { + send(ServerConnectionMessage.removeDeck(deckIndex, seatIndex)); + } } diff --git a/app/lib/logic/connection/server.dart b/app/lib/logic/connection/server.dart index cdedc31..55475b0 100644 --- a/app/lib/logic/connection/server.dart +++ b/app/lib/logic/connection/server.dart @@ -33,6 +33,15 @@ class ServerConnectionMessage with _$ServerConnectionMessage { List cards, int deckIndex, int? seatIndex) = AddCardsServerConnectionMessage; + const factory ServerConnectionMessage.putCards( + int deckIndex, + int? seatIndex, + PickLocation location, + int count, + int movedDeckIndex, + int? movedSeatIndex, + ) = PutCardsServerConnectionMessage; + const factory ServerConnectionMessage.removeCards(List cards) = RemoveCardsServerConnectionMessage; @@ -160,7 +169,9 @@ class ServerGameConnection with GameConnection { final found = deckIndexes.any((element) => element.deckIndex == de.key && element.cardIndex == e.key); - addingCards.add(e.value); + if (found) { + addingCards.add(e.value); + } return !found; }) .map((e) => e.value) @@ -181,7 +192,9 @@ class ServerGameConnection with GameConnection { element.deckIndex == de.key && element.seatIndex == se.key && element.cardIndex == e.key); - addingCards.add(e.value); + if (found) { + addingCards.add(e.value); + } return !found; }) .map((e) => e.value) @@ -286,6 +299,51 @@ class ServerGameConnection with GameConnection { _removeCards(cards); _changeState(state); }, + putCards: (deckIndex, seatIndex, location, count, movedDeckIndex, + movedSeatIndex) { + var cards = []; + var newState = state; + if (seatIndex != null) { + final removeState = state.seats[seatIndex].decks[deckIndex] + .removeCards(count, location); + newState = state.copyWith( + seats: List.from(state.seats) + ..[seatIndex] = state.seats[seatIndex].copyWith( + decks: List.from(state.seats[seatIndex].decks) + ..[deckIndex] = removeState.deck)); + cards.addAll(removeState.removedCards); + } else { + final removeState = + state.decks[deckIndex].removeCards(count, location); + newState = state.copyWith( + decks: List.from(state.decks) + ..[deckIndex] = removeState.deck); + cards.addAll(removeState.removedCards); + } + if (movedSeatIndex != null) { + newState = newState.copyWith( + seats: List.from(newState.seats) + ..[movedSeatIndex] = newState.seats[movedSeatIndex].copyWith( + decks: List.from( + newState.seats[movedSeatIndex].decks) + ..[movedDeckIndex] = newState + .seats[movedSeatIndex].decks[movedDeckIndex] + .copyWith( + cards: [ + ...newState.seats[movedSeatIndex] + .decks[movedDeckIndex].cards, + ...cards + ], + ))); + } else { + newState = newState.copyWith( + decks: List.from(newState.decks) + ..[movedDeckIndex] = newState.decks[movedDeckIndex].copyWith( + cards: [...newState.decks[movedDeckIndex].cards, ...cards], + )); + } + _changeState(newState); + }, ); } } diff --git a/app/lib/logic/connection/server.freezed.dart b/app/lib/logic/connection/server.freezed.dart index 9a3aba9..eda6e2c 100644 --- a/app/lib/logic/connection/server.freezed.dart +++ b/app/lib/logic/connection/server.freezed.dart @@ -29,6 +29,8 @@ ServerConnectionMessage _$ServerConnectionMessageFromJson( return AddSeatServerConnectionMessage.fromJson(json); case 'addCards': return AddCardsServerConnectionMessage.fromJson(json); + case 'putCards': + return PutCardsServerConnectionMessage.fromJson(json); case 'removeCards': return RemoveCardsServerConnectionMessage.fromJson(json); case 'removeSeat': @@ -56,6 +58,14 @@ mixin _$ServerConnectionMessage { required TResult Function( List cards, int deckIndex, int? seatIndex) addCards, + required TResult Function( + int deckIndex, + int? seatIndex, + PickLocation location, + int count, + int movedDeckIndex, + int? movedSeatIndex) + putCards, required TResult Function(List cards) removeCards, required TResult Function(int index) removeSeat, required TResult Function(int index) joinSeat, @@ -71,6 +81,9 @@ mixin _$ServerConnectionMessage { TResult? Function(String name)? addSeat, TResult? Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult? Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult? Function(List cards)? removeCards, TResult? Function(int index)? removeSeat, TResult? Function(int index)? joinSeat, @@ -86,6 +99,9 @@ mixin _$ServerConnectionMessage { TResult Function(String name)? addSeat, TResult Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult Function(List cards)? removeCards, TResult Function(int index)? removeSeat, TResult Function(int index)? joinSeat, @@ -104,6 +120,7 @@ mixin _$ServerConnectionMessage { removeDeck, required TResult Function(AddSeatServerConnectionMessage value) addSeat, required TResult Function(AddCardsServerConnectionMessage value) addCards, + required TResult Function(PutCardsServerConnectionMessage value) putCards, required TResult Function(RemoveCardsServerConnectionMessage value) removeCards, required TResult Function(RemoveSeatServerConnectionMessage value) @@ -120,6 +137,7 @@ mixin _$ServerConnectionMessage { TResult? Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult? Function(AddSeatServerConnectionMessage value)? addSeat, TResult? Function(AddCardsServerConnectionMessage value)? addCards, + TResult? Function(PutCardsServerConnectionMessage value)? putCards, TResult? Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult? Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult? Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -134,6 +152,7 @@ mixin _$ServerConnectionMessage { TResult Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult Function(AddSeatServerConnectionMessage value)? addSeat, TResult Function(AddCardsServerConnectionMessage value)? addCards, + TResult Function(PutCardsServerConnectionMessage value)? putCards, TResult Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -223,6 +242,14 @@ class _$FetchPlayersServerConnectionMessage required TResult Function( List cards, int deckIndex, int? seatIndex) addCards, + required TResult Function( + int deckIndex, + int? seatIndex, + PickLocation location, + int count, + int movedDeckIndex, + int? movedSeatIndex) + putCards, required TResult Function(List cards) removeCards, required TResult Function(int index) removeSeat, required TResult Function(int index) joinSeat, @@ -241,6 +268,9 @@ class _$FetchPlayersServerConnectionMessage TResult? Function(String name)? addSeat, TResult? Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult? Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult? Function(List cards)? removeCards, TResult? Function(int index)? removeSeat, TResult? Function(int index)? joinSeat, @@ -259,6 +289,9 @@ class _$FetchPlayersServerConnectionMessage TResult Function(String name)? addSeat, TResult Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult Function(List cards)? removeCards, TResult Function(int index)? removeSeat, TResult Function(int index)? joinSeat, @@ -283,6 +316,7 @@ class _$FetchPlayersServerConnectionMessage removeDeck, required TResult Function(AddSeatServerConnectionMessage value) addSeat, required TResult Function(AddCardsServerConnectionMessage value) addCards, + required TResult Function(PutCardsServerConnectionMessage value) putCards, required TResult Function(RemoveCardsServerConnectionMessage value) removeCards, required TResult Function(RemoveSeatServerConnectionMessage value) @@ -302,6 +336,7 @@ class _$FetchPlayersServerConnectionMessage TResult? Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult? Function(AddSeatServerConnectionMessage value)? addSeat, TResult? Function(AddCardsServerConnectionMessage value)? addCards, + TResult? Function(PutCardsServerConnectionMessage value)? putCards, TResult? Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult? Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult? Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -319,6 +354,7 @@ class _$FetchPlayersServerConnectionMessage TResult Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult Function(AddSeatServerConnectionMessage value)? addSeat, TResult Function(AddCardsServerConnectionMessage value)? addCards, + TResult Function(PutCardsServerConnectionMessage value)? putCards, TResult Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -437,6 +473,14 @@ class _$ChatMessageServerConnectionMessage required TResult Function( List cards, int deckIndex, int? seatIndex) addCards, + required TResult Function( + int deckIndex, + int? seatIndex, + PickLocation location, + int count, + int movedDeckIndex, + int? movedSeatIndex) + putCards, required TResult Function(List cards) removeCards, required TResult Function(int index) removeSeat, required TResult Function(int index) joinSeat, @@ -455,6 +499,9 @@ class _$ChatMessageServerConnectionMessage TResult? Function(String name)? addSeat, TResult? Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult? Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult? Function(List cards)? removeCards, TResult? Function(int index)? removeSeat, TResult? Function(int index)? joinSeat, @@ -473,6 +520,9 @@ class _$ChatMessageServerConnectionMessage TResult Function(String name)? addSeat, TResult Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult Function(List cards)? removeCards, TResult Function(int index)? removeSeat, TResult Function(int index)? joinSeat, @@ -497,6 +547,7 @@ class _$ChatMessageServerConnectionMessage removeDeck, required TResult Function(AddSeatServerConnectionMessage value) addSeat, required TResult Function(AddCardsServerConnectionMessage value) addCards, + required TResult Function(PutCardsServerConnectionMessage value) putCards, required TResult Function(RemoveCardsServerConnectionMessage value) removeCards, required TResult Function(RemoveSeatServerConnectionMessage value) @@ -516,6 +567,7 @@ class _$ChatMessageServerConnectionMessage TResult? Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult? Function(AddSeatServerConnectionMessage value)? addSeat, TResult? Function(AddCardsServerConnectionMessage value)? addCards, + TResult? Function(PutCardsServerConnectionMessage value)? putCards, TResult? Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult? Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult? Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -533,6 +585,7 @@ class _$ChatMessageServerConnectionMessage TResult Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult Function(AddSeatServerConnectionMessage value)? addSeat, TResult Function(AddCardsServerConnectionMessage value)? addCards, + TResult Function(PutCardsServerConnectionMessage value)? putCards, TResult Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -675,6 +728,14 @@ class _$AddDeckServerConnectionMessage required TResult Function( List cards, int deckIndex, int? seatIndex) addCards, + required TResult Function( + int deckIndex, + int? seatIndex, + PickLocation location, + int count, + int movedDeckIndex, + int? movedSeatIndex) + putCards, required TResult Function(List cards) removeCards, required TResult Function(int index) removeSeat, required TResult Function(int index) joinSeat, @@ -693,6 +754,9 @@ class _$AddDeckServerConnectionMessage TResult? Function(String name)? addSeat, TResult? Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult? Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult? Function(List cards)? removeCards, TResult? Function(int index)? removeSeat, TResult? Function(int index)? joinSeat, @@ -711,6 +775,9 @@ class _$AddDeckServerConnectionMessage TResult Function(String name)? addSeat, TResult Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult Function(List cards)? removeCards, TResult Function(int index)? removeSeat, TResult Function(int index)? joinSeat, @@ -735,6 +802,7 @@ class _$AddDeckServerConnectionMessage removeDeck, required TResult Function(AddSeatServerConnectionMessage value) addSeat, required TResult Function(AddCardsServerConnectionMessage value) addCards, + required TResult Function(PutCardsServerConnectionMessage value) putCards, required TResult Function(RemoveCardsServerConnectionMessage value) removeCards, required TResult Function(RemoveSeatServerConnectionMessage value) @@ -754,6 +822,7 @@ class _$AddDeckServerConnectionMessage TResult? Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult? Function(AddSeatServerConnectionMessage value)? addSeat, TResult? Function(AddCardsServerConnectionMessage value)? addCards, + TResult? Function(PutCardsServerConnectionMessage value)? putCards, TResult? Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult? Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult? Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -771,6 +840,7 @@ class _$AddDeckServerConnectionMessage TResult Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult Function(AddSeatServerConnectionMessage value)? addSeat, TResult Function(AddCardsServerConnectionMessage value)? addCards, + TResult Function(PutCardsServerConnectionMessage value)? putCards, TResult Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -904,6 +974,14 @@ class _$RemoveDeckServerConnectionMessage required TResult Function( List cards, int deckIndex, int? seatIndex) addCards, + required TResult Function( + int deckIndex, + int? seatIndex, + PickLocation location, + int count, + int movedDeckIndex, + int? movedSeatIndex) + putCards, required TResult Function(List cards) removeCards, required TResult Function(int index) removeSeat, required TResult Function(int index) joinSeat, @@ -922,6 +1000,9 @@ class _$RemoveDeckServerConnectionMessage TResult? Function(String name)? addSeat, TResult? Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult? Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult? Function(List cards)? removeCards, TResult? Function(int index)? removeSeat, TResult? Function(int index)? joinSeat, @@ -940,6 +1021,9 @@ class _$RemoveDeckServerConnectionMessage TResult Function(String name)? addSeat, TResult Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult Function(List cards)? removeCards, TResult Function(int index)? removeSeat, TResult Function(int index)? joinSeat, @@ -964,6 +1048,7 @@ class _$RemoveDeckServerConnectionMessage removeDeck, required TResult Function(AddSeatServerConnectionMessage value) addSeat, required TResult Function(AddCardsServerConnectionMessage value) addCards, + required TResult Function(PutCardsServerConnectionMessage value) putCards, required TResult Function(RemoveCardsServerConnectionMessage value) removeCards, required TResult Function(RemoveSeatServerConnectionMessage value) @@ -983,6 +1068,7 @@ class _$RemoveDeckServerConnectionMessage TResult? Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult? Function(AddSeatServerConnectionMessage value)? addSeat, TResult? Function(AddCardsServerConnectionMessage value)? addCards, + TResult? Function(PutCardsServerConnectionMessage value)? putCards, TResult? Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult? Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult? Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -1000,6 +1086,7 @@ class _$RemoveDeckServerConnectionMessage TResult Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult Function(AddSeatServerConnectionMessage value)? addSeat, TResult Function(AddCardsServerConnectionMessage value)? addCards, + TResult Function(PutCardsServerConnectionMessage value)? putCards, TResult Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -1123,6 +1210,14 @@ class _$AddSeatServerConnectionMessage required TResult Function( List cards, int deckIndex, int? seatIndex) addCards, + required TResult Function( + int deckIndex, + int? seatIndex, + PickLocation location, + int count, + int movedDeckIndex, + int? movedSeatIndex) + putCards, required TResult Function(List cards) removeCards, required TResult Function(int index) removeSeat, required TResult Function(int index) joinSeat, @@ -1141,6 +1236,9 @@ class _$AddSeatServerConnectionMessage TResult? Function(String name)? addSeat, TResult? Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult? Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult? Function(List cards)? removeCards, TResult? Function(int index)? removeSeat, TResult? Function(int index)? joinSeat, @@ -1159,6 +1257,9 @@ class _$AddSeatServerConnectionMessage TResult Function(String name)? addSeat, TResult Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult Function(List cards)? removeCards, TResult Function(int index)? removeSeat, TResult Function(int index)? joinSeat, @@ -1183,6 +1284,7 @@ class _$AddSeatServerConnectionMessage removeDeck, required TResult Function(AddSeatServerConnectionMessage value) addSeat, required TResult Function(AddCardsServerConnectionMessage value) addCards, + required TResult Function(PutCardsServerConnectionMessage value) putCards, required TResult Function(RemoveCardsServerConnectionMessage value) removeCards, required TResult Function(RemoveSeatServerConnectionMessage value) @@ -1202,6 +1304,7 @@ class _$AddSeatServerConnectionMessage TResult? Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult? Function(AddSeatServerConnectionMessage value)? addSeat, TResult? Function(AddCardsServerConnectionMessage value)? addCards, + TResult? Function(PutCardsServerConnectionMessage value)? putCards, TResult? Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult? Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult? Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -1219,6 +1322,7 @@ class _$AddSeatServerConnectionMessage TResult Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult Function(AddSeatServerConnectionMessage value)? addSeat, TResult Function(AddCardsServerConnectionMessage value)? addCards, + TResult Function(PutCardsServerConnectionMessage value)? putCards, TResult Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -1367,6 +1471,14 @@ class _$AddCardsServerConnectionMessage required TResult Function( List cards, int deckIndex, int? seatIndex) addCards, + required TResult Function( + int deckIndex, + int? seatIndex, + PickLocation location, + int count, + int movedDeckIndex, + int? movedSeatIndex) + putCards, required TResult Function(List cards) removeCards, required TResult Function(int index) removeSeat, required TResult Function(int index) joinSeat, @@ -1385,6 +1497,9 @@ class _$AddCardsServerConnectionMessage TResult? Function(String name)? addSeat, TResult? Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult? Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult? Function(List cards)? removeCards, TResult? Function(int index)? removeSeat, TResult? Function(int index)? joinSeat, @@ -1403,6 +1518,9 @@ class _$AddCardsServerConnectionMessage TResult Function(String name)? addSeat, TResult Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult Function(List cards)? removeCards, TResult Function(int index)? removeSeat, TResult Function(int index)? joinSeat, @@ -1427,6 +1545,7 @@ class _$AddCardsServerConnectionMessage removeDeck, required TResult Function(AddSeatServerConnectionMessage value) addSeat, required TResult Function(AddCardsServerConnectionMessage value) addCards, + required TResult Function(PutCardsServerConnectionMessage value) putCards, required TResult Function(RemoveCardsServerConnectionMessage value) removeCards, required TResult Function(RemoveSeatServerConnectionMessage value) @@ -1446,6 +1565,7 @@ class _$AddCardsServerConnectionMessage TResult? Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult? Function(AddSeatServerConnectionMessage value)? addSeat, TResult? Function(AddCardsServerConnectionMessage value)? addCards, + TResult? Function(PutCardsServerConnectionMessage value)? putCards, TResult? Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult? Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult? Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -1463,6 +1583,7 @@ class _$AddCardsServerConnectionMessage TResult Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult Function(AddSeatServerConnectionMessage value)? addSeat, TResult Function(AddCardsServerConnectionMessage value)? addCards, + TResult Function(PutCardsServerConnectionMessage value)? putCards, TResult Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -1501,6 +1622,306 @@ abstract class AddCardsServerConnectionMessage get copyWith => throw _privateConstructorUsedError; } +/// @nodoc +abstract class _$$PutCardsServerConnectionMessageCopyWith<$Res> { + factory _$$PutCardsServerConnectionMessageCopyWith( + _$PutCardsServerConnectionMessage value, + $Res Function(_$PutCardsServerConnectionMessage) then) = + __$$PutCardsServerConnectionMessageCopyWithImpl<$Res>; + @useResult + $Res call( + {int deckIndex, + int? seatIndex, + PickLocation location, + int count, + int movedDeckIndex, + int? movedSeatIndex}); +} + +/// @nodoc +class __$$PutCardsServerConnectionMessageCopyWithImpl<$Res> + extends _$ServerConnectionMessageCopyWithImpl<$Res, + _$PutCardsServerConnectionMessage> + implements _$$PutCardsServerConnectionMessageCopyWith<$Res> { + __$$PutCardsServerConnectionMessageCopyWithImpl( + _$PutCardsServerConnectionMessage _value, + $Res Function(_$PutCardsServerConnectionMessage) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? deckIndex = null, + Object? seatIndex = freezed, + Object? location = null, + Object? count = null, + Object? movedDeckIndex = null, + Object? movedSeatIndex = freezed, + }) { + return _then(_$PutCardsServerConnectionMessage( + null == deckIndex + ? _value.deckIndex + : deckIndex // ignore: cast_nullable_to_non_nullable + as int, + freezed == seatIndex + ? _value.seatIndex + : seatIndex // ignore: cast_nullable_to_non_nullable + as int?, + null == location + ? _value.location + : location // ignore: cast_nullable_to_non_nullable + as PickLocation, + null == count + ? _value.count + : count // ignore: cast_nullable_to_non_nullable + as int, + null == movedDeckIndex + ? _value.movedDeckIndex + : movedDeckIndex // ignore: cast_nullable_to_non_nullable + as int, + freezed == movedSeatIndex + ? _value.movedSeatIndex + : movedSeatIndex // ignore: cast_nullable_to_non_nullable + as int?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$PutCardsServerConnectionMessage + implements PutCardsServerConnectionMessage { + const _$PutCardsServerConnectionMessage(this.deckIndex, this.seatIndex, + this.location, this.count, this.movedDeckIndex, this.movedSeatIndex, + {final String? $type}) + : $type = $type ?? 'putCards'; + + factory _$PutCardsServerConnectionMessage.fromJson( + Map json) => + _$$PutCardsServerConnectionMessageFromJson(json); + + @override + final int deckIndex; + @override + final int? seatIndex; + @override + final PickLocation location; + @override + final int count; + @override + final int movedDeckIndex; + @override + final int? movedSeatIndex; + + @JsonKey(name: 'type') + final String $type; + + @override + String toString() { + return 'ServerConnectionMessage.putCards(deckIndex: $deckIndex, seatIndex: $seatIndex, location: $location, count: $count, movedDeckIndex: $movedDeckIndex, movedSeatIndex: $movedSeatIndex)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$PutCardsServerConnectionMessage && + (identical(other.deckIndex, deckIndex) || + other.deckIndex == deckIndex) && + (identical(other.seatIndex, seatIndex) || + other.seatIndex == seatIndex) && + (identical(other.location, location) || + other.location == location) && + (identical(other.count, count) || other.count == count) && + (identical(other.movedDeckIndex, movedDeckIndex) || + other.movedDeckIndex == movedDeckIndex) && + (identical(other.movedSeatIndex, movedSeatIndex) || + other.movedSeatIndex == movedSeatIndex)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, deckIndex, seatIndex, location, + count, movedDeckIndex, movedSeatIndex); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$PutCardsServerConnectionMessageCopyWith<_$PutCardsServerConnectionMessage> + get copyWith => __$$PutCardsServerConnectionMessageCopyWithImpl< + _$PutCardsServerConnectionMessage>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() fetchPlayers, + required TResult Function(String message) chatMessage, + required TResult Function(GameDeck deck, int? seatIndex) addDeck, + required TResult Function(int index, int? seatIndex) removeDeck, + required TResult Function(String name) addSeat, + required TResult Function( + List cards, int deckIndex, int? seatIndex) + addCards, + required TResult Function( + int deckIndex, + int? seatIndex, + PickLocation location, + int count, + int movedDeckIndex, + int? movedSeatIndex) + putCards, + required TResult Function(List cards) removeCards, + required TResult Function(int index) removeSeat, + required TResult Function(int index) joinSeat, + required TResult Function(int index) leaveSeat, + }) { + return putCards( + deckIndex, seatIndex, location, count, movedDeckIndex, movedSeatIndex); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? fetchPlayers, + TResult? Function(String message)? chatMessage, + TResult? Function(GameDeck deck, int? seatIndex)? addDeck, + TResult? Function(int index, int? seatIndex)? removeDeck, + TResult? Function(String name)? addSeat, + TResult? Function(List cards, int deckIndex, int? seatIndex)? + addCards, + TResult? Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, + TResult? Function(List cards)? removeCards, + TResult? Function(int index)? removeSeat, + TResult? Function(int index)? joinSeat, + TResult? Function(int index)? leaveSeat, + }) { + return putCards?.call( + deckIndex, seatIndex, location, count, movedDeckIndex, movedSeatIndex); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? fetchPlayers, + TResult Function(String message)? chatMessage, + TResult Function(GameDeck deck, int? seatIndex)? addDeck, + TResult Function(int index, int? seatIndex)? removeDeck, + TResult Function(String name)? addSeat, + TResult Function(List cards, int deckIndex, int? seatIndex)? + addCards, + TResult Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, + TResult Function(List cards)? removeCards, + TResult Function(int index)? removeSeat, + TResult Function(int index)? joinSeat, + TResult Function(int index)? leaveSeat, + required TResult orElse(), + }) { + if (putCards != null) { + return putCards(deckIndex, seatIndex, location, count, movedDeckIndex, + movedSeatIndex); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(FetchPlayersServerConnectionMessage value) + fetchPlayers, + required TResult Function(ChatMessageServerConnectionMessage value) + chatMessage, + required TResult Function(AddDeckServerConnectionMessage value) addDeck, + required TResult Function(RemoveDeckServerConnectionMessage value) + removeDeck, + required TResult Function(AddSeatServerConnectionMessage value) addSeat, + required TResult Function(AddCardsServerConnectionMessage value) addCards, + required TResult Function(PutCardsServerConnectionMessage value) putCards, + required TResult Function(RemoveCardsServerConnectionMessage value) + removeCards, + required TResult Function(RemoveSeatServerConnectionMessage value) + removeSeat, + required TResult Function(JoinSeatServerConnectionMessage value) joinSeat, + required TResult Function(LeaveSeatServerConnectionMessage value) leaveSeat, + }) { + return putCards(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(FetchPlayersServerConnectionMessage value)? fetchPlayers, + TResult? Function(ChatMessageServerConnectionMessage value)? chatMessage, + TResult? Function(AddDeckServerConnectionMessage value)? addDeck, + TResult? Function(RemoveDeckServerConnectionMessage value)? removeDeck, + TResult? Function(AddSeatServerConnectionMessage value)? addSeat, + TResult? Function(AddCardsServerConnectionMessage value)? addCards, + TResult? Function(PutCardsServerConnectionMessage value)? putCards, + TResult? Function(RemoveCardsServerConnectionMessage value)? removeCards, + TResult? Function(RemoveSeatServerConnectionMessage value)? removeSeat, + TResult? Function(JoinSeatServerConnectionMessage value)? joinSeat, + TResult? Function(LeaveSeatServerConnectionMessage value)? leaveSeat, + }) { + return putCards?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(FetchPlayersServerConnectionMessage value)? fetchPlayers, + TResult Function(ChatMessageServerConnectionMessage value)? chatMessage, + TResult Function(AddDeckServerConnectionMessage value)? addDeck, + TResult Function(RemoveDeckServerConnectionMessage value)? removeDeck, + TResult Function(AddSeatServerConnectionMessage value)? addSeat, + TResult Function(AddCardsServerConnectionMessage value)? addCards, + TResult Function(PutCardsServerConnectionMessage value)? putCards, + TResult Function(RemoveCardsServerConnectionMessage value)? removeCards, + TResult Function(RemoveSeatServerConnectionMessage value)? removeSeat, + TResult Function(JoinSeatServerConnectionMessage value)? joinSeat, + TResult Function(LeaveSeatServerConnectionMessage value)? leaveSeat, + required TResult orElse(), + }) { + if (putCards != null) { + return putCards(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$PutCardsServerConnectionMessageToJson( + this, + ); + } +} + +abstract class PutCardsServerConnectionMessage + implements ServerConnectionMessage { + const factory PutCardsServerConnectionMessage( + final int deckIndex, + final int? seatIndex, + final PickLocation location, + final int count, + final int movedDeckIndex, + final int? movedSeatIndex) = _$PutCardsServerConnectionMessage; + + factory PutCardsServerConnectionMessage.fromJson(Map json) = + _$PutCardsServerConnectionMessage.fromJson; + + int get deckIndex; + int? get seatIndex; + PickLocation get location; + int get count; + int get movedDeckIndex; + int? get movedSeatIndex; + @JsonKey(ignore: true) + _$$PutCardsServerConnectionMessageCopyWith<_$PutCardsServerConnectionMessage> + get copyWith => throw _privateConstructorUsedError; +} + /// @nodoc abstract class _$$RemoveCardsServerConnectionMessageCopyWith<$Res> { factory _$$RemoveCardsServerConnectionMessageCopyWith( @@ -1596,6 +2017,14 @@ class _$RemoveCardsServerConnectionMessage required TResult Function( List cards, int deckIndex, int? seatIndex) addCards, + required TResult Function( + int deckIndex, + int? seatIndex, + PickLocation location, + int count, + int movedDeckIndex, + int? movedSeatIndex) + putCards, required TResult Function(List cards) removeCards, required TResult Function(int index) removeSeat, required TResult Function(int index) joinSeat, @@ -1614,6 +2043,9 @@ class _$RemoveCardsServerConnectionMessage TResult? Function(String name)? addSeat, TResult? Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult? Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult? Function(List cards)? removeCards, TResult? Function(int index)? removeSeat, TResult? Function(int index)? joinSeat, @@ -1632,6 +2064,9 @@ class _$RemoveCardsServerConnectionMessage TResult Function(String name)? addSeat, TResult Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult Function(List cards)? removeCards, TResult Function(int index)? removeSeat, TResult Function(int index)? joinSeat, @@ -1656,6 +2091,7 @@ class _$RemoveCardsServerConnectionMessage removeDeck, required TResult Function(AddSeatServerConnectionMessage value) addSeat, required TResult Function(AddCardsServerConnectionMessage value) addCards, + required TResult Function(PutCardsServerConnectionMessage value) putCards, required TResult Function(RemoveCardsServerConnectionMessage value) removeCards, required TResult Function(RemoveSeatServerConnectionMessage value) @@ -1675,6 +2111,7 @@ class _$RemoveCardsServerConnectionMessage TResult? Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult? Function(AddSeatServerConnectionMessage value)? addSeat, TResult? Function(AddCardsServerConnectionMessage value)? addCards, + TResult? Function(PutCardsServerConnectionMessage value)? putCards, TResult? Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult? Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult? Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -1692,6 +2129,7 @@ class _$RemoveCardsServerConnectionMessage TResult Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult Function(AddSeatServerConnectionMessage value)? addSeat, TResult Function(AddCardsServerConnectionMessage value)? addCards, + TResult Function(PutCardsServerConnectionMessage value)? putCards, TResult Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -1815,6 +2253,14 @@ class _$RemoveSeatServerConnectionMessage required TResult Function( List cards, int deckIndex, int? seatIndex) addCards, + required TResult Function( + int deckIndex, + int? seatIndex, + PickLocation location, + int count, + int movedDeckIndex, + int? movedSeatIndex) + putCards, required TResult Function(List cards) removeCards, required TResult Function(int index) removeSeat, required TResult Function(int index) joinSeat, @@ -1833,6 +2279,9 @@ class _$RemoveSeatServerConnectionMessage TResult? Function(String name)? addSeat, TResult? Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult? Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult? Function(List cards)? removeCards, TResult? Function(int index)? removeSeat, TResult? Function(int index)? joinSeat, @@ -1851,6 +2300,9 @@ class _$RemoveSeatServerConnectionMessage TResult Function(String name)? addSeat, TResult Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult Function(List cards)? removeCards, TResult Function(int index)? removeSeat, TResult Function(int index)? joinSeat, @@ -1875,6 +2327,7 @@ class _$RemoveSeatServerConnectionMessage removeDeck, required TResult Function(AddSeatServerConnectionMessage value) addSeat, required TResult Function(AddCardsServerConnectionMessage value) addCards, + required TResult Function(PutCardsServerConnectionMessage value) putCards, required TResult Function(RemoveCardsServerConnectionMessage value) removeCards, required TResult Function(RemoveSeatServerConnectionMessage value) @@ -1894,6 +2347,7 @@ class _$RemoveSeatServerConnectionMessage TResult? Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult? Function(AddSeatServerConnectionMessage value)? addSeat, TResult? Function(AddCardsServerConnectionMessage value)? addCards, + TResult? Function(PutCardsServerConnectionMessage value)? putCards, TResult? Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult? Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult? Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -1911,6 +2365,7 @@ class _$RemoveSeatServerConnectionMessage TResult Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult Function(AddSeatServerConnectionMessage value)? addSeat, TResult Function(AddCardsServerConnectionMessage value)? addCards, + TResult Function(PutCardsServerConnectionMessage value)? putCards, TResult Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -2032,6 +2487,14 @@ class _$JoinSeatServerConnectionMessage required TResult Function( List cards, int deckIndex, int? seatIndex) addCards, + required TResult Function( + int deckIndex, + int? seatIndex, + PickLocation location, + int count, + int movedDeckIndex, + int? movedSeatIndex) + putCards, required TResult Function(List cards) removeCards, required TResult Function(int index) removeSeat, required TResult Function(int index) joinSeat, @@ -2050,6 +2513,9 @@ class _$JoinSeatServerConnectionMessage TResult? Function(String name)? addSeat, TResult? Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult? Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult? Function(List cards)? removeCards, TResult? Function(int index)? removeSeat, TResult? Function(int index)? joinSeat, @@ -2068,6 +2534,9 @@ class _$JoinSeatServerConnectionMessage TResult Function(String name)? addSeat, TResult Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult Function(List cards)? removeCards, TResult Function(int index)? removeSeat, TResult Function(int index)? joinSeat, @@ -2092,6 +2561,7 @@ class _$JoinSeatServerConnectionMessage removeDeck, required TResult Function(AddSeatServerConnectionMessage value) addSeat, required TResult Function(AddCardsServerConnectionMessage value) addCards, + required TResult Function(PutCardsServerConnectionMessage value) putCards, required TResult Function(RemoveCardsServerConnectionMessage value) removeCards, required TResult Function(RemoveSeatServerConnectionMessage value) @@ -2111,6 +2581,7 @@ class _$JoinSeatServerConnectionMessage TResult? Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult? Function(AddSeatServerConnectionMessage value)? addSeat, TResult? Function(AddCardsServerConnectionMessage value)? addCards, + TResult? Function(PutCardsServerConnectionMessage value)? putCards, TResult? Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult? Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult? Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -2128,6 +2599,7 @@ class _$JoinSeatServerConnectionMessage TResult Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult Function(AddSeatServerConnectionMessage value)? addSeat, TResult Function(AddCardsServerConnectionMessage value)? addCards, + TResult Function(PutCardsServerConnectionMessage value)? putCards, TResult Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -2249,6 +2721,14 @@ class _$LeaveSeatServerConnectionMessage required TResult Function( List cards, int deckIndex, int? seatIndex) addCards, + required TResult Function( + int deckIndex, + int? seatIndex, + PickLocation location, + int count, + int movedDeckIndex, + int? movedSeatIndex) + putCards, required TResult Function(List cards) removeCards, required TResult Function(int index) removeSeat, required TResult Function(int index) joinSeat, @@ -2267,6 +2747,9 @@ class _$LeaveSeatServerConnectionMessage TResult? Function(String name)? addSeat, TResult? Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult? Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult? Function(List cards)? removeCards, TResult? Function(int index)? removeSeat, TResult? Function(int index)? joinSeat, @@ -2285,6 +2768,9 @@ class _$LeaveSeatServerConnectionMessage TResult Function(String name)? addSeat, TResult Function(List cards, int deckIndex, int? seatIndex)? addCards, + TResult Function(int deckIndex, int? seatIndex, PickLocation location, + int count, int movedDeckIndex, int? movedSeatIndex)? + putCards, TResult Function(List cards)? removeCards, TResult Function(int index)? removeSeat, TResult Function(int index)? joinSeat, @@ -2309,6 +2795,7 @@ class _$LeaveSeatServerConnectionMessage removeDeck, required TResult Function(AddSeatServerConnectionMessage value) addSeat, required TResult Function(AddCardsServerConnectionMessage value) addCards, + required TResult Function(PutCardsServerConnectionMessage value) putCards, required TResult Function(RemoveCardsServerConnectionMessage value) removeCards, required TResult Function(RemoveSeatServerConnectionMessage value) @@ -2328,6 +2815,7 @@ class _$LeaveSeatServerConnectionMessage TResult? Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult? Function(AddSeatServerConnectionMessage value)? addSeat, TResult? Function(AddCardsServerConnectionMessage value)? addCards, + TResult? Function(PutCardsServerConnectionMessage value)? putCards, TResult? Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult? Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult? Function(JoinSeatServerConnectionMessage value)? joinSeat, @@ -2345,6 +2833,7 @@ class _$LeaveSeatServerConnectionMessage TResult Function(RemoveDeckServerConnectionMessage value)? removeDeck, TResult Function(AddSeatServerConnectionMessage value)? addSeat, TResult Function(AddCardsServerConnectionMessage value)? addCards, + TResult Function(PutCardsServerConnectionMessage value)? putCards, TResult Function(RemoveCardsServerConnectionMessage value)? removeCards, TResult Function(RemoveSeatServerConnectionMessage value)? removeSeat, TResult Function(JoinSeatServerConnectionMessage value)? joinSeat, diff --git a/app/lib/logic/connection/server.g.dart b/app/lib/logic/connection/server.g.dart index e98a04c..a6e5549 100644 --- a/app/lib/logic/connection/server.g.dart +++ b/app/lib/logic/connection/server.g.dart @@ -98,6 +98,36 @@ Map _$$AddCardsServerConnectionMessageToJson( 'type': instance.$type, }; +_$PutCardsServerConnectionMessage _$$PutCardsServerConnectionMessageFromJson( + Map json) => + _$PutCardsServerConnectionMessage( + json['deckIndex'] as int, + json['seatIndex'] as int?, + $enumDecode(_$PickLocationEnumMap, json['location']), + json['count'] as int, + json['movedDeckIndex'] as int, + json['movedSeatIndex'] as int?, + $type: json['type'] as String?, + ); + +Map _$$PutCardsServerConnectionMessageToJson( + _$PutCardsServerConnectionMessage instance) => + { + 'deckIndex': instance.deckIndex, + 'seatIndex': instance.seatIndex, + 'location': _$PickLocationEnumMap[instance.location]!, + 'count': instance.count, + 'movedDeckIndex': instance.movedDeckIndex, + 'movedSeatIndex': instance.movedSeatIndex, + 'type': instance.$type, + }; + +const _$PickLocationEnumMap = { + PickLocation.top: 'top', + PickLocation.bottom: 'bottom', + PickLocation.random: 'random', +}; + _$RemoveCardsServerConnectionMessage _$$RemoveCardsServerConnectionMessageFromJson(Map json) => _$RemoveCardsServerConnectionMessage( diff --git a/app/lib/logic/state.dart b/app/lib/logic/state.dart index ba2f244..11dd7a6 100644 --- a/app/lib/logic/state.dart +++ b/app/lib/logic/state.dart @@ -1,5 +1,6 @@ import 'dart:math'; +import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'state.freezed.dart'; @@ -49,8 +50,10 @@ class GameState with _$GameState { copyWith(seats: seats.map((e) => e.copyWith(players: [])).toList()) .toJson(); - GameState onPlayer(int client) { - return copyWith(); + GameState onPlayer(int player) { + final sentDecks = decks.map((e) => e.hideOutside()).toList(); + final sentSeats = seats.map((e) => e.forPlayer(player)).toList(); + return copyWith(decks: sentDecks, seats: sentSeats); } } @@ -66,6 +69,18 @@ class GameSeat with _$GameSeat { factory GameSeat.fromJson(Map json) => _$GameSeatFromJson(json); + + GameSeat forPlayer(int player) { + if (players.contains(player)) { + return copyWith( + decks: decks.map((e) => e.hideOwn()).toList(), + ); + } else { + return copyWith( + decks: decks.map((e) => e.hideOutside()).toList(), + ); + } + } } enum DeckVisibility { @@ -92,7 +107,7 @@ class DeckRefill with _$DeckRefill { _$DeckRefillFromJson(json); } -enum CardLocation { top, bottom, random } +enum PickLocation { top, bottom, random } @freezed class CardsRemoveState with _$CardsRemoveState { @@ -115,7 +130,11 @@ class GameDeck with _$GameDeck { factory GameDeck.fromJson(Map json) => _$GameDeckFromJson(json); - GameDeck hide() { + GameDeck hideOutside() => hide(visibility); + + GameDeck hideOwn() => hide(getOwnVisibility()); + + GameDeck hide(DeckVisibility visibility) { switch (visibility) { case DeckVisibility.visible: return this; @@ -144,16 +163,16 @@ class GameDeck with _$GameDeck { } GameDeck putCards(List cards, - [CardLocation location = CardLocation.bottom]) { + [PickLocation location = PickLocation.bottom]) { final newCards = List.from(cards); switch (location) { - case CardLocation.top: + case PickLocation.top: newCards.insertAll(0, cards); break; - case CardLocation.bottom: + case PickLocation.bottom: newCards.addAll(cards); break; - case CardLocation.random: + case PickLocation.random: newCards.insertAll(Random().nextInt(newCards.length + 1), cards); break; } @@ -161,20 +180,20 @@ class GameDeck with _$GameDeck { } CardsRemoveState removeCards( - [int count = 1, CardLocation location = CardLocation.top]) { + [int count = 1, PickLocation location = PickLocation.top]) { final newCards = List.from(cards); final removedCards = []; switch (location) { - case CardLocation.top: + case PickLocation.top: removedCards.addAll(newCards.getRange(0, count)); newCards.removeRange(0, count); break; - case CardLocation.bottom: + case PickLocation.bottom: removedCards.addAll( newCards.getRange(newCards.length - count, newCards.length)); newCards.removeRange(newCards.length - count, newCards.length); break; - case CardLocation.random: + case PickLocation.random: final random = Random(); for (var i = 0; i < count; i++) { removedCards.add(newCards.removeAt(random.nextInt(newCards.length))); diff --git a/app/lib/pages/game/card.dart b/app/lib/pages/game/card.dart index 9e9d65f..12dc6ea 100644 --- a/app/lib/pages/game/card.dart +++ b/app/lib/pages/game/card.dart @@ -1,11 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; -import 'package:phosphor_flutter/phosphor_flutter.dart'; -import 'package:qeck/logic/connection/client.dart'; import 'package:qeck/logic/state.dart'; -import '../../logic/connection/logic.dart'; - class CardView extends StatelessWidget { final GameCard card; @@ -28,127 +23,3 @@ class CardView extends StatelessWidget { ); } } - -class CardsOperationDialog extends StatelessWidget { - final ClientGameConnection connection; - final List cards; - - const CardsOperationDialog( - {super.key, required this.cards, required this.connection}); - - @override - Widget build(BuildContext context) { - int? deckIndex, seatIndex; - return AlertDialog( - title: Text(AppLocalizations.of(context).cardsOperation), - content: SizedBox( - width: 500, - height: 500, - child: DefaultTabController( - length: 3, - child: Column( - children: [ - TabBar(tabs: [ - Tab( - text: AppLocalizations.of(context).moveToDeck, - ), - Tab( - text: AppLocalizations.of(context).moveToSeatDeck, - ), - Tab( - text: AppLocalizations.of(context).remove, - ), - ]), - Expanded( - child: TabBarView( - children: [ - ListView(children: [ - DropdownButtonFormField( - decoration: InputDecoration( - labelText: AppLocalizations.of(context).deck, - filled: true, - icon: - const PhosphorIcon(PhosphorIconsLight.textT), - ), - items: connection.state.decks - .asMap() - .entries - .map((e) => DropdownMenuItem( - value: e.key, child: Text(e.value.name))) - .toList(), - onChanged: (value) => deckIndex = value, - ), - ElevatedButton( - onPressed: () { - if (deckIndex == null) return; - connection.addCards(cards, deckIndex!); - Navigator.pop(context); - }, - child: Text( - AppLocalizations.of(context).move, - ), - ) - ]), - ListView(children: [ - DropdownButtonFormField( - decoration: InputDecoration( - labelText: AppLocalizations.of(context).deck, - filled: true, - icon: - const PhosphorIcon(PhosphorIconsLight.textT), - ), - items: connection.state.decks - .asMap() - .entries - .map((e) => DropdownMenuItem( - value: e.key, child: Text(e.value.name))) - .toList(), - onChanged: (value) => deckIndex = value, - ), - DropdownButtonFormField( - decoration: InputDecoration( - labelText: AppLocalizations.of(context).seat, - filled: true, - icon: const PhosphorIcon(PhosphorIconsLight.user), - ), - items: connection.state.seats - .asMap() - .entries - .map((e) => DropdownMenuItem( - value: e.key, child: Text(e.value.name))) - .toList(), - onChanged: (value) => seatIndex = value, - ), - ElevatedButton( - onPressed: () { - if (deckIndex == null || seatIndex == null) { - return; - } - connection.addCards( - cards, deckIndex!, seatIndex!); - Navigator.pop(context); - }, - child: Text( - AppLocalizations.of(context).move, - ), - ) - ]), - ListView(children: [ - ElevatedButton( - onPressed: () { - connection.removeCards(cards); - Navigator.pop(context); - }, - child: Text( - AppLocalizations.of(context).remove, - ), - ) - ]), - ], - ), - ) - ], - ))), - ); - } -} diff --git a/app/lib/pages/game/cards.dart b/app/lib/pages/game/cards.dart new file mode 100644 index 0000000..ea3ce7f --- /dev/null +++ b/app/lib/pages/game/cards.dart @@ -0,0 +1,332 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:phosphor_flutter/phosphor_flutter.dart'; + +import '../../logic/connection/client.dart'; +import '../../logic/connection/logic.dart'; +import '../../logic/state.dart'; + +class CardsOperationDialog extends StatelessWidget { + final ClientGameConnection connection; + final List cards; + + const CardsOperationDialog( + {super.key, required this.cards, required this.connection}); + + @override + Widget build(BuildContext context) { + int? deckIndex, seatIndex; + return StatefulBuilder( + builder: (context, setState) => AlertDialog( + title: Text(AppLocalizations.of(context).cardsOperation), + content: SizedBox( + width: 500, + height: 500, + child: DefaultTabController( + length: 3, + child: Column( + children: [ + TabBar(tabs: [ + Tab( + text: AppLocalizations.of(context).moveToDeck, + ), + Tab( + text: AppLocalizations.of(context).moveToSeatDeck, + ), + Tab( + text: AppLocalizations.of(context).remove, + ), + ]), + Expanded( + child: TabBarView( + children: [ + ListView(children: [ + DropdownButtonFormField( + decoration: InputDecoration( + labelText: + AppLocalizations.of(context).deck, + filled: true, + icon: const PhosphorIcon( + PhosphorIconsLight.textT), + ), + items: connection.state.decks + .asMap() + .entries + .map((e) => DropdownMenuItem( + value: e.key, + child: Text(e.value.name))) + .toList(), + onChanged: (value) => setState(() { + deckIndex = value; + seatIndex = null; + }), + ), + ElevatedButton( + onPressed: () { + if (deckIndex == null) return; + connection.addCards(cards, deckIndex!); + Navigator.pop(context); + }, + child: Text( + AppLocalizations.of(context).move, + ), + ) + ]), + ListView(children: [ + DropdownButtonFormField( + decoration: InputDecoration( + labelText: + AppLocalizations.of(context).seat, + filled: true, + icon: const PhosphorIcon( + PhosphorIconsLight.user), + ), + items: connection.state.seats + .asMap() + .entries + .map((e) => DropdownMenuItem( + value: e.key, + child: Text(e.value.name))) + .toList(), + onChanged: (value) => setState(() { + seatIndex = value; + deckIndex = null; + }), + ), + DropdownButtonFormField( + decoration: InputDecoration( + labelText: + AppLocalizations.of(context).deck, + filled: true, + icon: const PhosphorIcon( + PhosphorIconsLight.textT), + ), + items: seatIndex == null + ? [] + : connection + .state.seats[seatIndex!].decks + .asMap() + .entries + .map((e) => DropdownMenuItem( + value: e.key, + child: Text(e.value.name))) + .toList(), + onChanged: (value) { + deckIndex = value; + }, + ), + ElevatedButton( + onPressed: () { + if (deckIndex == null || + seatIndex == null) { + return; + } + connection.addCards( + cards, deckIndex!, seatIndex!); + Navigator.pop(context); + }, + child: Text( + AppLocalizations.of(context).move, + ), + ) + ]), + ListView(children: [ + ElevatedButton( + onPressed: () { + connection.removeCards(cards); + Navigator.pop(context); + }, + child: Text( + AppLocalizations.of(context).remove, + ), + ) + ]), + ], + ), + ) + ], + ))), + )); + } +} + +class PutCardsDialog extends StatelessWidget { + final ClientGameConnection connection; + final int deckIndex; + final int? seatIndex; + + const PutCardsDialog( + {super.key, + required this.connection, + required this.deckIndex, + this.seatIndex}); + + @override + Widget build(BuildContext context) { + int? movedDeckIndex, movedSeatIndex; + var count = 1; + var location = PickLocation.top; + return StatefulBuilder( + builder: (context, setState) => AlertDialog( + title: Text(AppLocalizations.of(context).putCards), + content: SizedBox( + width: 500, + height: 500, + child: Column( + children: [ + DropdownButtonFormField( + decoration: InputDecoration( + labelText: AppLocalizations.of(context).location, + filled: true, + icon: const PhosphorIcon(PhosphorIconsLight.textT), + ), + items: PickLocation.values + .map((e) => + DropdownMenuItem(value: e, child: Text(e.name))) + .toList(), + onChanged: (value) => location = value ?? location, + ), + TextFormField( + decoration: InputDecoration( + labelText: AppLocalizations.of(context).count, + filled: true, + icon: const PhosphorIcon(PhosphorIconsLight.textT), + ), + initialValue: count.toString(), + onChanged: (value) => + count = int.tryParse(value) ?? count, + ), + Expanded( + child: DefaultTabController( + length: 2, + child: Column( + children: [ + TabBar(tabs: [ + Tab( + text: + AppLocalizations.of(context).moveToDeck, + ), + Tab( + text: AppLocalizations.of(context) + .moveToSeatDeck, + ), + ]), + Expanded( + child: TabBarView( + children: [ + ListView(children: [ + DropdownButtonFormField( + decoration: InputDecoration( + labelText: + AppLocalizations.of(context) + .deck, + filled: true, + icon: const PhosphorIcon( + PhosphorIconsLight.textT), + ), + items: connection.state.decks + .asMap() + .entries + .map((e) => DropdownMenuItem( + value: e.key, + child: Text(e.value.name))) + .toList(), + onChanged: (value) => setState(() { + movedDeckIndex = value; + movedSeatIndex = null; + }), + ), + ElevatedButton( + onPressed: () { + if (movedDeckIndex == null) return; + connection.putCards( + deckIndex, + seatIndex, + location, + count, + movedDeckIndex!, + null); + Navigator.pop(context); + }, + child: Text( + AppLocalizations.of(context).move, + ), + ) + ]), + ListView(children: [ + DropdownButtonFormField( + decoration: InputDecoration( + labelText: + AppLocalizations.of(context) + .seat, + filled: true, + icon: const PhosphorIcon( + PhosphorIconsLight.user), + ), + items: connection.state.seats + .asMap() + .entries + .map((e) => DropdownMenuItem( + value: e.key, + child: Text(e.value.name))) + .toList(), + onChanged: (value) => setState(() { + movedSeatIndex = value; + movedDeckIndex = null; + }), + ), + DropdownButtonFormField( + decoration: InputDecoration( + labelText: + AppLocalizations.of(context) + .deck, + filled: true, + icon: const PhosphorIcon( + PhosphorIconsLight.textT), + ), + items: movedSeatIndex == null + ? [] + : connection.state + .seats[movedSeatIndex!].decks + .asMap() + .entries + .map((e) => DropdownMenuItem( + value: e.key, + child: + Text(e.value.name))) + .toList(), + onChanged: (value) { + movedDeckIndex = value; + }, + ), + ElevatedButton( + onPressed: () { + if (movedDeckIndex == null || + movedSeatIndex == null) { + return; + } + connection.putCards( + deckIndex, + seatIndex, + location, + count, + movedDeckIndex!, + movedSeatIndex!); + Navigator.pop(context); + }, + child: Text( + AppLocalizations.of(context).move, + ), + ) + ]), + ], + ), + ) + ], + )), + ), + ], + )), + )); + } +} diff --git a/app/lib/pages/game/deck.dart b/app/lib/pages/game/deck.dart index 6b8f766..755903d 100644 --- a/app/lib/pages/game/deck.dart +++ b/app/lib/pages/game/deck.dart @@ -7,6 +7,8 @@ import 'package:qeck/logic/connection/logic.dart'; import 'package:qeck/logic/state.dart'; import 'package:qeck/pages/game/card.dart'; +import 'cards.dart'; + class DeckLocation { final GameDeck deck; final int? index; @@ -50,11 +52,14 @@ class GameDeckView extends StatelessWidget { children: [ if (firstCard != null) Expanded( - child: Draggable( - data: DeckLocation(deck, index, seatIndex), - feedback: Material( - child: Text(deck.name), - ), + child: InkWell( + onTap: () => showDialog( + context: context, + builder: (context) => CardDeckDialog( + deck: deck, + index: index, + connection: connection, + seatIndex: seatIndex)), child: CardView( card: firstCard, ), @@ -93,7 +98,28 @@ class GameDeckView extends StatelessWidget { ), ); }, - ) + ), + if (index != null) ...[ + MenuItemButton( + child: Text(AppLocalizations.of(context).putCards), + onPressed: () { + showDialog( + context: context, + builder: (context) => PutCardsDialog( + deckIndex: index!, + seatIndex: seatIndex, + connection: connection, + ), + ); + }, + ), + MenuItemButton( + child: Text(AppLocalizations.of(context).remove), + onPressed: () { + connection.removeDeck(index!, seatIndex); + }, + ), + ], ], ), ]), @@ -105,9 +131,84 @@ class GameDeckView extends StatelessWidget { } } +class CardDeckDialog extends StatelessWidget { + final GameDeck deck; + final int? index; + final int? seatIndex; + final ClientGameConnection connection; + + const CardDeckDialog({ + super.key, + required this.deck, + required this.index, + required this.connection, + required this.seatIndex, + }); + + @override + Widget build(BuildContext context) { + return Stack( + children: [ + Align( + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 500, maxHeight: 500), + child: Material( + child: SingleChildScrollView( + child: StreamBuilder( + stream: connection.stateStream, + builder: (context, snapshot) { + if (!snapshot.hasData) { + return const SizedBox(); + } + final state = snapshot.data; + var realDeck = deck; + if (seatIndex != null) { + realDeck = state!.seats[seatIndex!].decks[index!]; + } else if (index != null) { + realDeck = state!.decks[index!]; + } + return Wrap( + children: realDeck.cards + .asMap() + .entries + .map((e) => InkWell( + onTap: () { + CardIndex cardIndex; + if (index == null) { + cardIndex = AvailableCardIndex(e.value); + } else if (seatIndex == null) { + cardIndex = DeckCardIndex(e.key, index!); + } else { + cardIndex = SeatCardIndex( + e.key, index!, seatIndex!); + } + showDialog( + context: context, + builder: (context) => + CardsOperationDialog( + cards: [cardIndex], + connection: connection)); + }, + child: CardView( + card: e.value, + ), + )) + .toList(), + ); + }), + ), + ), + ), + ), + ], + ); + } +} + class AddDeckView extends StatelessWidget { final ClientGameConnection connection; - const AddDeckView({super.key, required this.connection}); + final int? seatIndex; + const AddDeckView({super.key, required this.connection, this.seatIndex}); @override Widget build(BuildContext context) { @@ -120,6 +221,7 @@ class AddDeckView extends StatelessWidget { context: context, builder: (context) => AddDeckDialog( connection: connection, + seatIndex: seatIndex, ), ), child: const Padding( diff --git a/app/lib/pages/game/view.dart b/app/lib/pages/game/view.dart index 29eb6f6..30e38fa 100644 --- a/app/lib/pages/game/view.dart +++ b/app/lib/pages/game/view.dart @@ -80,9 +80,29 @@ class GameView extends StatelessWidget { ), ], ), - ...connection.getMySeats().expand((e) => [ + ...connection.getMySeats().asMap().entries.expand((se) => [ const SizedBox(height: 16), - Text(e.name), + Text(se.value.name), + SizedBox( + height: 150, + child: ListView( + shrinkWrap: true, + scrollDirection: Axis.horizontal, + children: [ + ...se.value.decks + .asMap() + .entries + .map((e) => GameDeckView( + connection: connection, + deck: e.value, + index: e.key, + seatIndex: se.key, + )), + AddDeckView( + connection: connection, seatIndex: se.key), + ], + ), + ), ]) ], );