unreal-html5-touch-controller
Version:
Touch controller for Unreal Engine HTML5 exports with joystick and gesture support.
2 lines (1 loc) • 7.63 kB
JavaScript
const t=n;function n(t,s){const o=e();return(n=function(t,n){return o[t-=376]})(t,s)}function e(){const t=["8888090hGRLop","touches","41258SUTmpH","clientY","384ZSDLrn","dispatchEvent","touchstart","1413wqNPzp","pressed","length","touchend","_bind","clear","_updateKeys","26752PPBfSD","addEventListener","22cOBnTz","touchmove","clientX","keyup","51394BAMwtz","285789kjxgha","1736260WJQUxc","has","origin","4546300ByZkWv","33sIuHNS","getElementById","_fire","preventDefault","add","Key"];return(e=function(){return t})()}!function(){const t=n,s=e();for(;;)try{if(654527===parseInt(t(392))/1+-parseInt(t(391))/2*(-parseInt(t(397))/3)+-parseInt(t(396))/4+parseInt(t(393))/5+-parseInt(t(407))/6*(parseInt(t(405))/7)+-parseInt(t(385))/8*(parseInt(t(378))/9)+-parseInt(t(403))/10*(-parseInt(t(387))/11))break;s.push(s.shift())}catch(t){s.push(s.shift())}}();class s{constructor(t){const e=n;this.el=document[e(398)](t),this.el?(this[e(395)]=null,this[e(379)]=new Set,this[e(382)]()):console.warn("[JoystickControl] Element not found for id: "+t)}[t(382)](){const n=t;this.el[n(386)](n(377),(t=>{const e=n;1===t[e(404)].length&&(this[e(395)]={x:t[e(404)][0].clientX,y:t[e(404)][0].clientY}),t[e(400)]()}),{passive:!1}),this.el[n(386)](n(388),(t=>{const e=n;if(!this[e(395)]||1!==t.touches[e(380)])return;const s=t[e(404)][0][e(389)]-this.origin.x,o=t.touches[0][e(406)]-this.origin.y;this[e(384)](s,o),t[e(400)]()}),{passive:!1}),this.el.addEventListener(n(381),(t=>{const e=n;this[e(395)]=null,this[e(384)](0,0),t.preventDefault()}),{passive:!1})}[t(399)](n,e){const s=t,o=new KeyboardEvent(n,{key:e.toLowerCase(),code:s(402)+e.toUpperCase(),bubbles:!0});document[s(376)](o)}[t(384)](n,e){const s=t,o=new Set;e<-15&&o[s(401)]("w"),e>15&&o[s(401)]("s"),n<-15&&o[s(401)]("a"),n>15&&o.add("d");for(const t of this[s(379)])!o[s(394)](t)&&(this[s(399)](s(390),t),this[s(379)].delete(t));for(const t of o)!this.pressed.has(t)&&(this[s(399)]("keydown",t),this[s(379)].add(t));if(0===o.size){for(const t of this[s(379)])this[s(399)](s(390),t);this.pressed[s(383)]()}}}function o(t,n){const e=r();return(o=function(t,n){return e[t-=107]})(t,n)}const i=o;function r(){const t=["touchstart","none","focus","innerWidth","_onTouchMove","clientY","hidden","clientX","7640ddigRw","1973994HeGGgP","changedTouches","body","_styleCanvas","canvas","addEventListener","_fireMouseEvent","height","mousemove","bind","touchRegion","723110eMIAmf","mouseup","_onTouchEnd","touchAction","fixed","985879CNPZdb","getElementById","identifier","preventDefault","2034339wyIESW","1694970fKQCvx","lastTouch","function","609HHmvKJ","100%","_onTouchStart","width","viewTouchId","97760gyLkPI",'[UnrealHTML5TouchController] Canvas not found with id "',"tabindex","_bindEvents","setAttribute","style"];return(r=function(){return t})()}!function(){const t=o,n=r();for(;;)try{if(523692===parseInt(t(138))/1+-parseInt(t(122))/2+-parseInt(t(142))/3+parseInt(t(121))/4+-parseInt(t(133))/5+parseInt(t(143))/6+parseInt(t(146))/7*(parseInt(t(107))/8))break;n.push(n.shift())}catch(t){n.push(n.shift())}}();class c{constructor(t,n){const e=o;this[e(126)]=document[e(139)](t),this[e(126)]?(this[e(150)]=null,this.lastTouch=null,this[e(132)]=typeof n===e(145)?n:t=>t>window.innerWidth*n,this._styleCanvas(),this[e(110)]()):console.warn(e(108)+t+'"')}[i(125)](){const t=i;this[t(126)].style[t(136)]=t(114);const n=document[t(124)];n[t(112)].overflow=t(119),n[t(112)].position=t(137),n[t(112)][t(149)]="100%",n[t(112)][t(129)]=t(147),n[t(112)].touchAction=t(114),this[t(126)][t(111)](t(109),"0"),this[t(126)][t(115)]()}[i(110)](){const t=i;this[t(126)][t(127)](t(113),this[t(148)][t(131)](this),{passive:!1}),this.canvas[t(127)]("touchmove",this[t(117)][t(131)](this),{passive:!1}),this[t(126)][t(127)]("touchend",this[t(135)].bind(this),{passive:!1})}[i(148)](t){const n=i;for(const e of t.changedTouches)e[n(120)]>window[n(116)]/2&&(this[n(150)]=e.identifier,this[n(144)]={x:e[n(120)],y:e[n(118)]},this._fireMouseEvent("mousedown",e));t[n(141)]()}[i(117)](t){const n=i;if(null!==this[n(150)]){for(const e of t[n(123)])if(e[n(140)]===this[n(150)]){const t=e[n(120)]-this[n(144)].x,s=e[n(118)]-this[n(144)].y;this[n(144)]={x:e[n(120)],y:e[n(118)]},this[n(128)](n(130),e,t,s)}t.preventDefault()}}_onTouchEnd(t){const n=i;for(const e of t[n(123)])e[n(140)]===this[n(150)]&&(this._fireMouseEvent(n(134),e),this[n(150)]=null,this[n(144)]=null);t.preventDefault()}[i(128)](t,n,e=0,s=0){const o=i,r=new MouseEvent(t,{bubbles:!0,cancelable:!0,clientX:n[o(120)],clientY:n[o(118)],movementX:e,movementY:s,buttons:t===o(134)?0:1});this[o(126)].dispatchEvent(r)}}const h=u;function a(){const t=["mousedown","3970rTSzlY","972VQrxkX","preventDefault","Space","touchstart","string","keydown","mouseup","132GIrxRs","startsWith","bindings","_keyFromCode","touchend","1017MEHPhW","106512ukmpDM","activeKeys","Shift","has","addEventListener","248JTuZPE","191219JzNDKu","2739240fFBkSA","add","2488DpqUcN","4MFPECN","slice","_fireKey","delete","1762387fPHTJa","dispatchEvent","querySelector","ShiftLeft","3722465uLJEbX","toLowerCase","Key"];return(a=function(){return t})()}function u(t,n){const e=a();return(u=function(t,n){return e[t-=109]})(t,n)}!function(){const t=u,n=a();for(;;)try{if(683964===parseInt(t(126))/1*(parseInt(t(136))/2)+-parseInt(t(113))/3*(parseInt(t(135))/4)+-parseInt(t(144))/5+parseInt(t(133))/6+-parseInt(t(132))/7*(parseInt(t(131))/8)+parseInt(t(125))/9*(parseInt(t(112))/10)+-parseInt(t(140))/11*(-parseInt(t(120))/12))break;n.push(n.shift())}catch(t){n.push(n.shift())}}();class d{constructor(){const t=u;this[t(127)]=new Set,this[t(122)]=[]}bindButton(t,n){const e=u,s=typeof t===e(117)?document[e(142)](t):t;if(!s)return;const o=t=>{const s=e;!this.activeKeys[s(129)](n)&&(this[s(138)](s(118),n),this[s(127)][s(134)](n)),t[s(114)]()},i=t=>{const s=e;this[s(127)][s(129)](n)&&(this[s(138)]("keyup",n),this[s(127)][s(139)](n)),t[s(114)]()};s[e(130)](e(116),o,{passive:!1}),s.addEventListener(e(111),o),s[e(130)](e(124),i,{passive:!1}),s[e(130)](e(119),i),this[e(122)].push({el:s,keyCode:n})}[h(138)](t,n){const e=h,s=new KeyboardEvent(t,{key:this._keyFromCode(n),code:n,bubbles:!0}),o=document.getElementById("canvas");o&&(o.dispatchEvent(s),o.focus()),window[e(141)](s),document.dispatchEvent(s)}[h(123)](t){const n=h;return t[n(121)](n(110))?t[n(137)](3).toLowerCase():t===n(115)?" ":t===n(143)?n(128):t[n(109)]()}}const p=l;function f(){const t=["joystick-left","4500885VkxnVS","1105410BqBElS","104696vtAiaM","dom","[UnrealHTML5TouchController] Skipped invalid customKey entry:","469RxXSNV","[UnrealHTML5TouchController] Invalid `customKeys`:","2259NyLxAe","4TMPbqA","keyController","7970Hunqth","key","joystickControl","1221224wAigum","1008309saiqNo","bindButton","warn","isArray","2899854XOTivY"];return(f=function(){return t})()}function l(t,n){const e=f();return(l=function(t,n){return e[t-=329]})(t,n)}!function(){const t=l,n=f();for(;;)try{if(529761===-parseInt(t(346))/1+parseInt(t(345))/2+parseInt(t(330))/3+parseInt(t(340))/4*(-parseInt(t(332))/5)+parseInt(t(333))/6+parseInt(t(337))/7*(parseInt(t(334))/8)+parseInt(t(339))/9*(-parseInt(t(342))/10))break;n.push(n.shift())}catch(t){n.push(n.shift())}}();class v{constructor({canvasId:t="canvas",joystickId:n=p(331),viewTouchRegion:e=.5,customKeys:o}){const i=p;if(this.keyController=new d,this.viewControl=new c(t,e),this[i(344)]=new s(n),!o)return;const r=Array[i(329)](o)?o:"object"==typeof o&&o[i(335)]&&o[i(343)]?[o]:(()=>{const t=i;return console[t(348)](t(338),o),[]})();for(const{dom:t,key:n}of r)t&&n?this[i(341)][i(347)](t,n):console[i(348)](i(336),{dom:t,key:n})}}export{v as UnrealHTML5TouchController};