added completer and recursive function to start a new round at the end of a round
This commit is contained in:
parent
ac6ddc6d0e
commit
2b574f42c1
2 changed files with 15 additions and 2 deletions
|
|
@ -296,6 +296,17 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
}
|
||||
}
|
||||
|
||||
// #Pangea
|
||||
void addRound() {
|
||||
debugPrint("ADDING A ROUND. Rounds so far: ${gameRounds.length}");
|
||||
final newRound = GameRoundModel(controller: this);
|
||||
gameRounds.add(newRound);
|
||||
newRound.roundCompleter.future.then((_) {
|
||||
if (mounted) addRound();
|
||||
});
|
||||
}
|
||||
// Pangea#
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
scrollController.addListener(_updateScrollController);
|
||||
|
|
@ -311,7 +322,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
sendingClient = Matrix.of(context).client;
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
// #Pangea
|
||||
gameRounds.add(GameRoundModel(controller: this));
|
||||
addRound();
|
||||
if (!mounted) return;
|
||||
Future.delayed(const Duration(seconds: 1), () async {
|
||||
if (!mounted) return;
|
||||
|
|
|
|||
|
|
@ -8,9 +8,10 @@ import 'package:matrix/matrix.dart';
|
|||
enum RoundState { notStarted, inProgress, completed }
|
||||
|
||||
class GameRoundModel {
|
||||
static const Duration roundLength = Duration(minutes: 3);
|
||||
static const Duration roundLength = Duration(seconds: 10);
|
||||
|
||||
final ChatController controller;
|
||||
final Completer<void> roundCompleter = Completer<void>();
|
||||
Timer? timer;
|
||||
DateTime? startTime;
|
||||
DateTime? endTime;
|
||||
|
|
@ -41,6 +42,7 @@ class GameRoundModel {
|
|||
endTime = DateTime.now();
|
||||
state = RoundState.completed;
|
||||
timer?.cancel();
|
||||
roundCompleter.complete();
|
||||
}
|
||||
|
||||
void dispose() {}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue