-
-
Notifications
You must be signed in to change notification settings - Fork 455
Expand file tree
/
Copy pathbroadcast.dart
More file actions
131 lines (108 loc) · 3.29 KB
/
Copy pathbroadcast.dart
File metadata and controls
131 lines (108 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import 'package:dartchess/dartchess.dart';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:lichess_mobile/src/model/common/id.dart';
part 'broadcast.freezed.dart';
typedef BroadcastsList = ({
IList<Broadcast> active,
IList<Broadcast> upcoming,
IList<Broadcast> past,
int? nextPage,
});
@freezed
class Broadcast with _$Broadcast {
const Broadcast._();
const factory Broadcast({
required BroadcastTournamentData tour,
required BroadcastRound round,
required String? group,
/// The round to which the user should be brought when cliking on the tournament
required BroadcastRoundId roundToLinkId,
}) = _Broadcast;
bool get isLive => round.status == RoundStatus.live;
bool get isFinished => round.status == RoundStatus.finished;
String get title => group ?? tour.name;
}
@freezed
class BroadcastTournament with _$BroadcastTournament {
const factory BroadcastTournament({
required BroadcastTournamentData data,
required IList<BroadcastRound> rounds,
required BroadcastRoundId defaultRoundId,
required IList<BroadcastTournamentGroup>? group,
}) = _BroadcastTournament;
}
@freezed
class BroadcastTournamentData with _$BroadcastTournamentData {
const factory BroadcastTournamentData({
required BroadcastTournamentId id,
required String name,
required String? imageUrl,
required String? description,
required BroadcastTournamentInformation information,
}) = _BroadcastTournamentData;
}
typedef BroadcastTournamentInformation = ({
String? format,
String? timeControl,
String? players,
BroadcastTournamentDates? dates,
});
typedef BroadcastTournamentDates = ({
DateTime startsAt,
DateTime? endsAt,
});
typedef BroadcastTournamentGroup = ({
BroadcastTournamentId id,
String name,
});
@freezed
class BroadcastRound with _$BroadcastRound {
const BroadcastRound._();
const factory BroadcastRound({
required BroadcastRoundId id,
required String name,
required RoundStatus status,
required DateTime? startsAt,
}) = _BroadcastRound;
}
typedef BroadcastRoundGames = IMap<BroadcastGameId, BroadcastGame>;
@freezed
class BroadcastGame with _$BroadcastGame {
const BroadcastGame._();
const factory BroadcastGame({
required BroadcastGameId id,
required IMap<Side, BroadcastPlayer> players,
required String fen,
required Move? lastMove,
required String? status,
/// The amount of time that the player whose turn it is has been thinking since his last move
required Duration thinkTime,
}) = _BroadcastGame;
bool get isPlaying => status == '*';
Side get playingSide => Setup.parseFen(fen).turn;
Duration? get timeLeft {
final clock = players[playingSide]!.clock;
if (clock == null) return null;
final timeLeftMaybeNegative = clock - thinkTime;
return timeLeftMaybeNegative.isNegative
? Duration.zero
: timeLeftMaybeNegative;
}
}
@freezed
class BroadcastPlayer with _$BroadcastPlayer {
const BroadcastPlayer._();
const factory BroadcastPlayer({
required String name,
required String? title,
required int? rating,
required Duration? clock,
required String? federation,
}) = _BroadcastPlayer;
}
enum RoundStatus {
live,
finished,
upcoming,
}