Skip to content

Commit

Permalink
Finish functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed May 9, 2023
1 parent 1c03334 commit dc3437c
Show file tree
Hide file tree
Showing 10 changed files with 1,093 additions and 153 deletions.
5 changes: 4 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
"remove": "Remove",
"move": "Move",
"deck": "Deck",
"moveCards": "Move cards"
"moveCards": "Move cards",
"location": "Location",
"count": "Count",
"putCards": "Put cards"
}
16 changes: 16 additions & 0 deletions app/lib/logic/connection/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,20 @@ class ClientGameConnection with GameConnection, ConnectedGameConnection {
void removeCards(List<CardIndex> 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));
}
}
62 changes: 60 additions & 2 deletions app/lib/logic/connection/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ class ServerConnectionMessage with _$ServerConnectionMessage {
List<CardIndex> 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<CardIndex> cards) =
RemoveCardsServerConnectionMessage;

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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<GameSeat>.from(state.seats)
..[seatIndex] = state.seats[seatIndex].copyWith(
decks: List<GameDeck>.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<GameDeck>.from(state.decks)
..[deckIndex] = removeState.deck);
cards.addAll(removeState.removedCards);
}
if (movedSeatIndex != null) {
newState = newState.copyWith(
seats: List<GameSeat>.from(newState.seats)
..[movedSeatIndex] = newState.seats[movedSeatIndex].copyWith(
decks: List<GameDeck>.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<GameDeck>.from(newState.decks)
..[movedDeckIndex] = newState.decks[movedDeckIndex].copyWith(
cards: [...newState.decks[movedDeckIndex].cards, ...cards],
));
}
_changeState(newState);
},
);
}
}
Expand Down
Loading

0 comments on commit dc3437c

Please sign in to comment.