diff --git a/public/static/css/maps.css b/public/static/css/maps.css index acfb23d..7c3eed5 100644 --- a/public/static/css/maps.css +++ b/public/static/css/maps.css @@ -93,6 +93,7 @@ div.mapItem>div.buttonContainer { #restrictions input[type=range] { height: 1.5em; margin-left: 2em; + width: 70%; } #timeLimitType { diff --git a/public/static/js/maps.js b/public/static/js/maps.js index 8631cc5..41c16ae 100644 --- a/public/static/js/maps.js +++ b/public/static/js/maps.js @@ -65,6 +65,22 @@ } }; + var Util = { + printTimeForHuman: function (time) { + if (time < 60) { + return '' + time + ' seconds'; + } else if (time == 60) { + return '1 minute'; + } else if (time % 60 == 0) { + return '' + Math.floor(time / 60) + ' minutes'; + } else if (time % 60 == 1) { + return '' + Math.floor(time / 60) + ' minutes and 1 second'; + } else { + return '' + Math.floor(time / 60) + ' minutes and ' + time % 60 + ' seconds'; + } + } + }; + Maps.addStaticMaps(); Maps.initializeDescriptionDivs(); @@ -119,7 +135,7 @@ document.getElementById('playMode').style.visibility = 'hidden'; var timeLimit = document.getElementById('timeLimit').value; - document.getElementById('timeLimitLabel').innerText = 'Time limit of ' + timeLimit + ' seconds per round'; + document.getElementById('timeLimitLabel').innerText = 'Time limit of ' + Util.printTimeForHuman(timeLimit); }; } @@ -149,7 +165,7 @@ document.getElementById('timeLimit').oninput = function () { var timeLimit = document.getElementById('timeLimit').value; - document.getElementById('timeLimitLabel').innerText = 'Time limit of ' + timeLimit + ' seconds per round'; + document.getElementById('timeLimitLabel').innerText = 'Time limit of ' + Util.printTimeForHuman(timeLimit); document.getElementById('timerEnabled').checked = true; } })(); diff --git a/src/Controller/GameFlowController.php b/src/Controller/GameFlowController.php index b0e4473..88eef5c 100644 --- a/src/Controller/GameFlowController.php +++ b/src/Controller/GameFlowController.php @@ -239,6 +239,11 @@ class GameFlowController $response = $this->prepareChallengeResponse($userId, $challenge, $currentRound, true); + if ($challenge->getTimeLimitType() === 'game' && $userInChallenge->getCurrentRound() > 0) { + $timeLimit = max(10, $userInChallenge->getTimeLeft()); + $response['restrictions']['timeLimit'] = $timeLimit * 1000; + } + return new JsonContent($response); } diff --git a/src/PersistentData/Model/UserInChallenge.php b/src/PersistentData/Model/UserInChallenge.php index 680e04c..1b636e9 100644 --- a/src/PersistentData/Model/UserInChallenge.php +++ b/src/PersistentData/Model/UserInChallenge.php @@ -50,7 +50,7 @@ class UserInChallenge extends Model public function setTimeLeft(?int $timeLeft): void { if(isset($timeLeft)) { - $this->timeLeft = $timeLeft; + $this->timeLeft = max(0, $timeLeft); } } diff --git a/views/maps.php b/views/maps.php index c097e4c..1e3f712 100644 --- a/views/maps.php +++ b/views/maps.php @@ -51,7 +51,7 @@ TODO: condition!
- +
Time limit