diff --git a/game_manager_frame.php b/game_manager_frame.php index 24568e7..b6f1f2c 100644 --- a/game_manager_frame.php +++ b/game_manager_frame.php @@ -16,6 +16,7 @@ if (!get_autologin_state() || (($user_data["privilege"] !== PRIVILEGE_CREATOR) & SpreadQuiz + @@ -55,6 +56,15 @@ if (!get_autologin_state() || (($user_data["privilege"] !== PRIVILEGE_CREATOR) &
Csoportok:
+ + + + +
+ + + + diff --git a/gamemgr.php b/gamemgr.php index 0364314..b383802 100644 --- a/gamemgr.php +++ b/gamemgr.php @@ -7,7 +7,7 @@ $gamedb = new \SleekDB\Store(GAMEDB, DATADIR, ["timeout" => false]); const DEFAULT_GAME_PROPERTIES = [ "forward_only" => false, // player may traverse back and forth between challenges - "time_limit" => -1, // no time limit; otherwise, this field indicates time limit in seconds + "time_limit" => 0, // no time limit; otherwise, this field indicates time limit in seconds "repeatable" => false // this test can be taken multiple times ]; diff --git a/interface.php b/interface.php index ef7632e..0a14ad4 100644 --- a/interface.php +++ b/interface.php @@ -161,6 +161,7 @@ switch ($action) { $contributors = explode_list($data["contributors"] ?: ""); $owner = $update ? trim($data["owner"] ?: $nickname) : $nickname; $groups = explode_list($data["groups"] ?: ""); + $properties = $data["properties"] ?: []; $groupids = get_groupids_by_compounds($groups); // convert group compounds to _ids @@ -200,6 +201,8 @@ switch ($action) { $game_data["owner"] = $owner; } $game_data["contributors"] = array_intersect($contributors, get_all_nicknames()); + $game_data["properties"]["time_limit"] = $properties["time_limit"]; + $game_data["properties"]["repeatable"] = $properties["repeatable"]; update_game($game_data); // update game file if supplied diff --git a/js/common.js b/js/common.js index 1a7445c..768b367 100644 --- a/js/common.js +++ b/js/common.js @@ -2,4 +2,32 @@ function unix_time_to_human_readable(tunix) { const date = new Date(Number(tunix) * 1000); return date.getFullYear() + ". " + String(date.getMonth() + 1).padStart(2, "0") + ". " + String(date.getDate()).padStart(2, "0") + ". " + String(date.getHours()).padStart(2, "0") + ":" + String(date.getMinutes()).padStart(2, "0") + ":" + String(date.getSeconds()).padStart(2, "0"); +} + +function seconds_to_time(s) { + let hours = Math.floor(s / 3600); + s -= hours * 3600; + let minutes = Math.floor(s / 60); + s -= minutes * 60; + let seconds = s; + return String(hours).padStart(2, "0") + ":" + + String(minutes).padStart(2, "0") + ":" + + String(seconds).padStart(2, "0"); +} + +function time_to_seconds(t) { + let s = 0; + let parts = t.split(":").reverse(); + if (parts.length >= 1) { + s += Number(parts[0]); + + if (parts.length >= 2) { + s += Number(parts[1]) * 60; + + if (parts.length >= 3) { + s += Number(parts[2]) * 3600; + } + } + } + return s; } \ No newline at end of file diff --git a/js/gamemgr.js b/js/gamemgr.js index aa0d03a..ba09e1d 100644 --- a/js/gamemgr.js +++ b/js/gamemgr.js @@ -47,6 +47,9 @@ function create_edit_game(game = null) { let show_game_file_upload_btn = document.getElementById("show_game_file_upload"); let cancel_game_file_upload_btn = document.getElementById("cancel_game_file_upload"); let groupF = document.getElementById("game_groups"); + let time_limitedChk = document.getElementById("time_limited"); + let time_limitF = document.getElementById("time_limit"); + let repeatableChk = document.getElementById("repeatable"); if (!updating) { // creating a new game nameF.value = ""; @@ -56,6 +59,8 @@ function create_edit_game(game = null) { ownerF.readOnly = true; contributorsF.value = ""; groupF.value = ""; + time_limitedChk.checked = false; + repeatableChk.checked = true; // hide additional controls hide("additional_controls"); @@ -68,8 +73,17 @@ function create_edit_game(game = null) { contributorsF.value = game["contributors"].join(", "); groupF.value = game["groups"].join(", "); + let props = game["properties"]; + let time_limit = Math.max(Number(props["time_limit"]), 0); + time_limitF.value = seconds_to_time(time_limit); + time_limitedChk.checked = time_limit > 0; + handle_time_limit_chkbox(); + + repeatableChk.checked = props["repeatable"]; + // show additional controls show("additional_controls"); + } gameFileF.value = ""; @@ -87,7 +101,11 @@ function create_edit_game(game = null) { description: descriptionF.value.trim(), owner: updating ? ownerF.value.trim() : USERDATA["nickname"], contributors: contributorsF.value.trim(), - groups: groupF.value.trim() + groups: groupF.value.trim(), + properties: { + time_limit: updating ? (time_limitedChk.checked ? time_to_seconds(time_limitF.value): 0) : 0, + repeatable: updating ? repeatableChk.checked : false + } }; if (updating) { reqData["_id"] = game["_id"]; @@ -163,6 +181,12 @@ function delete_games() { } } +function handle_time_limit_chkbox() { + let time_limitedChk = document.getElementById("time_limited"); + let time_limitF = document.getElementById("time_limit"); + time_limitF.disabled = !time_limitedChk.checked; +} + // function hint_all_groups(target_element_id) { // const hintbox_insert_fn = (record) => { // let targetF = document.getElementById(target_element_id); @@ -178,4 +202,4 @@ function delete_games() { // } // // open_hintbox_at(target_element_id, req, print_group_name, hintbox_insert_fn); -// } \ No newline at end of file +// } diff --git a/js/testground.js b/js/testground.js index c44eb1a..10182e3 100644 --- a/js/testground.js +++ b/js/testground.js @@ -1,18 +1,6 @@ let TEST_DATA = {} let INTERVAL_HANDLE = null; -function print_time_left(t) { - let timerS = document.getElementById("timer"); - let hours = Math.floor(t / 3600); - t -= hours * 3600; - let minutes = Math.floor(t / 60); - t -= minutes * 60; - let seconds = t; - timerS.innerHTML = String(hours).padStart(2, "0") + ":" - + String(minutes).padStart(2, "0") + ":" - + String(seconds).padStart(2, "0"); -} - function populate_infobox(test_data) { if (INTERVAL_HANDLE !== null) { clearInterval(INTERVAL_HANDLE); @@ -41,11 +29,12 @@ function populate_infobox(test_data) { show("concluded-info"); } else { if (test_data["time_limited"]) { + let timerS = document.getElementById("timer"); let time_left_s = Number(test_data["end_limit_time"]) - Number(test_data["current_time"]); - print_time_left(time_left_s); + seconds_to_time(time_left_s); INTERVAL_HANDLE = setInterval(() => { time_left_s--; - print_time_left(time_left_s); + timerS.innerHTML = seconds_to_time(time_left_s); if (time_left_s <= 0) { populate_all(test_data["_id"]); clearInterval(INTERVAL_HANDLE);