mirror of
https://github.com/eugene-serb/wavelovers.git
synced 2023-09-09 23:41:16 +03:00
2 lines
6.3 KiB
JavaScript
2 lines
6.3 KiB
JavaScript
(function(){"use strict";var t={1194:function(t,e,n){var a=n(9242),i=n(3396);function s(t,e,n,a,s,r){const o=(0,i.up)("WaveloversApp");return(0,i.wg)(),(0,i.j4)(o)}const r={class:"wavelovers"},o=(0,i.Uk)("Loading..."),c=(0,i.Uk)("Press any gamepad's button or connect new gamepad.");function d(t,e,n,a,s,d){const p=(0,i.up)("PatternList"),u=(0,i.up)("MessageItem"),h=(0,i.up)("GamepadList");return(0,i.wg)(),(0,i.iD)("div",r,[t.patterns.length>0?((0,i.wg)(),(0,i.j4)(p,{key:0,patterns:t.patterns,mode:t.mode,isActive:t.isActive,onChange:t.change},null,8,["patterns","mode","isActive","onChange"])):((0,i.wg)(),(0,i.j4)(u,{key:1},{default:(0,i.w5)((()=>[o])),_:1})),t.gamepads.length>0?((0,i.wg)(),(0,i.j4)(h,{key:2,gamepads:t.gamepads},null,8,["gamepads"])):((0,i.wg)(),(0,i.j4)(u,{key:3},{default:(0,i.w5)((()=>[c])),_:1}))])}const p={class:"pattern-list"};function u(t,e,n,a,s,r){const o=(0,i.up)("PatternItem");return(0,i.wg)(),(0,i.iD)("div",p,[((0,i.wg)(!0),(0,i.iD)(i.HY,null,(0,i.Ko)(t.patterns,((e,n)=>((0,i.wg)(),(0,i.j4)(o,{key:e.name,pattern:e,index:n,mode:t.mode,isActive:t.isActive,onChange:t.change},null,8,["pattern","index","mode","isActive","onChange"])))),128))])}var h=n(7139);const l=["textContent"],m=["textContent"];function v(t,e,n,a,s,r){return(0,i.wg)(),(0,i.iD)("div",{onClick:e[0]||(e[0]=e=>t.change(t.index)),class:(0,h.C_)(["pattern-item",t.index===t.mode&&!0===t.isActive?"pattern-item_selected":""])},[(0,i._)("span",{class:"pattern-item__icon",textContent:(0,h.zw)(t.pattern.icon)},null,8,l),(0,i._)("span",{class:"pattern-item__name",textContent:(0,h.zw)(t.pattern.name)},null,8,m)],2)}var g=(0,i.aZ)({name:"PatternItem",props:{pattern:{type:Object},index:{type:Number},mode:{type:Number},isActive:{type:Boolean}},methods:{change(t){this.$emit("change",t)}}}),f=n(89);const w=(0,f.Z)(g,[["render",v]]);var b=w,y=(0,i.aZ)({name:"PatternList",props:{patterns:{type:Array},mode:{type:Number},isActive:{type:Boolean}},components:{PatternItem:b},methods:{change(t){this.$emit("change",t)}}});const A=(0,f.Z)(y,[["render",u]]);var Z=A;const j={class:"device-list"};function x(t,e,n,a,s,r){const o=(0,i.up)("GamepadItem");return(0,i.wg)(),(0,i.iD)("div",j,[((0,i.wg)(!0),(0,i.iD)(i.HY,null,(0,i.Ko)(t.gamepads,(t=>((0,i.wg)(),(0,i.j4)(o,{key:t.id,textContent:(0,h.zw)(t.unit.id)},null,8,["textContent"])))),128))])}const k={class:"list-item"};function C(t,e,n,a,s,r){return(0,i.wg)(),(0,i.iD)("div",k)}var _=(0,i.aZ)({name:"GamepadItem"});const O=(0,f.Z)(_,[["render",C]]);var P=O,G=(0,i.aZ)({name:"GamepadList",props:{gamepads:{type:Array}},components:{GamepadItem:P}});const I=(0,f.Z)(G,[["render",x]]);var L=I;const D={class:"message"};function E(t,e,n,a,s,r){return(0,i.wg)(),(0,i.iD)("div",D,[(0,i._)("span",null,[(0,i.WI)(t.$slots,"default")])])}var V=(0,i.aZ)({name:"MessageItem"});const M=(0,f.Z)(V,[["render",E]]);var W=M,z=n(2482);class N{constructor(t){(0,z.Z)(this,"id",void 0),(0,z.Z)(this,"canVibrate",void 0),(0,z.Z)(this,"isVibrating",void 0),(0,z.Z)(this,"unit",void 0),(0,z.Z)(this,"pattern",void 0),this.unit=t,this.id=Date.now(),this.canVibrate=!!this.unit.vibrationActuator,this.isVibrating=!1,this.pattern=[]}update(){const t=navigator.getGamepads();this.unit=t[this.unit.index]}reset(){this.isVibrating=!1,this.unit.vibrationActuator.reset()}async vibrate(t){this.isVibrating=!0,this.pattern=t;while(!0===this.isVibrating)for(let t=0;t<this.pattern.length;t++){if(!0!==this.isVibrating)return;this.unit.vibrationActuator.playEffect("dual-rumble",this.pattern[t]),await this.sleep(this.pattern[t].startDelay+this.pattern[t].duration+100)}}sleep(t){return new Promise((e=>setTimeout(e,t)))}}var T=N,$=(0,i.aZ)({name:"WaveloversApp",components:{PatternList:Z,GamepadList:L,MessageItem:W},data:()=>({gamepads:[],patterns:[],isActive:!1,mode:0}),methods:{loadPatterns:async function(){const t="https://wavelovers.ru/assets/patterns.json";try{const e=await fetch(t);if(e.ok){let t=await e.json();this.patterns=t}else console.log("Connect to the Internet for download more patterns...")}catch(e){console.log(e)}},addEventListeners(){window.addEventListener("gamepadconnected",(t=>this.addGamepad(t))),window.addEventListener("gamepaddisconnected",(t=>this.deleteGamepad(t)))},addGamepad(t){const e=t;this.gamepads.length>=1||this.gamepads.push(new T(e.gamepad))},deleteGamepad(t){this.gamepads.forEach(((e,n)=>{e.unit.id===t.gamepad.id&&this.gamepads.splice(n,1)}))},change(t){this.mode===t?(this.isActive=!this.isActive,this.reset()):(this.isActive=!0,this.mode=t),!0===this.isActive&&(this.reset(),this.vibrate())},vibrate(){this.gamepads.forEach((t=>{t.vibrate(this.patterns[this.mode].pattern)}))},reset(){this.gamepads.forEach((t=>{t.reset()}))}},mounted(){this.loadPatterns(),this.addEventListeners()}});const B=(0,f.Z)($,[["render",d]]);var H=B,K=(0,i.aZ)({name:"App",components:{WaveloversApp:H}});const U=(0,f.Z)(K,[["render",s]]);var Y=U;(0,a.ri)(Y).mount("#app")}},e={};function n(a){var i=e[a];if(void 0!==i)return i.exports;var s=e[a]={exports:{}};return t[a](s,s.exports,n),s.exports}n.m=t,function(){var t=[];n.O=function(e,a,i,s){if(!a){var r=1/0;for(p=0;p<t.length;p++){a=t[p][0],i=t[p][1],s=t[p][2];for(var o=!0,c=0;c<a.length;c++)(!1&s||r>=s)&&Object.keys(n.O).every((function(t){return n.O[t](a[c])}))?a.splice(c--,1):(o=!1,s<r&&(r=s));if(o){t.splice(p--,1);var d=i();void 0!==d&&(e=d)}}return e}s=s||0;for(var p=t.length;p>0&&t[p-1][2]>s;p--)t[p]=t[p-1];t[p]=[a,i,s]}}(),function(){n.n=function(t){var e=t&&t.__esModule?function(){return t["default"]}:function(){return t};return n.d(e,{a:e}),e}}(),function(){n.d=function(t,e){for(var a in e)n.o(e,a)&&!n.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:e[a]})}}(),function(){n.g=function(){if("object"===typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"===typeof window)return window}}()}(),function(){n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}}(),function(){var t={143:0};n.O.j=function(e){return 0===t[e]};var e=function(e,a){var i,s,r=a[0],o=a[1],c=a[2],d=0;if(r.some((function(e){return 0!==t[e]}))){for(i in o)n.o(o,i)&&(n.m[i]=o[i]);if(c)var p=c(n)}for(e&&e(a);d<r.length;d++)s=r[d],n.o(t,s)&&t[s]&&t[s][0](),t[s]=0;return n.O(p)},a=self["webpackChunkwavelovers"]=self["webpackChunkwavelovers"]||[];a.forEach(e.bind(null,0)),a.push=e.bind(null,a.push.bind(a))}();var a=n.O(void 0,[998],(function(){return n(1194)}));a=n.O(a)})();
|
|
//# sourceMappingURL=app.c9621bc7.js.map
|