From 2b574f42c1f0a6a691ee8a7b448c30a281d3c76f Mon Sep 17 00:00:00 2001 From: ggurdin Date: Mon, 12 Aug 2024 15:42:33 -0400 Subject: [PATCH] added completer and recursive function to start a new round at the end of a round --- lib/pages/chat/chat.dart | 13 ++++++++++++- lib/pangea/pages/games/story_game/round_model.dart | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index d6f75f360..acfb585e4 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -296,6 +296,17 @@ class ChatController extends State } } + // #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 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; diff --git a/lib/pangea/pages/games/story_game/round_model.dart b/lib/pangea/pages/games/story_game/round_model.dart index 6177fe1fe..4f351198b 100644 --- a/lib/pangea/pages/games/story_game/round_model.dart +++ b/lib/pangea/pages/games/story_game/round_model.dart @@ -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 roundCompleter = Completer(); Timer? timer; DateTime? startTime; DateTime? endTime; @@ -41,6 +42,7 @@ class GameRoundModel { endTime = DateTime.now(); state = RoundState.completed; timer?.cancel(); + roundCompleter.complete(); } void dispose() {}