wavelovers/docs/js/app.6d107a0d.js

2 lines
6.1 KiB
JavaScript

(function(){var t={7375:function(t,e,n){var i=n(4344)["default"];t.exports=class{constructor(t){i(this,"init",(()=>{this.id=Date.now(),this.canVibrate=!!this.unit.vibrationActuator,this.isVibrating=!1,this.pattern=[]})),i(this,"update",(()=>{let t=navigator.getGamepads();this.unit=t[this.unit.index]})),i(this,"reset",(()=>{this.isVibrating=!1,this.unit.vibrationActuator.reset()})),i(this,"vibrate",(async 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)}})),i(this,"sleep",(t=>new Promise((e=>setTimeout(e,t))))),this.unit=t,this.init()}}},3596:function(t,e,n){"use strict";var i=n(9242),a=n(3396);function s(t,e,n,i,s,r){const o=(0,a.up)("Wavelovers");return(0,a.wg)(),(0,a.j4)(o)}const r={class:"wavelovers"},o={class:"content-item"},c={key:1,class:"message"},d=(0,a._)("span",null,"Loading...",-1),p=[d],u={class:"content-item"},h={key:1,class:"message"},l=(0,a._)("span",null,"Press any gamepad's button or connect new gamepad.",-1),m=[l];function v(t,e,n,i,s,d){const l=(0,a.up)("PatternList"),v=(0,a.up)("GamepadList");return(0,a.wg)(),(0,a.iD)("div",r,[(0,a._)("div",o,[t.patterns.length>0?((0,a.wg)(),(0,a.j4)(l,{key:0,patterns:t.patterns,mode:t.mode,isActive:t.isActive,onChange:d.change},null,8,["patterns","mode","isActive","onChange"])):((0,a.wg)(),(0,a.iD)("div",c,p))]),(0,a._)("div",u,[t.gamepads.length>0?((0,a.wg)(),(0,a.j4)(v,{key:0,gamepads:t.gamepads},null,8,["gamepads"])):((0,a.wg)(),(0,a.iD)("div",h,m))])])}const g={class:"pattern-list"};function f(t,e,n,i,s,r){const o=(0,a.up)("PatternItem");return(0,a.wg)(),(0,a.iD)("div",g,[((0,a.wg)(!0),(0,a.iD)(a.HY,null,(0,a.Ko)(n.patterns,((t,e)=>((0,a.wg)(),(0,a.j4)(o,{key:t.name,pattern:t,index:e,mode:n.mode,isActive:n.isActive,onChange:r.change},null,8,["pattern","index","mode","isActive","onChange"])))),128))])}var w=n(7139);const b=["textContent"],y=["textContent"];function A(t,e,n,i,s,r){return(0,a.wg)(),(0,a.iD)("div",{onClick:e[0]||(e[0]=t=>r.change(n.index)),class:(0,w.C_)(["pattern-item",n.index===n.mode&&!0===n.isActive?"pattern-item_selected":""])},[(0,a._)("span",{class:"pattern-item__icon",textContent:(0,w.zw)(n.pattern.icon)},null,8,b),(0,a._)("span",{class:"pattern-item__name",textContent:(0,w.zw)(n.pattern.name)},null,8,y)],2)}var x={name:"PatternItem",props:{pattern:{type:Object},index:{type:Number},mode:{type:Number},isActive:{type:Boolean}},components:{},methods:{change(t){this.$emit("change",t)}}},C=n(89);const j=(0,C.Z)(x,[["render",A]]);var _=j,k={name:"PatternList",props:{patterns:{type:Array},mode:{type:Number},isActive:{type:Boolean}},components:{PatternItem:_},methods:{change(t){this.$emit("change",t)}}};const O=(0,C.Z)(k,[["render",f]]);var P=O;const D={class:"device-list"};function G(t,e,n,i,s,r){const o=(0,a.up)("GamepadItem");return(0,a.wg)(),(0,a.iD)("div",D,[((0,a.wg)(!0),(0,a.iD)(a.HY,null,(0,a.Ko)(n.gamepads,(t=>((0,a.wg)(),(0,a.j4)(o,{key:t.id,textContent:(0,w.zw)(t.unit.id)},null,8,["textContent"])))),128))])}const L={class:"list-item"};function E(t,e,n,i,s,r){return(0,a.wg)(),(0,a.iD)("div",L)}var I={name:"GamepadItem",components:{}};const V=(0,C.Z)(I,[["render",E]]);var Z=V,z={name:"GamepadList",props:{gamepads:{type:Array}},components:{GamepadItem:Z}};const N=(0,C.Z)(z,[["render",G]]);var T=N,W=n(7375),B=n.n(W),H={name:"WaveloversApp",components:{PatternList:P,GamepadList:T},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("[error]",e)}},addEventListeners(){window.addEventListener("gamepadconnected",(()=>this.addGamepad(event))),window.addEventListener("gamepaddisconnected",(()=>this.deleteGamepad(event)))},addGamepad(t){this.gamepads.length>1||this.gamepads.push(new(B())(t.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 K=(0,C.Z)(H,[["render",v]]);var Y=K,$={name:"App",components:{Wavelovers:Y}};const F=(0,C.Z)($,[["render",s]]);var M=F;(0,i.ri)(M).mount("#app")}},e={};function n(i){var a=e[i];if(void 0!==a)return a.exports;var s=e[i]={exports:{}};return t[i](s,s.exports,n),s.exports}n.m=t,function(){var t=[];n.O=function(e,i,a,s){if(!i){var r=1/0;for(p=0;p<t.length;p++){i=t[p][0],a=t[p][1],s=t[p][2];for(var o=!0,c=0;c<i.length;c++)(!1&s||r>=s)&&Object.keys(n.O).every((function(t){return n.O[t](i[c])}))?i.splice(c--,1):(o=!1,s<r&&(r=s));if(o){t.splice(p--,1);var d=a();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]=[i,a,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 i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})}}(),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,i){var a,s,r=i[0],o=i[1],c=i[2],d=0;if(r.some((function(e){return 0!==t[e]}))){for(a in o)n.o(o,a)&&(n.m[a]=o[a]);if(c)var p=c(n)}for(e&&e(i);d<r.length;d++)s=r[d],n.o(t,s)&&t[s]&&t[s][0](),t[s]=0;return n.O(p)},i=self["webpackChunkwavelovers"]=self["webpackChunkwavelovers"]||[];i.forEach(e.bind(null,0)),i.push=e.bind(null,i.push.bind(i))}();var i=n.O(void 0,[998],(function(){return n(3596)}));i=n.O(i)})();
//# sourceMappingURL=app.6d107a0d.js.map