MAPG-235 timeLimit restored after reload of the page. Time limit selector usability improved

This commit is contained in:
Balázs Vigh 2021-05-21 11:30:30 +02:00
parent b78d564f6f
commit aadeda05af
5 changed files with 26 additions and 4 deletions

View File

@ -93,6 +93,7 @@ div.mapItem>div.buttonContainer {
#restrictions input[type=range] { #restrictions input[type=range] {
height: 1.5em; height: 1.5em;
margin-left: 2em; margin-left: 2em;
width: 70%;
} }
#timeLimitType { #timeLimitType {

View File

@ -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.addStaticMaps();
Maps.initializeDescriptionDivs(); Maps.initializeDescriptionDivs();
@ -119,7 +135,7 @@
document.getElementById('playMode').style.visibility = 'hidden'; document.getElementById('playMode').style.visibility = 'hidden';
var timeLimit = document.getElementById('timeLimit').value; 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 () { document.getElementById('timeLimit').oninput = function () {
var timeLimit = document.getElementById('timeLimit').value; 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; document.getElementById('timerEnabled').checked = true;
} }
})(); })();

View File

@ -239,6 +239,11 @@ class GameFlowController
$response = $this->prepareChallengeResponse($userId, $challenge, $currentRound, true); $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); return new JsonContent($response);
} }

View File

@ -50,7 +50,7 @@ class UserInChallenge extends Model
public function setTimeLeft(?int $timeLeft): void public function setTimeLeft(?int $timeLeft): void
{ {
if(isset($timeLeft)) { if(isset($timeLeft)) {
$this->timeLeft = $timeLeft; $this->timeLeft = max(0, $timeLeft);
} }
} }

View File

@ -51,7 +51,7 @@ TODO: condition!
<label id="timeLimitLabel" for="timerEnabled">Time limit measured in seconds</label> <label id="timeLimitLabel" for="timerEnabled">Time limit measured in seconds</label>
</div> </div>
<div> <div>
<input type="range" id="timeLimit" name="timeLimit" min="10" max="600" value="120" /> <input type="range" id="timeLimit" name="timeLimit" min="10" max="1800" step="10" value="300" />
</div> </div>
<div id="timeLimitType"> <div id="timeLimitType">
Time limit Time limit