2 lines
6.0 KiB
JavaScript
2 lines
6.0 KiB
JavaScript
(function(e){function t(t){for(var s,a,r=t[0],c=t[1],l=t[2],u=0,d=[];u<r.length;u++)a=r[u],Object.prototype.hasOwnProperty.call(i,a)&&i[a]&&d.push(i[a][0]),i[a]=0;for(s in c)Object.prototype.hasOwnProperty.call(c,s)&&(e[s]=c[s]);h&&h(t);while(d.length)d.shift()();return o.push.apply(o,l||[]),n()}function n(){for(var e,t=0;t<o.length;t++){for(var n=o[t],s=!0,r=1;r<n.length;r++){var c=n[r];0!==i[c]&&(s=!1)}s&&(o.splice(t--,1),e=a(a.s=n[0]))}return e}var s={},i={app:0},o=[];function a(t){if(s[t])return s[t].exports;var n=s[t]={i:t,l:!1,exports:{}};return e[t].call(n.exports,n,n.exports,a),n.l=!0,n.exports}a.m=e,a.c=s,a.d=function(e,t,n){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},a.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,t){if(1&t&&(e=a(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(a.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)a.d(n,s,function(t){return e[t]}.bind(null,s));return n},a.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="";var r=window["webpackJsonp"]=window["webpackJsonp"]||[],c=r.push.bind(r);r.push=t,r=r.slice();for(var l=0;l<r.length;l++)t(r[l]);var h=c;o.push([0,"chunk-vendors"]),n()})({0:function(e,t,n){e.exports=n("56d7")},"56d7":function(e,t,n){"use strict";n.r(t);var s=n("7a23");const i={class:"simeon"},o={class:"simeon-wrapper"},a={class:"overlay"},r={class:"start"},c=["disabled"],l={class:"reset"},h=["disabled"],u={class:"simeon-game-board"},d=["onClick"],p={class:"lite"},b={class:"key"};function f(e,t,n,f,k,v){return Object(s["f"])(),Object(s["c"])("div",i,[Object(s["d"])("div",o,[Object(s["d"])("div",a,[Object(s["d"])("div",r,[Object(s["d"])("div",{class:Object(s["e"])(["score",{"score-success":k.success,"score-fail":k.fail}])},Object(s["h"])(k.score),3),Object(s["d"])("button",{disabled:k.started,onClick:t[0]||(t[0]=e=>v.startGame())}," START ",8,c)]),Object(s["d"])("div",l,[Object(s["d"])("button",{disabled:!k.started,onClick:t[1]||(t[1]=e=>v.reset())}," RESET ",8,h)])]),Object(s["d"])("div",u,[(Object(s["f"])(!0),Object(s["c"])(s["a"],null,Object(s["g"])(k.spaces,(e,t)=>(Object(s["f"])(),Object(s["c"])("div",{key:e,onClick:e=>v.checkInput(t),class:Object(s["e"])([[e.klass,{fail:k.fail,blink:k.blink==t||k.success}],"simeon-game-spaces"])},[Object(s["d"])("div",p,[Object(s["d"])("div",b,Object(s["h"])(e.key),1)])],10,d))),128))])])])}n("14d9");const k=()=>{let e=null,t=!0;try{if(window.AudioContext=window.AudioContext||window.webkitAudioContext,e=new AudioContext,t&&"suspended"===e.state){var n=function(){e.resume(),setTimeout((function(){"running"===e.state&&document.body.removeEventListener("touchend",n,!1)}),0)};document.body.addEventListener("touchend",n,!1)}return e}catch(s){return t=!1,alert("Sorry, Web Audio API is not supported in this browser"),null}};var v={name:"App",components:{},data(){return{colors:["green","red","blue","yellow"],started:!1,audioContext:null,oscMain:null,gainMain:null,volume:60,count:4,score:0,blink:null,check:[],pattern:[],fail:!1,success:!1,playing:!1,spaces:[{key:"Q",tone:220,klass:"piece-t-l"},{key:"W",tone:261.63,klass:"piece-t-r"},{key:"A",tone:293.66,klass:"piece-b-l"},{key:"S",tone:329.63,klass:"piece-b-r"}]}},created(){window.addEventListener("keyup",e=>{switch(e.key){case"q":this.playOSC(this.spaces[0].tone),this.checkInput(0);break;case"w":this.playOSC(this.spaces[1].tone),this.checkInput(1);break;case"a":this.playOSC(this.spaces[2].tone),this.checkInput(2);break;case"s":this.playOSC(this.spaces[3].tone),this.checkInput(3);break}})},mounted(){},methods:{playOSC:function(e=440,t="triangle"){null!=this.oscMain&&(this.oscMain.stop(),this.oscMain=null),this.oscMain=null,this.oscMain=this.audioContext.createOscillator(),this.oscMain.type=t,this.oscMain.frequency.value=e,this.gainMain=this.gainMain||this.audioContext.createGain(),this.gainMain.gain.value=this.volume/100,this.oscMain.connect(this.gainMain),this.gainMain.connect(this.audioContext.destination),this.oscMain.start(),this.oscMain.stop(this.audioContext.currentTime+.2)},checkInput(e){if(!this.playing&&this.started){this.blink=e,this.check.length<this.pattern.length&&(this.playOSC(this.spaces[e].tone),this.check.push(e));for(let e=0;e<this.check.length;e++)this.check[e]!=this.pattern[e]&&(this.blink=null,this.fail=!0);this.fail||this.check.length!=this.pattern.length||(this.score+=1,this.check=[],this.success=!0,this.blink=null,setTimeout(()=>{this.success=!1,this.fail=!1,this.addToPattern(),this.playPattern()},200))}},startGame(){this.started=!0,this.audioContext||(this.audioContext=k()),this.reset()},reset(){this.fail=!1,this.success=!1,this.pattern=[],this.check=[],this.score=0,this.addToPattern(),this.playPattern()},playPattern(){var e=0;this.playing=!0;var t=setInterval(()=>{this.blink=this.pattern[e],this.playOSC(this.spaces[this.pattern[e]].tone),e++,setTimeout(()=>{this.blink=null},500),e>=this.pattern.length&&(clearInterval(t),setTimeout(()=>{this.blink=null,this.playing=!1},200))},600)},addToPattern(){this.pattern.push(Math.floor(4*Math.random()))}}},y=(n("e829"),n("6b0d")),g=n.n(y);const O=g()(v,[["render",f]]);var m=O,j=n("9483");Object(j["a"])("service-worker.js",{ready(){console.log("App is being served from cache by a service worker.\nFor more details, visit https://goo.gl/AFskqB")},registered(){console.log("Service worker has been registered.")},cached(){console.log("Content has been cached for offline use.")},updatefound(){console.log("New content is downloading.")},updated(){console.log("New content is available; please refresh.")},offline(){console.log("No internet connection found. App is running in offline mode.")},error(e){console.error("Error during service worker registration:",e)}}),Object(s["b"])(m).mount("#app")},8530:function(e,t,n){},e829:function(e,t,n){"use strict";n("8530")}});
|
|
//# sourceMappingURL=app.4b99dfb1.js.map
|