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(){var t={7375:function(t,e,n){var a=n(4344)["default"];t.exports=class{constructor(t){a(this,"init",(()=>{this.id=Date.now(),this.canVibrate=!!this.unit.vibrationActuator,this.isVibrating=!1,this.pattern=[]})),a(this,"update",(()=>{let t=navigator.getGamepads();this.unit=t[this.unit.index]})),a(this,"reset",(()=>{this.isVibrating=!1,this.unit.vibrationActuator.reset()})),a(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)}})),a(this,"sleep",(t=>new Promise((e=>setTimeout(e,t))))),this.unit=t,this.init()}}},1723:function(t,e,n){"use strict";var a=n(9242),i=n(3396);function s(t,e,n,a,s,r){const o=(0,i.up)("Wavelovers");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:d.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)(n.patterns,((t,e)=>((0,i.wg)(),(0,i.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 h=n(7139);const m=["textContent"],l=["textContent"];function v(t,e,n,a,s,r){return(0,i.wg)(),(0,i.iD)("div",{onClick:e[0]||(e[0]=t=>r.change(n.index)),class:(0,h.C_)(["pattern-item",n.index===n.mode&&!0===n.isActive?"pattern-item_selected":""])},[(0,i._)("span",{class:"pattern-item__icon",textContent:(0,h.zw)(n.pattern.icon)},null,8,m),(0,i._)("span",{class:"pattern-item__name",textContent:(0,h.zw)(n.pattern.name)},null,8,l)],2)}var g={name:"PatternItem",props:{pattern:{type:Object},index:{type:Number},mode:{type:Number},isActive:{type:Boolean}},components:{},methods:{change(t){this.$emit("change",t)}}},f=n(89);const w=(0,f.Z)(g,[["render",v]]);var b=w,y={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 x=A;const j={class:"device-list"};function k(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)(n.gamepads,(t=>((0,i.wg)(),(0,i.j4)(o,{key:t.id,textContent:(0,h.zw)(t.unit.id)},null,8,["textContent"])))),128))])}const C={class:"list-item"};function _(t,e,n,a,s,r){return(0,i.wg)(),(0,i.iD)("div",C)}var O={name:"GamepadItem",components:{}};const P=(0,f.Z)(O,[["render",_]]);var G=P,I={name:"GamepadList",props:{gamepads:{type:Array}},components:{GamepadItem:G}};const L=(0,f.Z)(I,[["render",k]]);var D=L,E=n(7375),Z=n.n(E);const V={class:"message"};function M(t,e,n,a,s,r){return(0,i.wg)(),(0,i.iD)("div",V,[(0,i._)("span",null,[(0,i.WI)(t.$slots,"default")])])}var W={name:"MessageItem",components:{}};const z=(0,f.Z)(W,[["render",M]]);var N=z,T={name:"WaveloversApp",components:{PatternList:x,GamepadList:D,MessageItem:N},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(Z())(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 $=(0,f.Z)(T,[["render",d]]);var B=$,H={name:"App",components:{Wavelovers:B}};const K=(0,f.Z)(H,[["render",s]]);var U=K;(0,a.ri)(U).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(1723)}));a=n.O(a)})();
|
|
//# sourceMappingURL=app.098507b7.js.map
|