|
| 1 | +var GameEditUrl = "/live/gameedit"; |
| 2 | +var GameEditUpdateInterval = 3000; |
| 3 | + |
| 4 | +function GameEdit() { |
| 5 | + var base = this; |
| 6 | + this.timer = null; |
| 7 | + |
| 8 | + this.onInit = function() { |
| 9 | + base.timer = setInterval(base.updateStatus, GameEditUpdateInterval); |
| 10 | + this.updateStatus(); |
| 11 | + |
| 12 | + // Array of buttons and their corresponding time values |
| 13 | + const timeButtons = [ |
| 14 | + { id: "#gameedit_btn_add_time_15", time: 15 }, |
| 15 | + { id: "#gameedit_btn_add_time_30", time: 30 }, |
| 16 | + { id: "#gameedit_btn_add_time_45", time: 45 }, |
| 17 | + { id: "#gameedit_btn_add_time_60", time: 60 }, |
| 18 | + { id: "#gameedit_btn_del_time_15", time: -15 }, |
| 19 | + { id: "#gameedit_btn_del_time_30", time: -30 }, |
| 20 | + { id: "#gameedit_btn_del_time_45", time: -45 }, |
| 21 | + { id: "#gameedit_btn_del_time_60", time: -60 } |
| 22 | + ]; |
| 23 | + |
| 24 | + timeButtons.forEach(button => { |
| 25 | + $(button.id).click(function(e) { |
| 26 | + e.preventDefault(); |
| 27 | + base.addTime(button.time); |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + // Array of flags and their corresponding values |
| 32 | + const flagButtons = [ |
| 33 | + { id: "#gameedit_btn_add_flag_1", team: 1 , score: 1}, |
| 34 | + { id: "#gameedit_btn_add_flag_2", team: 2 , score: 1}, |
| 35 | + { id: "#gameedit_btn_sub_flag_1", team: 1 , score: -1}, |
| 36 | + { id: "#gameedit_btn_sub_flag_2", team: 2 , score: -1} |
| 37 | + ]; |
| 38 | + |
| 39 | + flagButtons.forEach(button => { |
| 40 | + $(button.id).click(function(e) { |
| 41 | + e.preventDefault(); |
| 42 | + base.addFlag(button.team, button.score); |
| 43 | + }); |
| 44 | + }); |
| 45 | + }; |
| 46 | + |
| 47 | + this.onDeinit = function() { |
| 48 | + if(base.timer != null) clearInterval(base.timer); |
| 49 | + }; |
| 50 | + |
| 51 | + this.updateStatus = function(s) { |
| 52 | + $.post({ |
| 53 | + url: DashboardUrl, |
| 54 | + data: '{"action":"status_get"}', |
| 55 | + contentType: "application/json", |
| 56 | + dataType:"json", |
| 57 | + }).done(function(res) { |
| 58 | + $("#team1_score").text(`Score: ${res.Team1Score}`); |
| 59 | + $("#team2_score").text(`Score: ${res.Team2Score}`); |
| 60 | + }); |
| 61 | + }; |
| 62 | + |
| 63 | + this.addTime = function(time) { |
| 64 | + $.post({ |
| 65 | + url: GameEditUrl, |
| 66 | + data: JSON.stringify({ action: "add_time", TimeToAdd: time}), |
| 67 | + }) |
| 68 | + .done(function(res) { |
| 69 | + base.updateStatus(); |
| 70 | + }) |
| 71 | + .fail(function() { |
| 72 | + alert("Failed to add time!"); |
| 73 | + }); |
| 74 | + }; |
| 75 | + |
| 76 | + this.addFlag = function(team, score) { |
| 77 | + $.post({ |
| 78 | + url: GameEditUrl, |
| 79 | + data: JSON.stringify({action: "add_flag", team: team, score: score}), |
| 80 | + }) |
| 81 | + .done(function(res){ |
| 82 | + base.updateStatus(); |
| 83 | + }) |
| 84 | + .fail(function() { |
| 85 | + alert("Failed to add flag!"); |
| 86 | + }) |
| 87 | + }; |
| 88 | + |
| 89 | + this.addPlayerPoints = function(slot, score){ |
| 90 | + $.post({ |
| 91 | + url: GameEditUrl, |
| 92 | + data: JSON.stringify({action:"add_player_points", slot: slot, score: score}), |
| 93 | + }) |
| 94 | + .done(function(res){ |
| 95 | + }) |
| 96 | + .fail(function() { |
| 97 | + alert("Failed to add flag!"); |
| 98 | + }) |
| 99 | + }; |
| 100 | +} |
| 101 | + |
| 102 | +// Register the GameEdit page |
| 103 | +mainFrame.setActivePage(new GameEdit()); |
0 commit comments