diff options
| author | RblSb <msrblsb@gmail.com> | 2021-01-17 22:50:39 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2021-01-17 22:50:39 +0300 |
| commit | 3444b413ab12783c85ce73df9931142fea11b749 (patch) | |
| tree | 97e128323033cedb0cf6e6c713385960b339c830 /res | |
| parent | 266c0cbe76d345afe49759ba8be9ba7aadc4760d (diff) | |
requestLeaderOnPause option
closes #13
Diffstat (limited to 'res')
| -rw-r--r-- | res/client.js | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/res/client.js b/res/client.js index ed6c43a..1a0f9d3 100644 --- a/res/client.js +++ b/res/client.js @@ -1,4 +1,4 @@ -// Generated by Haxe 4.1.4 +// Generated by Haxe 4.1.5 (function ($hx_exports, $global) { "use strict"; $hx_exports["client"] = $hx_exports["client"] || {}; $hx_exports["client"]["JsApi"] = $hx_exports["client"]["JsApi"] || {}; @@ -50,6 +50,13 @@ ClientTools.setLeader = function(clients,name) { } } }; +ClientTools.hasLeader = function(clients) { + var _g = 0; + while(_g < clients.length) if((clients[_g++].group & 2) != 0) { + return true; + } + return false; +}; ClientTools.getByName = function(clients,name,def) { var _g = 0; while(_g < clients.length) { @@ -681,7 +688,7 @@ client_Buttons.initHotkeys = function(main,player) { window.document.querySelector("#fullscreenbtn").onclick(); break; case 76: - window.document.querySelector("#leader_btn").onclick(); + main.toggleLeader(); break; case 80: if((main.personal.group & 2) == 0) { @@ -691,7 +698,7 @@ client_Buttons.initHotkeys = function(main,player) { } }); } - window.document.querySelector("#leader_btn").onclick(); + main.toggleLeader(); break; case 82: window.document.querySelector("#mediarefresh").onclick(); @@ -996,10 +1003,7 @@ client_Main.prototype = { ,initListeners: function() { var _gthis = this; client_Buttons.init(this); - window.document.querySelector("#leader_btn").onclick = function(e) { - _gthis.setLeaderButton((_gthis.personal.group & 2) == 0); - _gthis.send({ type : "SetLeader", setLeader : { clientName : (_gthis.personal.group & 2) != 0 ? "" : _gthis.personal.name}}); - }; + window.document.querySelector("#leader_btn").onclick = $bind(this,this.toggleLeader); window.document.querySelector("#voteskip").onclick = function(e) { if(client_Utils.isTouch() && !window.confirm(Lang.get("skipItemConfirm"))) { return; @@ -1182,7 +1186,7 @@ client_Main.prototype = { var data = JSON.parse(e.data); if(this.config != null && this.config.isVerbose) { var t = data.type; - haxe_Log.trace("Event: " + data.type,{ fileName : "src/client/Main.hx", lineNumber : 342, className : "client.Main", methodName : "onMessage", customParams : [Reflect.field(data,t.charAt(0).toLowerCase() + HxOverrides.substr(t,1,null))]}); + haxe_Log.trace("Event: " + data.type,{ fileName : "src/client/Main.hx", lineNumber : 334, className : "client.Main", methodName : "onMessage", customParams : [Reflect.field(data,t.charAt(0).toLowerCase() + HxOverrides.substr(t,1,null))]}); } client_JsApi.fireOnceEvent(data); switch(data.type) { @@ -1704,6 +1708,19 @@ client_Main.prototype = { this.settings.synchThreshold = s; client_Settings.write(this.settings); } + ,hasPermission: function(group,permission) { + return Reflect.field(this.config.permissions,$hxEnums[group.__enum__].__constructs__[group._hx_index].toLowerCase()).indexOf(permission) != -1; + } + ,toggleLeader: function() { + this.setLeaderButton((this.personal.group & 2) == 0); + this.send({ type : "SetLeader", setLeader : { clientName : (this.personal.group & 2) != 0 ? "" : this.personal.name}}); + } + ,hasLeader: function() { + return ClientTools.hasLeader(this.clients); + } + ,hasLeaderOnPauseRequest: function() { + return this.config.requestLeaderOnPause; + } ,getTemplateUrl: function() { return this.config.templateUrl; } @@ -1853,8 +1870,25 @@ client_Player.prototype = { return; } this.main.send({ type : "Play", play : { time : this.getTime()}}); + if(this.main.hasLeaderOnPauseRequest()) { + if(this.main.hasPermission((this.main.personal.group & 4) != 0 ? ClientGroup.Admin : ClientGroup.User,"requestLeader")) { + this.main.toggleLeader(); + } + } } ,onPause: function() { + var _gthis = this; + if(this.main.hasLeaderOnPauseRequest() && !this.main.hasLeader()) { + client_JsApi.once("SetLeader",function(event) { + if(event.setLeader.clientName != _gthis.main.personal.name) { + return; + } + _gthis.main.send({ type : "Pause", pause : { time : _gthis.getTime()}}); + _gthis.player.pause(); + }); + this.main.toggleLeader(); + return; + } if((this.main.personal.group & 2) == 0) { return; } |
