mirror of
https://github.com/eugene-serb/wavelovers.git
synced 2023-09-09 23:41:16 +03:00
2 lines
7.9 KiB
JavaScript
2 lines
7.9 KiB
JavaScript
(function(){"use strict";var t={9839:function(t,e,n){var a=n(9242),s=n(3396);function i(t,e,n,a,i,r){const o=(0,s.up)("router-view");return(0,s.wg)(),(0,s.j4)(o)}var r=(0,s.aZ)({name:"App"}),o=n(89);const c=(0,o.Z)(r,[["render",i]]);var d=c,p=n(2483);function u(t,e,n,a,i,r){const o=(0,s.up)("WaveloversApp");return(0,s.wg)(),(0,s.j4)(o)}const m={class:"wavelovers"},v=(0,s.Uk)("Loading..."),g=(0,s.Uk)("Press any gamepad button or connect a new gamepad to vibrate.");function l(t,e,n,a,i,r){const o=(0,s.up)("PatternList"),c=(0,s.up)("MessageItem"),d=(0,s.up)("GamepadList");return(0,s.wg)(),(0,s.iD)("div",m,[t.patterns.length>0?((0,s.wg)(),(0,s.j4)(o,{key:0,patterns:t.patterns,mode:t.mode,isActive:t.isActive,onChange:t.change},null,8,["patterns","mode","isActive","onChange"])):((0,s.wg)(),(0,s.j4)(c,{key:1},{default:(0,s.w5)((()=>[v])),_:1})),t.gamepads.length>0?((0,s.wg)(),(0,s.j4)(d,{key:2,gamepads:t.gamepads},null,8,["gamepads"])):((0,s.wg)(),(0,s.j4)(c,{key:3},{default:(0,s.w5)((()=>[g])),_:1}))])}const h={class:"pattern-list"};function f(t,e,n,a,i,r){const o=(0,s.up)("PatternItem");return(0,s.wg)(),(0,s.iD)("div",h,[((0,s.wg)(!0),(0,s.iD)(s.HY,null,(0,s.Ko)(t.patterns,((e,n)=>((0,s.wg)(),(0,s.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 w=n(7139);const b=["textContent"],y=["textContent"];function A(t,e,n,a,i,r){return(0,s.wg)(),(0,s.iD)("div",{onClick:e[0]||(e[0]=e=>t.change(t.index)),class:(0,w.C_)(["pattern-item",t.index===t.mode&&!0===t.isActive?"pattern-item_selected":""])},[(0,s._)("span",{class:"pattern-item__icon",textContent:(0,w.zw)(t.pattern.icon)},null,8,b),(0,s._)("span",{class:"pattern-item__name",textContent:(0,w.zw)(t.pattern.name)},null,8,y)],2)}var Z=(0,s.aZ)({name:"PatternItem",props:{pattern:{type:Object},index:{type:Number},mode:{type:Number},isActive:{type:Boolean}},methods:{change:function(t){this.$emit("change",t)}}});const G=(0,o.Z)(Z,[["render",A]]);var j=G,x=(0,s.aZ)({name:"PatternList",props:{patterns:{type:Array},mode:{type:Number},isActive:{type:Boolean}},components:{PatternItem:j},methods:{change:function(t){this.$emit("change",t)}}});const I=(0,o.Z)(x,[["render",f]]);var P=I;const k={class:"device-list"};function C(t,e,n,a,i,r){const o=(0,s.up)("GamepadItem");return(0,s.wg)(),(0,s.iD)("div",k,[((0,s.wg)(!0),(0,s.iD)(s.HY,null,(0,s.Ko)(t.gamepads,(t=>((0,s.wg)(),(0,s.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,a,i,r){return(0,s.wg)(),(0,s.iD)("div",L)}var O=(0,s.aZ)({name:"GamepadItem"});const _=(0,o.Z)(O,[["render",E]]);var M=_,D=(0,s.aZ)({name:"GamepadList",props:{gamepads:{type:Array}},components:{GamepadItem:M}});const V=(0,o.Z)(D,[["render",C]]);var T=V;const W={class:"message"};function z(t,e,n,a,i,r){return(0,s.wg)(),(0,s.iD)("div",W,[(0,s._)("span",null,[(0,s.WI)(t.$slots,"default")])])}var H=(0,s.aZ)({name:"MessageItem"});const N=(0,o.Z)(H,[["render",z]]);var $=N,B=n(65),K=n(2482);class U{constructor(t){(0,K.Z)(this,"id",void 0),(0,K.Z)(this,"canVibrate",void 0),(0,K.Z)(this,"isVibrating",void 0),(0,K.Z)(this,"unit",void 0),(0,K.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)}}sleep(t){return new Promise((e=>setTimeout(e,t)))}}var Y=U;const F={state:()=>({gamepads:[]}),getters:{gamepads:function(t){return t.gamepads}},mutations:{addGamepad:function(t,e){t.gamepads.push(e)},deleteGamepad:function(t,e){t.gamepads.splice(e,1)}},actions:{addGamepad:function(t,e){const n=e;t.getters.gamepads.length>=1||t.commit("addGamepad",new Y(n.gamepad))},deleteGamepad:function(t,e){t.getters.gamepads.forEach(((n,a)=>{n.unit.id===e.gamepad.id&&t.commit("deleteGamepad",a)}))},vibrate:function(t){t.getters.gamepads.forEach((e=>{e.vibrate(t.getters.patterns[t.getters.mode].pattern)}))},reset:function(t){t.getters.gamepads.forEach((t=>{t.reset()}))}}};var q=F;const J={state:()=>({patterns:[]}),getters:{patterns:function(t){return t.patterns}},mutations:{setPatterns:function(t,e){t.patterns=e}},actions:{loadPatterns:async function(t){const e="https://wavelovers.ru/assets/patterns.json";try{const n=await fetch(e);if(n.ok){const e=await n.json();t.commit("setPatterns",e)}else console.log("Connect to the Internet for download more patterns...")}catch(n){console.log(n)}}}};var Q=J;const R=(0,B.MT)({state:()=>({mode:0,isActive:!1}),getters:{mode:function(t){return t.mode},isActive:function(t){return t.isActive}},mutations:{setMode:function(t,e){t.mode=e},setIsActive:function(t,e){t.isActive=e}},actions:{setMode:function(t,e){t.commit("setMode",e)},setIsActive:function(t,e){t.commit("setIsActive",e)},change:function(t,e){t.getters.mode===e?t.dispatch("setIsActive",!t.getters.isActive):(t.dispatch("setIsActive",!0),t.dispatch("setMode",e)),!0===t.getters.isActive?(t.dispatch("reset"),t.dispatch("vibrate")):t.dispatch("reset")}},modules:{MGamepads:q,MPatterns:Q}});var S=R,X=(0,s.aZ)({name:"WaveloversApp",components:{PatternList:P,GamepadList:T,MessageItem:$},computed:{gamepads:function(){return S.getters.gamepads},patterns:function(){return S.getters.patterns},mode:function(){return S.getters.mode},isActive:function(){return S.getters.isActive}},methods:{addEventListeners(){window.addEventListener("gamepadconnected",(t=>S.dispatch("addGamepad",t))),window.addEventListener("gamepaddisconnected",(t=>S.dispatch("deleteGamepad",t)))},removeEventListeners(){window.removeEventListener("gamepadconnected",(t=>S.dispatch("addGamepad",t))),window.removeEventListener("gamepaddisconnected",(t=>S.dispatch("deleteGamepad",t)))},change(t){S.dispatch("change",t)}},mounted(){S.dispatch("loadPatterns"),this.addEventListeners()},unmounted(){this.removeEventListeners()}});const tt=(0,o.Z)(X,[["render",l]]);var et=tt,nt=(0,s.aZ)({name:"HomeView",components:{WaveloversApp:et}});const at=(0,o.Z)(nt,[["render",u]]);var st=at;const it=[{path:"/",name:"home",component:st}],rt=(0,p.p7)({history:(0,p.PO)("/"),routes:it});var ot=rt;(0,a.ri)(d).use(S).use(ot).mount("#app")}},e={};function n(a){var s=e[a];if(void 0!==s)return s.exports;var i=e[a]={exports:{}};return t[a](i,i.exports,n),i.exports}n.m=t,function(){var t=[];n.O=function(e,a,s,i){if(!a){var r=1/0;for(p=0;p<t.length;p++){a=t[p][0],s=t[p][1],i=t[p][2];for(var o=!0,c=0;c<a.length;c++)(!1&i||r>=i)&&Object.keys(n.O).every((function(t){return n.O[t](a[c])}))?a.splice(c--,1):(o=!1,i<r&&(r=i));if(o){t.splice(p--,1);var d=s();void 0!==d&&(e=d)}}return e}i=i||0;for(var p=t.length;p>0&&t[p-1][2]>i;p--)t[p]=t[p-1];t[p]=[a,s,i]}}(),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 s,i,r=a[0],o=a[1],c=a[2],d=0;if(r.some((function(e){return 0!==t[e]}))){for(s in o)n.o(o,s)&&(n.m[s]=o[s]);if(c)var p=c(n)}for(e&&e(a);d<r.length;d++)i=r[d],n.o(t,i)&&t[i]&&t[i][0](),t[i]=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(9839)}));a=n.O(a)})();
|
|
//# sourceMappingURL=app.93acf04c.js.map
|