added completer and recursive function to start a new round at the end of a round

This commit is contained in:
ggurdin 2024-08-12 15:42:33 -04:00
parent ac6ddc6d0e
commit 2b574f42c1
No known key found for this signature in database
GPG key ID: A01CB41737CBB478
2 changed files with 15 additions and 2 deletions

View file

@ -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;

View file

@ -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() {}