Skip to content

Commit

Permalink
Add seat and deck creation
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed May 9, 2023
1 parent e96dd50 commit eb62723
Show file tree
Hide file tree
Showing 13 changed files with 570 additions and 224 deletions.
9 changes: 8 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,12 @@
"seat": "Seat",
"shuffle": "Shuffle",
"decks": "Decks",
"cards": "Cards"
"cards": "Cards",
"classic": "Classic",
"available": "Available",
"seats": "Seats",
"addDeck": "Add deck",
"addSeat": "Add seat",
"visibility": "Visibility",
"ownVisibility": "Own visibility"
}
24 changes: 24 additions & 0 deletions app/lib/logic/connection/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,28 @@ class ClientGameConnection with GameConnection, ConnectedGameConnection {
Future<void> close() async {
await channel.sink.close();
}

List<GameSeat> getMySeats() => state.seats
.where((element) => element.players.any((e) => e == playerId))
.toList();

void addSeat(String name) {
send(ServerConnectionMessage.addSeat(name));
}

void leaveSeat(int key) {
send(ServerConnectionMessage.leaveSeat(key));
}

void joinSeat(int key) {
send(ServerConnectionMessage.joinSeat(key));
}

void removeSeat(int key) {
send(ServerConnectionMessage.removeSeat(key));
}

void addDeck(GameDeck deck, int? seatIndex) {
send(ServerConnectionMessage.addDeck(deck, seatIndex));
}
}
15 changes: 6 additions & 9 deletions app/lib/logic/connection/client.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final _privateConstructorUsedError = UnsupportedError(

ClientConnectionMessage _$ClientConnectionMessageFromJson(
Map<String, dynamic> json) {
switch (json['runtimeType']) {
switch (json['type']) {
case 'playersUpdated':
return FetchedPlayersClientConnectionMessage.fromJson(json);
case 'chatMessage':
Expand All @@ -25,11 +25,8 @@ ClientConnectionMessage _$ClientConnectionMessageFromJson(
return GameStateChangedClientConnectionMessage.fromJson(json);

default:
throw CheckedFromJsonException(
json,
'runtimeType',
'ClientConnectionMessage',
'Invalid union type "${json['runtimeType']}"!');
throw CheckedFromJsonException(json, 'type', 'ClientConnectionMessage',
'Invalid union type "${json['type']}"!');
}
}

Expand Down Expand Up @@ -173,7 +170,7 @@ class _$FetchedPlayersClientConnectionMessage
@override
final int playerId;

@JsonKey(name: 'runtimeType')
@JsonKey(name: 'type')
final String $type;

@override
Expand Down Expand Up @@ -362,7 +359,7 @@ class _$ChatMessageClientConnectionMessage
@override
final String from;

@JsonKey(name: 'runtimeType')
@JsonKey(name: 'type')
final String $type;

@override
Expand Down Expand Up @@ -552,7 +549,7 @@ class _$GameStateChangedClientConnectionMessage
@override
final GameState state;

@JsonKey(name: 'runtimeType')
@JsonKey(name: 'type')
final String $type;

@override
Expand Down
29 changes: 14 additions & 15 deletions app/lib/logic/connection/client.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions app/lib/logic/connection/logic.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 21 additions & 4 deletions app/lib/logic/connection/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class ServerConnectionMessage with _$ServerConnectionMessage {
const factory ServerConnectionMessage.chatMessage(String message) =
ChatMessageServerConnectionMessage;

const factory ServerConnectionMessage.addDeck(GameDeck deck) =
const factory ServerConnectionMessage.addDeck(GameDeck deck, int? seatIndex) =
AddDeckServerConnectionMessage;

const factory ServerConnectionMessage.removeDeck(int index) =
const factory ServerConnectionMessage.removeDeck(int index, int? seatIndex) =
RemoveDeckServerConnectionMessage;

const factory ServerConnectionMessage.addSeat(String name,
Expand Down Expand Up @@ -151,10 +151,27 @@ class ServerGameConnection with GameConnection {
client.info.remoteAddress.address,
),
),
addDeck: (deck) {
addDeck: (deck, seatIndex) {
if (seatIndex != null) {
_changeState(state.copyWith(
seats: List<GameSeat>.from(state.seats)
..[seatIndex] = state.seats[seatIndex].copyWith(
decks: [...state.seats[seatIndex].decks, deck],
)));
return;
}
_changeState(state.copyWith(decks: [...state.decks, deck]));
},
removeDeck: (index) {
removeDeck: (index, 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)
..removeAt(index),
)));
return;
}
_changeState(state.copyWith(
decks: List<GameDeck>.from(state.decks)..removeAt(index)));
},
Expand Down
Loading

0 comments on commit eb62723

Please sign in to comment.