Added mercure to update when everyone is ready
This commit is contained in:
@@ -329,8 +329,12 @@ final class GameDashboardService
|
||||
$this->checkAllPlayersReady($session);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$topic = $this->mercureTopicBase . '/game/hub-' . $session->getId();
|
||||
$this->hub->publish(new Update($topic, json_encode(['type' => 'player_ready', 'player' => $player->getScreen(), 'ready' => !$setting])));
|
||||
try {
|
||||
$topic = $this->mercureTopicBase . '/game/hub-' . $session->getId();
|
||||
$this->hub->publish(new Update($topic, json_encode(['type' => 'player_ready', 'player' => $player->getScreen(), 'ready' => !$setting])));
|
||||
} catch (\Exception $e) {
|
||||
// Mercure might be down, but we don't want to crash the game
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -350,6 +354,7 @@ final class GameDashboardService
|
||||
|
||||
$readyPlayersCount = 0;
|
||||
$now = new \DateTime();
|
||||
$anyReset = false;
|
||||
|
||||
/** @var \App\Game\Repository\SessionSettingRepository $settingRepo */
|
||||
$settingRepo = $this->entityManager->getRepository(SessionSetting::class);
|
||||
@@ -367,12 +372,23 @@ final class GameDashboardService
|
||||
if (($now->getTimestamp() - $readyAtTimestamp) > 60) {
|
||||
$session->removeSetting($setting);
|
||||
$this->entityManager->remove($setting);
|
||||
$anyReset = true;
|
||||
} else {
|
||||
$readyPlayersCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($anyReset) {
|
||||
$this->entityManager->flush();
|
||||
try {
|
||||
$topic = $this->mercureTopicBase . '/game/hub-' . $session->getId();
|
||||
$this->hub->publish(new Update($topic, json_encode(['type' => 'player_ready'])));
|
||||
} catch (\Exception $e) {
|
||||
// Mercure might be down
|
||||
}
|
||||
}
|
||||
|
||||
if ($readyPlayersCount === $numPlayers) {
|
||||
$session->setStatus(SessionStatus::PLAYING);
|
||||
$this->entityManager->persist($session);
|
||||
@@ -389,8 +405,12 @@ final class GameDashboardService
|
||||
}
|
||||
}
|
||||
|
||||
$topic = $this->mercureTopicBase . '/game/hub-' . $session->getId();
|
||||
$this->hub->publish(new Update($topic, json_encode(['type' => 'all_ready'])));
|
||||
try {
|
||||
$topic = $this->mercureTopicBase . '/game/hub-' . $session->getId();
|
||||
$this->hub->publish(new Update($topic, json_encode(['type' => 'all_ready'])));
|
||||
} catch (\Exception $e) {
|
||||
// Mercure might be down, but we don't want to crash the game
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user