pacman-contribution-graph 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pacman-contribution-graph.min.js +1 -1
- package/github-action/dist/index.js +474 -474
- package/github-action/package.json +1 -1
- package/github-action/pnpm-lock.yaml +5 -5
- package/package.json +1 -1
- package/src/canvas.ts +2 -2
- package/src/constants.ts +6 -6
- package/src/game.ts +13 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
var t={d:(n,e)=>{for(var a in e)t.o(e,a)&&!t.o(n,a)&&Object.defineProperty(n,a,{enumerable:!0,get:e[a]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n)},n={};t.d(n,{C:()=>P});const e=52,a="yellow",o="#80808064",i=["blinky","clyde","inky","pinky"],s=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],c={github:{textColor:"#586069",gridBackground:"#ffffff",contributionBoxColor:"#9be9a8",emptyContributionBoxColor:"#ebedf0"},"github-dark":{textColor:"#8b949e",gridBackground:"#0d1117",contributionBoxColor:"#26a641",emptyContributionBoxColor:"#161b22"},gitlab:{textColor:"#626167",gridBackground:"#ffffff",contributionBoxColor:"#7992f5",emptyContributionBoxColor:"#ececef"},"gitlab-dark":{textColor:"#999999",gridBackground:"#1f1f1f",contributionBoxColor:"#2e7db1",emptyContributionBoxColor:"#2d2d2d"}},r={blinky:{imgDate:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAfUlEQVQ4T+2TUQ7AIAhDy/0PzQIRAqxmLtnn/DJPWypBAVkKKOMCyOQN7IRElLrcnIrDLNK4wVtxNbkb6Hq+jOcSbim6QVzKEstkw92gxVeFrMpqokix4wA+NvCOnvfArvcEbHoe2G9QmmhDMUc65p3xYC6q3zQPxtdl3NgF5QpL/b/rs3IAAAAASUVORK5CYIIA",img:new Image},clyde:{imgDate:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAgUlEQVQ4T+2T0Q6AIAhFLx9sH1MfTIPCAeLKrcd8PHqP4JBQLN7BFacNlHkAs+AQcqIueBs2mVWjgtWwl4yCdrd/pHYLLlVEgR2yK0wy4SoI5TcGXU4wM+AEJQfwsUCuXngDOR4rqKbngf0C94gyFHmkbd4rbkxD/pv2jfR1Ky7sBNrzXbHpnBX+AAAAAElFTkSuQmCC",img:new Image},inky:{imgDate:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAg0lEQVQ4T+WTWxKAIAhFuQvK/a+jFoT5QAVxypn+6vMEx6sDIO/jk12OAMs1WDVOXV3UBW+bRVbTFMFu8yCZBExH/g26VHCXI0AJpKgdUCUrTlkwxE+FECdzS7HiJemXgvyeO29gE7jD8wDVFX4vSLNtR1q2z+OVlaZxTaXYrq7HbxYBS8VgMVrqzkEAAAAASUVORK5CYIIA",img:new Image},pinky:{imgDate:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAhklEQVQ4T+2T0Q2AIAwF281wC50Qt9DNagoptqVESfyUz4N3vJCCECxaD4o47gt6bsAo2IWUqAnehkUmbYpgNqwlvSCnur+dtnnAuYUVyCGJimTAi8DUzwmwOoGI7hYjDgAfC/jqiTfg47ZBND0P7BeoR+Sh8CMt8x5xYSWkv2nbcF834swuA/9u49Yy5bgAAAAASUVORK5CYIIA",img:new Image},scared:{imgDate:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAeUlEQVQ4T82TUQ6AMAhD7UX0/sdyF0GREVmDmTN+bH9r6Bs0A0t2VpFULwDrrfBkZFcA3YC3ZodViAFGzQHyP0B2w2NrB0/1AoDbHwLoQ5/nrw1OBuD5e/crbM9Aiz35njHWzpSB/m3+0r40mV41M8U19WJe3Uw/tQOKt08pUUbBEQAAAABJRU5ErkJgggAA",img:new Image}};var g,u=function(t,n,e,a){return new(e||(e=Promise))((function(o,i){function s(t){try{r(a.next(t))}catch(t){i(t)}}function c(t){try{r(a.throw(t))}catch(t){i(t)}}function r(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(s,c)}r((a=a.apply(t,n||[])).next())}))};!function(t){t.DEFAULT="https://cdn.jsdelivr.net/npm/pacman-contribution-graph/src/assets/sounds/pacman_chomp.wav",t.BEGINNING="https://cdn.jsdelivr.net/npm/pacman-contribution-graph/src/assets/sounds/pacman_beginning.wav",t.GAME_OVER="https://cdn.jsdelivr.net/npm/pacman-contribution-graph/src/assets/sounds/pacman_death.wav",t.EAT_GHOST="https://cdn.jsdelivr.net/npm/pacman-contribution-graph/src/assets/sounds/pacman_eatghost.wav"}(g||(g={}));class d{constructor(){this.sounds=new Map,this.currentSource=null,this.defaultSource=null,this.isMuted=!1,this.audioContext=new AudioContext}static getInstance(){return d.instance||(d.instance=new d),d.instance}preloadSounds(){return u(this,void 0,void 0,(function*(){for(const t of Object.values(g)){const n=yield fetch(t),e=yield n.arrayBuffer(),a=yield this.audioContext.decodeAudioData(e);this.sounds.set(t,a)}}))}play(t){return u(this,void 0,void 0,(function*(){if(this.isMuted)return;if(this.currentSource)try{this.currentSource.stop()}catch(t){}const n=this.sounds.get(t);if(n)return this.currentSource=this.audioContext.createBufferSource(),this.currentSource.buffer=n,this.currentSource.connect(this.audioContext.destination),this.isMuted||this.currentSource.start(),new Promise((t=>{this.currentSource.onended=()=>{this.currentSource=null,t()}}));console.error(`Sound ${t} not found`)}))}startDefaultSound(){if(this.defaultSource)try{this.defaultSource.stop()}catch(t){}const t=this.sounds.get(g.DEFAULT);t?(this.defaultSource=this.audioContext.createBufferSource(),this.defaultSource.buffer=t,this.defaultSource.loop=!0,this.defaultSource.connect(this.audioContext.destination),this.isMuted||this.defaultSource.start()):console.error("Default sound not found")}stopDefaultSound(){if(this.defaultSource){try{this.defaultSource.stop()}catch(t){}this.defaultSource=null}}mute(){this.isMuted=!0,this.currentSource&&this.currentSource.disconnect(),this.defaultSource&&this.defaultSource.disconnect()}unmute(){this.isMuted=!1,this.currentSource&&this.currentSource.connect(this.audioContext.destination),this.defaultSource&&this.defaultSource.connect(this.audioContext.destination)}}var m=function(t,n,e,a){return new(e||(e=Promise))((function(o,i){function s(t){try{r(a.next(t))}catch(t){i(t)}}function c(t){try{r(a.throw(t))}catch(t){i(t)}}function r(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(s,c)}r((a=a.apply(t,n||[])).next())}))};const l=t=>m(void 0,void 0,void 0,(function*(){const n=yield fetch(`https://v0-new-project-q1hhrdodoye-abozanona-gmailcoms-projects.vercel.app/api/contributions?username=${t.config.username}`),e=yield n.json();return Object.entries(e).map((([t,n])=>({date:new Date(t),count:Number(n)})))})),h=t=>m(void 0,void 0,void 0,(function*(){var n;const e=[];let a=!1,o=1;do{try{const i={};(null===(n=t.config.githubSettings)||void 0===n?void 0:n.accessToken)&&(i.Authorization="Bearer "+t.config.githubSettings.accessToken);const s=yield fetch(`https://api.github.com/search/commits?q=author:${t.config.username}&sort=author-date&order=desc&page=${o}&per_page=1000`,{headers:i}),c=yield s.json();a=0===c.items.length,e.push(...c.items),o++}catch(t){a=!0}}while(!a);return Array.from(e.reduce(((t,n)=>{const e=n.commit.committer.date.split("T")[0],a=new Date(e),o=(t.get(e)||{count:0}).count+1;return t.set(e,{date:a,count:o})}),new Map).values())})),f=t=>{var n;return null!==(n=c[t.config.gameTheme])&&void 0!==n?n:c.github},p=function(t,n){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${n})`},y=t=>{t.config.canvas.getContext("2d").fillStyle=f(t).gridBackground,t.config.canvas.getContext("2d").fillRect(0,0,t.config.canvas.width,t.config.canvas.height);for(let n=0;n<7;n++)for(let a=0;a<e;a++){const e=t.grid[n][a].intensity;if(e>0){const n=e<.2?.3:e,a=p(f(t).contributionBoxColor,n);t.config.canvas.getContext("2d").fillStyle=a}else t.config.canvas.getContext("2d").fillStyle=f(t).emptyContributionBoxColor;t.config.canvas.getContext("2d").beginPath(),t.config.canvas.getContext("2d").roundRect(22*a,22*n+15,20,20,5),t.config.canvas.getContext("2d").fill()}t.config.canvas.getContext("2d").fillStyle=f(t).textColor,t.config.canvas.getContext("2d").font="10px Arial",t.config.canvas.getContext("2d").textAlign="center";let n="";for(let a=0;a<e;a++)if(t.monthLabels[a]!==n){const e=22*a+10;t.config.canvas.getContext("2d").fillText(t.monthLabels[a],e,10),n=t.monthLabels[a]}},A=t=>{const n=22*t.pacman.y+10,e=22*t.pacman.x+10+15;t.pacman.deadRemainingDuration?t.config.canvas.getContext("2d").fillStyle=o:t.pacman.powerupRemainingDuration?t.config.canvas.getContext("2d").fillStyle="red":t.config.canvas.getContext("2d").fillStyle=a;const i=t.pacmanMouthOpen?.35*Math.PI:.1*Math.PI;let s,c;switch(t.pacman.direction){case"up":s=1.5*Math.PI+i,c=1.5*Math.PI-i;break;case"down":s=.5*Math.PI+i,c=.5*Math.PI-i;break;case"left":s=Math.PI+i,c=Math.PI-i;break;default:s=0+i,c=2*Math.PI-i}t.config.canvas.getContext("2d").beginPath(),t.config.canvas.getContext("2d").arc(n,e,10,s,c),t.config.canvas.getContext("2d").lineTo(n,e),t.config.canvas.getContext("2d").fill()},v=t=>{t.ghosts.forEach((n=>{const e=22*n.y,a=22*n.x+15,o=t.config.canvas.getContext("2d");n.scared?o.drawImage(r.scared.img,e,a,20,20):o.drawImage(r[n.name].img,e,a,20,20)}))},x=t=>{t.config.enableSounds&&t.config.canvas.addEventListener("click",(function(n){const e=t.config.canvas.getBoundingClientRect(),a=n.clientX-e.left,o=n.clientY-e.top,i=t.config.canvas.width-30-10;a>=i&&a<=i+this.width&&o>=10&&o<=10+this.height&&(d.getInstance().isMuted?d.getInstance().unmute():d.getInstance().mute())}))},b=t=>{const n=10,e=t,a=2*Math.PI-t;return`M 10,10\n L ${n+n*Math.cos(e)},${n+n*Math.sin(e)}\n A 10,10 0 1,1 ${n+n*Math.cos(a)},${n+n*Math.sin(a)}\n Z`},C=t=>t.gameHistory.map(((n,e)=>e/(t.gameHistory.length-1))).join(";"),w=(t,n,e)=>t.gameHistory.map((a=>{const o=a.grid[n][e];return o>0?M(t,o):f(t).emptyContributionBoxColor})).join(";"),M=(t,n)=>{const e=n<.2?.3:n;return p(f(t).contributionBoxColor,e)},D=t=>{let n='<svg width="1144" height="174" xmlns="http://www.w3.org/2000/svg">';n+="<desc>Generated with https://github.com/abozanona/pacman-contribution-graph</desc>",n+=`<rect width="100%" height="100%" fill="${f(t).gridBackground}"/>`,n+=`<defs>\n\t\t<symbol id="blinky" viewBox="0 0 100 100">\n <image href="${r.blinky.imgDate}" width="100" height="100"/>\n\t\t</symbol>\n\t\t<symbol id="clyde" viewBox="0 0 100 100">\n <image href="${r.clyde.imgDate}" width="100" height="100"/>\n\t\t</symbol>\n\t\t<symbol id="inky" viewBox="0 0 100 100">\n <image href="${r.inky.imgDate}" width="100" height="100"/>\n\t\t</symbol>\n\t\t<symbol id="pinky" viewBox="0 0 100 100">\n <image href="${r.pinky.imgDate}" width="100" height="100"/>\n\t\t</symbol>\n\t\t<symbol id="scared" viewBox="0 0 100 100">\n <image href="${r.scared.imgDate}" width="100" height="100"/>\n\t\t</symbol>\n\t</defs>`;let i="";for(let a=0;a<e;a++)t.monthLabels[a]!==i&&(n+=`<text x="${22*a+10}" y="10" text-anchor="middle" font-size="10" fill="${f(t).textColor}">${t.monthLabels[a]}</text>`,i=t.monthLabels[a]);for(let a=0;a<7;a++)for(let o=0;o<e;o++){const e=22*o,i=22*a+15,s=t.gameHistory[0].grid[a][o],c=s>0?M(t,s):f(t).emptyContributionBoxColor;n+=`<rect id="cell-${a}-${o}" x="${e}" y="${i}" width="20" height="20" rx="5" fill="${c}">\n <animate attributeName="fill" dur="${300*t.gameHistory.length}ms" repeatCount="indefinite" \n values="${w(t,a,o)}" \n keyTimes="${C(t)}"/>\n </rect>`}return n+=`<path id="pacman" d="${b(.35)}"\n transform="translate(${22*t.pacman.y}, ${22*t.pacman.x+15})">\n\t\t<animate attributeName="fill" dur="${300*t.gameHistory.length}ms" repeatCount="indefinite"\n keyTimes="${C(t)}"\n values="${(t=>t.gameHistory.map((t=>t.pacman.deadRemainingDuration?o:t.pacman.powerupRemainingDuration?"red":a)).join(";"))(t)}"/>\n <animateTransform attributeName="transform" type="translate" dur="${300*t.gameHistory.length}ms" repeatCount="indefinite"\n keyTimes="${C(t)}"\n values="${(t=>t.gameHistory.map((t=>`${22*t.pacman.y},${22*t.pacman.x+15}`)).join(";"))(t)}"/>\n <animate attributeName="d" dur="0.2s" repeatCount="indefinite"\n values="${b(.25)};${b(.05)};${b(.25)}"/>\n </path>`,t.ghosts.forEach(((e,a)=>{n+=`<use id="ghost${a}" width="20" height="20" href="#ghost-${e.name}">\n <animateTransform attributeName="transform" type="translate" dur="${300*t.gameHistory.length}ms" repeatCount="indefinite"\n keyTimes="${C(t)}"\n values="${((t,n)=>t.gameHistory.map((t=>{const e=t.ghosts[n];return`${22*e.y},${22*e.x+15}`})).join(";"))(t,a)}"/>\n <animate attributeName="href" dur="${300*t.gameHistory.length}ms" repeatCount="indefinite"\n keyTimes="${C(t)}"\n values="${((t,n)=>t.gameHistory.map((t=>{const e=t.ghosts[n];return e.scared?"#scared":"#"+e.name})).join(";"))(t,a)}"/>\n </use>`})),n+="</svg>",n};var S=function(t,n,e,a){return new(e||(e=Promise))((function(o,i){function s(t){try{r(a.next(t))}catch(t){i(t)}}function c(t){try{r(a.throw(t))}catch(t){i(t)}}function r(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(s,c)}r((a=a.apply(t,n||[])).next())}))};const I=t=>S(void 0,void 0,void 0,(function*(){if(t.frameCount++,t.frameCount%t.config.gameSpeed==0)if(t.pacman.deadRemainingDuration&&(t.pacman.deadRemainingDuration--,t.pacman.deadRemainingDuration||"canvas"==t.config.outputFormat&&d.getInstance().play(g.GAME_OVER).then((()=>d.getInstance().startDefaultSound()))),t.pacman.powerupRemainingDuration&&(t.pacman.powerupRemainingDuration--,t.pacman.powerupRemainingDuration||(t.ghosts.forEach((t=>t.scared=!1)),t.pacman.points=0)),t.grid.some((t=>t.some((t=>t.intensity>0)))))k(t),B(t),E(t),t.pacmanMouthOpen=!t.pacmanMouthOpen,t.gameHistory.push({pacman:Object.assign({},t.pacman),ghosts:t.ghosts.map((t=>Object.assign({},t))),grid:t.grid.map((t=>[...t.map((t=>t.intensity))]))}),"canvas"==t.config.outputFormat&&y(t),"canvas"==t.config.outputFormat&&A(t),"canvas"==t.config.outputFormat&&v(t),"canvas"==t.config.outputFormat&&(t=>{if(!t.config.enableSounds)return;const n=t.config.canvas.width-30-10;t.config.canvas.getContext("2d").fillStyle=`rgba(0, 0, 0, ${d.getInstance().isMuted?.3:.5})`,t.config.canvas.getContext("2d").beginPath(),t.config.canvas.getContext("2d").moveTo(n+10,20),t.config.canvas.getContext("2d").lineTo(n+20,15),t.config.canvas.getContext("2d").lineTo(n+20,35),t.config.canvas.getContext("2d").lineTo(n+10,30),t.config.canvas.getContext("2d").closePath(),t.config.canvas.getContext("2d").fill(),d.getInstance().isMuted?(t.config.canvas.getContext("2d").strokeStyle="rgba(255, 0, 0, 0.6)",t.config.canvas.getContext("2d").lineWidth=3,t.config.canvas.getContext("2d").beginPath(),t.config.canvas.getContext("2d").moveTo(n+25,15),t.config.canvas.getContext("2d").lineTo(n+5,35),t.config.canvas.getContext("2d").stroke()):(t.config.canvas.getContext("2d").strokeStyle="rgba(0, 0, 0, 0.4)",t.config.canvas.getContext("2d").lineWidth=2,t.config.canvas.getContext("2d").beginPath(),t.config.canvas.getContext("2d").arc(n+25,25,5,0,2*Math.PI),t.config.canvas.getContext("2d").stroke(),t.config.canvas.getContext("2d").beginPath(),t.config.canvas.getContext("2d").arc(n+25,25,8,0,2*Math.PI),t.config.canvas.getContext("2d").stroke())})(t);else{if("canvas"==t.config.outputFormat&&(clearInterval(t.gameInterval),"canvas"==t.config.outputFormat&&((t=>{t.config.canvas.getContext("2d").fillStyle=f(t).textColor,t.config.canvas.getContext("2d").font="20px Arial",t.config.canvas.getContext("2d").textAlign="center",t.config.canvas.getContext("2d").fillText("Game Over",t.config.canvas.width/2,t.config.canvas.height/2)})(t),d.getInstance().play(g.BEGINNING).then((()=>d.getInstance().stopDefaultSound())))),"svg"==t.config.outputFormat){const n=D(t);t.config.svgCallback(n)}t.config.gameOverCallback()}else t.gameHistory.push({pacman:Object.assign({},t.pacman),ghosts:t.ghosts.map((t=>Object.assign({},t))),grid:t.grid.map((t=>[...t.map((t=>t.intensity))]))})})),k=t=>{if(t.pacman.deadRemainingDuration)return;let n=[];if(t.pacman.powerupRemainingDuration)n=t.ghosts.map((t=>({x:t.x,y:t.y,distance:1/0})));else for(let a=0;a<7;a++)for(let o=0;o<e;o++)t.grid[a][o].intensity>0&&n.push({x:a,y:o,distance:1/0});if(0===n.length)return;const a=n.reduce(((n,e)=>{const a=Math.abs(e.x-t.pacman.x)+Math.abs(e.y-t.pacman.y);return a<n.distance?Object.assign(Object.assign({},e),{distance:a}):n}),{x:t.pacman.x,y:t.pacman.y,distance:1/0}),o=a.x-t.pacman.x,i=a.y-t.pacman.y;Math.abs(o)>Math.abs(i)?(t.pacman.x+=Math.sign(o),t.pacman.direction=o>0?"down":"up"):(t.pacman.y+=Math.sign(i),t.pacman.direction=i>0?"right":"left"),t.grid[t.pacman.x][t.pacman.y].intensity>0&&(t.pacman.totalPoints+=t.grid[t.pacman.x][t.pacman.y].commitsCount,t.pacman.points++,t.config.pointsIncreasedCallback(t.pacman.totalPoints),t.grid[t.pacman.x][t.pacman.y].intensity=0,t.pacman.points>=30&&R(t))},B=t=>{t.ghosts.forEach(((n,a)=>{if(n.scared){n.target||(n.target=$(n.x,n.y));const t=n.target.x-n.x,a=n.target.y-n.y,o=Math.abs(t)>Math.abs(a)?Math.sign(t):0,i=Math.abs(a)>=Math.abs(t)?Math.sign(a):0,s=n.x+o,c=n.y+i;s>=0&&s<7&&c>=0&&c<e&&(n.x=s,n.y=c),n.x===n.target.x&&n.y===n.target.y&&(n.target=$(n.x,n.y))}else{const a=[[-1,0],[1,0],[0,-1],[0,1]],[o,i]=a[Math.floor(Math.random()*a.length)];if(t.pacman.powerupRemainingDuration&&Math.random()<.5)return;const s=n.x+o,c=n.y+i;s>=0&&s<7&&c>=0&&c<e&&(n.x=s,n.y=c)}}))},$=(t,n)=>{const e=t+Math.floor(21*Math.random())-10,a=n+Math.floor(21*Math.random())-10;return{x:Math.max(0,Math.min(e,6)),y:Math.max(0,Math.min(a,51))}},E=t=>{t.pacman.deadRemainingDuration||t.ghosts.forEach(((n,e)=>{n.x===t.pacman.x&&n.y===t.pacman.y&&(t.pacman.powerupRemainingDuration&&n.scared?(O(t,e),t.pacman.points+=10,"canvas"==t.config.outputFormat&&d.getInstance().play(g.EAT_GHOST)):(t.pacman.points=0,t.pacman.powerupRemainingDuration=0,t.pacman.deadRemainingDuration=10,"canvas"==t.config.outputFormat&&d.getInstance().play(g.GAME_OVER).then((()=>d.getInstance().stopDefaultSound()))))}))},O=(t,n)=>{let a,o;do{a=Math.floor(7*Math.random()),o=Math.floor(Math.random()*e)}while(Math.abs(a-t.pacman.x)<=2&&Math.abs(o-t.pacman.y)<=2||0===t.grid[a][o].intensity);t.ghosts[n]={x:a,y:o,name:i[n%i.length],scared:!1,target:void 0}},R=t=>{t.pacman.powerupRemainingDuration=15,t.ghosts.forEach((t=>t.scared=!0))},T={frameCount:0,contributions:[],pacman:{x:0,y:0,direction:"right",points:0,totalPoints:0,deadRemainingDuration:0,powerupRemainingDuration:0},ghosts:[],grid:[],monthLabels:[],pacmanMouthOpen:!0,gameInterval:0,scaredGhostsDestinations:[],gameHistory:[],config:void 0};class P{constructor(t){this.store=Object.assign({},T),this.conf=Object.assign({},t)}start(){return t=this,n=void 0,o=function*(){switch(this.store.config=Object.assign(Object.assign({},{platform:"github",username:"",canvas:void 0,outputFormat:"svg",svgCallback:t=>{},gameOverCallback:()=>()=>{},gameTheme:"github",gameSpeed:1,enableSounds:!0,pointsIncreasedCallback:t=>{}}),this.conf),this.conf.platform){case"gitlab":this.store.contributions=yield l(this.store);break;case"github":this.store.contributions=yield h(this.store)}var t;t=this.store,S(void 0,void 0,void 0,(function*(){"canvas"==t.config.outputFormat&&(t.config.canvas=t.config.canvas,(t=>{t.config.canvas.width=1144,t.config.canvas.height=174})(t),x(t)),t.frameCount=0,t.ghosts.forEach((t=>t.scared=!1)),(t=>{t.pacman.points=0,t.pacman.totalPoints=0,t.grid=Array.from({length:7},(()=>Array.from({length:e},(()=>({commitsCount:0,intensity:0}))))),t.monthLabels=Array(e).fill("");let n=1;const a=new Date,o=new Date(a);o.setDate(a.getDate()-a.getDay()),t.contributions.forEach((a=>{const i=new Date(a.date),s=i.getDay(),c=Math.floor((+o-+i)/6048e5);c>=0&&c<e&&s>=0&&s<7&&(t.grid[s][51-c]={commitsCount:a.count,intensity:0},a.count>n&&(n=a.count))}));for(let a=0;a<7;a++)for(let o=0;o<e;o++)t.grid[a][o].commitsCount>0&&(t.grid[a][o].intensity=t.grid[a][o].commitsCount/n);for(let n=0;n<e;n++){const e=51-n,a=new Date(o);a.setDate(a.getDate()-7*e),t.monthLabels[n]=s[a.getMonth()]}})(t),"canvas"==t.config.outputFormat&&y(t),"canvas"==t.config.outputFormat&&(t.config.enableSounds||d.getInstance().mute(),yield d.getInstance().preloadSounds(),d.getInstance().startDefaultSound(),yield d.getInstance().play(g.BEGINNING));const n=()=>t.grid.some((t=>t.some((t=>t.intensity>0))));if(n()&&((t=>{let n=[];for(let a=0;a<7;a++)for(let o=0;o<e;o++)t.grid[a][o].intensity>0&&n.push({x:a,y:o});if(n.length>0){const e=n[Math.floor(Math.random()*n.length)];t.pacman={x:e.x,y:e.y,direction:"right",points:0,totalPoints:0,deadRemainingDuration:0,powerupRemainingDuration:0}}"canvas"==t.config.outputFormat&&A(t)})(t),(t=>{t.ghosts=[],t.scaredGhostsDestinations=[];for(let n=0;n<4;n++){let a,o;do{a=Math.floor(7*Math.random()),o=Math.floor(Math.random()*e)}while(0===t.grid[a][o].intensity);t.ghosts.push({x:a,y:o,name:i[n],scared:!1,target:void 0}),t.scaredGhostsDestinations.push({x:0,y:0})}"canvas"==t.config.outputFormat&&v(t)})(t)),r.blinky.img.src=r.blinky.imgDate,r.clyde.img.src=r.clyde.imgDate,r.inky.img.src=r.inky.imgDate,r.pinky.img.src=r.pinky.imgDate,r.scared.img.src=r.scared.imgDate,"svg"==t.config.outputFormat){for(;n();)yield I(t);yield I(t)}else clearInterval(t.gameInterval),t.gameInterval=setInterval((()=>S(void 0,void 0,void 0,(function*(){return yield I(t)}))),250)}))},new((a=void 0)||(a=Promise))((function(e,i){function s(t){try{r(o.next(t))}catch(t){i(t)}}function c(t){try{r(o.throw(t))}catch(t){i(t)}}function r(t){var n;t.done?e(t.value):(n=t.value,n instanceof a?n:new a((function(t){t(n)}))).then(s,c)}r((o=o.apply(t,n||[])).next())}));var t,n,a,o}stop(){var t;t=this.store,S(void 0,void 0,void 0,(function*(){clearInterval(t.gameInterval)}))}}var F=n.C;export{F as PacmanRenderer};
|
|
1
|
+
var t={d:(n,e)=>{for(var a in e)t.o(e,a)&&!t.o(n,a)&&Object.defineProperty(n,a,{enumerable:!0,get:e[a]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n)},n={};t.d(n,{C:()=>P});const e=52,a="yellow",o="#80808064",i=["blinky","clyde","inky","pinky"],s=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],c={github:{textColor:"#586069",gridBackground:"#ffffff",contributionBoxColor:"#9be9a8",emptyContributionBoxColor:"#ebedf0"},"github-dark":{textColor:"#8b949e",gridBackground:"#0d1117",contributionBoxColor:"#26a641",emptyContributionBoxColor:"#161b22"},gitlab:{textColor:"#626167",gridBackground:"#ffffff",contributionBoxColor:"#7992f5",emptyContributionBoxColor:"#ececef"},"gitlab-dark":{textColor:"#999999",gridBackground:"#1f1f1f",contributionBoxColor:"#2e7db1",emptyContributionBoxColor:"#2d2d2d"}},r={blinky:{imgDate:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAfUlEQVQ4T+2TUQ7AIAhDy/0PzQIRAqxmLtnn/DJPWypBAVkKKOMCyOQN7IRElLrcnIrDLNK4wVtxNbkb6Hq+jOcSbim6QVzKEstkw92gxVeFrMpqokix4wA+NvCOnvfArvcEbHoe2G9QmmhDMUc65p3xYC6q3zQPxtdl3NgF5QpL/b/rs3IAAAAASUVORK5CYIIA",img:void 0},clyde:{imgDate:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAgUlEQVQ4T+2T0Q6AIAhFLx9sH1MfTIPCAeLKrcd8PHqP4JBQLN7BFacNlHkAs+AQcqIueBs2mVWjgtWwl4yCdrd/pHYLLlVEgR2yK0wy4SoI5TcGXU4wM+AEJQfwsUCuXngDOR4rqKbngf0C94gyFHmkbd4rbkxD/pv2jfR1Ky7sBNrzXbHpnBX+AAAAAElFTkSuQmCC",img:void 0},inky:{imgDate:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAg0lEQVQ4T+WTWxKAIAhFuQvK/a+jFoT5QAVxypn+6vMEx6sDIO/jk12OAMs1WDVOXV3UBW+bRVbTFMFu8yCZBExH/g26VHCXI0AJpKgdUCUrTlkwxE+FECdzS7HiJemXgvyeO29gE7jD8wDVFX4vSLNtR1q2z+OVlaZxTaXYrq7HbxYBS8VgMVrqzkEAAAAASUVORK5CYIIA",img:void 0},pinky:{imgDate:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAhklEQVQ4T+2T0Q2AIAwF281wC50Qt9DNagoptqVESfyUz4N3vJCCECxaD4o47gt6bsAo2IWUqAnehkUmbYpgNqwlvSCnur+dtnnAuYUVyCGJimTAi8DUzwmwOoGI7hYjDgAfC/jqiTfg47ZBND0P7BeoR+Sh8CMt8x5xYSWkv2nbcF834swuA/9u49Yy5bgAAAAASUVORK5CYIIA",img:void 0},scared:{imgDate:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAeUlEQVQ4T82TUQ6AMAhD7UX0/sdyF0GREVmDmTN+bH9r6Bs0A0t2VpFULwDrrfBkZFcA3YC3ZodViAFGzQHyP0B2w2NrB0/1AoDbHwLoQ5/nrw1OBuD5e/crbM9Aiz35njHWzpSB/m3+0r40mV41M8U19WJe3Uw/tQOKt08pUUbBEQAAAABJRU5ErkJgggAA",img:void 0}};var g,u=function(t,n,e,a){return new(e||(e=Promise))((function(o,i){function s(t){try{r(a.next(t))}catch(t){i(t)}}function c(t){try{r(a.throw(t))}catch(t){i(t)}}function r(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(s,c)}r((a=a.apply(t,n||[])).next())}))};!function(t){t.DEFAULT="https://cdn.jsdelivr.net/npm/pacman-contribution-graph/src/assets/sounds/pacman_chomp.wav",t.BEGINNING="https://cdn.jsdelivr.net/npm/pacman-contribution-graph/src/assets/sounds/pacman_beginning.wav",t.GAME_OVER="https://cdn.jsdelivr.net/npm/pacman-contribution-graph/src/assets/sounds/pacman_death.wav",t.EAT_GHOST="https://cdn.jsdelivr.net/npm/pacman-contribution-graph/src/assets/sounds/pacman_eatghost.wav"}(g||(g={}));class d{constructor(){this.sounds=new Map,this.currentSource=null,this.defaultSource=null,this.isMuted=!1,this.audioContext=new AudioContext}static getInstance(){return d.instance||(d.instance=new d),d.instance}preloadSounds(){return u(this,void 0,void 0,(function*(){for(const t of Object.values(g)){const n=yield fetch(t),e=yield n.arrayBuffer(),a=yield this.audioContext.decodeAudioData(e);this.sounds.set(t,a)}}))}play(t){return u(this,void 0,void 0,(function*(){if(this.isMuted)return;if(this.currentSource)try{this.currentSource.stop()}catch(t){}const n=this.sounds.get(t);if(n)return this.currentSource=this.audioContext.createBufferSource(),this.currentSource.buffer=n,this.currentSource.connect(this.audioContext.destination),this.isMuted||this.currentSource.start(),new Promise((t=>{this.currentSource.onended=()=>{this.currentSource=null,t()}}));console.error(`Sound ${t} not found`)}))}startDefaultSound(){if(this.defaultSource)try{this.defaultSource.stop()}catch(t){}const t=this.sounds.get(g.DEFAULT);t?(this.defaultSource=this.audioContext.createBufferSource(),this.defaultSource.buffer=t,this.defaultSource.loop=!0,this.defaultSource.connect(this.audioContext.destination),this.isMuted||this.defaultSource.start()):console.error("Default sound not found")}stopDefaultSound(){if(this.defaultSource){try{this.defaultSource.stop()}catch(t){}this.defaultSource=null}}mute(){this.isMuted=!0,this.currentSource&&this.currentSource.disconnect(),this.defaultSource&&this.defaultSource.disconnect()}unmute(){this.isMuted=!1,this.currentSource&&this.currentSource.connect(this.audioContext.destination),this.defaultSource&&this.defaultSource.connect(this.audioContext.destination)}}var m=function(t,n,e,a){return new(e||(e=Promise))((function(o,i){function s(t){try{r(a.next(t))}catch(t){i(t)}}function c(t){try{r(a.throw(t))}catch(t){i(t)}}function r(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(s,c)}r((a=a.apply(t,n||[])).next())}))};const l=t=>m(void 0,void 0,void 0,(function*(){const n=yield fetch(`https://v0-new-project-q1hhrdodoye-abozanona-gmailcoms-projects.vercel.app/api/contributions?username=${t.config.username}`),e=yield n.json();return Object.entries(e).map((([t,n])=>({date:new Date(t),count:Number(n)})))})),h=t=>m(void 0,void 0,void 0,(function*(){var n;const e=[];let a=!1,o=1;do{try{const i={};(null===(n=t.config.githubSettings)||void 0===n?void 0:n.accessToken)&&(i.Authorization="Bearer "+t.config.githubSettings.accessToken);const s=yield fetch(`https://api.github.com/search/commits?q=author:${t.config.username}&sort=author-date&order=desc&page=${o}&per_page=1000`,{headers:i}),c=yield s.json();a=0===c.items.length,e.push(...c.items),o++}catch(t){a=!0}}while(!a);return Array.from(e.reduce(((t,n)=>{const e=n.commit.committer.date.split("T")[0],a=new Date(e),o=(t.get(e)||{count:0}).count+1;return t.set(e,{date:a,count:o})}),new Map).values())})),f=t=>{var n;return null!==(n=c[t.config.gameTheme])&&void 0!==n?n:c.github},p=function(t,n){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${n})`},y=t=>{t.config.canvas.getContext("2d").fillStyle=f(t).gridBackground,t.config.canvas.getContext("2d").fillRect(0,0,t.config.canvas.width,t.config.canvas.height);for(let n=0;n<7;n++)for(let a=0;a<e;a++){const e=t.grid[n][a].intensity;if(e>0){const n=e<.2?.3:e,a=p(f(t).contributionBoxColor,n);t.config.canvas.getContext("2d").fillStyle=a}else t.config.canvas.getContext("2d").fillStyle=f(t).emptyContributionBoxColor;t.config.canvas.getContext("2d").beginPath(),t.config.canvas.getContext("2d").roundRect(22*a,22*n+15,20,20,5),t.config.canvas.getContext("2d").fill()}t.config.canvas.getContext("2d").fillStyle=f(t).textColor,t.config.canvas.getContext("2d").font="10px Arial",t.config.canvas.getContext("2d").textAlign="center";let n="";for(let a=0;a<e;a++)if(t.monthLabels[a]!==n){const e=22*a+10;t.config.canvas.getContext("2d").fillText(t.monthLabels[a],e,10),n=t.monthLabels[a]}},v=t=>{const n=22*t.pacman.y+10,e=22*t.pacman.x+10+15;t.pacman.deadRemainingDuration?t.config.canvas.getContext("2d").fillStyle=o:t.pacman.powerupRemainingDuration?t.config.canvas.getContext("2d").fillStyle="red":t.config.canvas.getContext("2d").fillStyle=a;const i=t.pacmanMouthOpen?.35*Math.PI:.1*Math.PI;let s,c;switch(t.pacman.direction){case"up":s=1.5*Math.PI+i,c=1.5*Math.PI-i;break;case"down":s=.5*Math.PI+i,c=.5*Math.PI-i;break;case"left":s=Math.PI+i,c=Math.PI-i;break;default:s=0+i,c=2*Math.PI-i}t.config.canvas.getContext("2d").beginPath(),t.config.canvas.getContext("2d").arc(n,e,10,s,c),t.config.canvas.getContext("2d").lineTo(n,e),t.config.canvas.getContext("2d").fill()},A=t=>{t.ghosts.forEach((n=>{const e=22*n.y,a=22*n.x+15,o=t.config.canvas.getContext("2d");n.scared?o.drawImage(r.scared.img,e,a,20,20):o.drawImage(r[n.name].img,e,a,20,20)}))},x=t=>{t.config.enableSounds&&t.config.canvas.addEventListener("click",(function(n){const e=t.config.canvas.getBoundingClientRect(),a=n.clientX-e.left,o=n.clientY-e.top,i=t.config.canvas.width-30-10;a>=i&&a<=i+this.width&&o>=10&&o<=10+this.height&&(d.getInstance().isMuted?d.getInstance().unmute():d.getInstance().mute())}))},b=t=>{const n=10,e=t,a=2*Math.PI-t;return`M 10,10\n L ${n+n*Math.cos(e)},${n+n*Math.sin(e)}\n A 10,10 0 1,1 ${n+n*Math.cos(a)},${n+n*Math.sin(a)}\n Z`},C=t=>t.gameHistory.map(((n,e)=>e/(t.gameHistory.length-1))).join(";"),w=(t,n,e)=>t.gameHistory.map((a=>{const o=a.grid[n][e];return o>0?M(t,o):f(t).emptyContributionBoxColor})).join(";"),M=(t,n)=>{const e=n<.2?.3:n;return p(f(t).contributionBoxColor,e)},D=t=>{let n='<svg width="1144" height="174" xmlns="http://www.w3.org/2000/svg">';n+="<desc>Generated with https://github.com/abozanona/pacman-contribution-graph</desc>",n+=`<rect width="100%" height="100%" fill="${f(t).gridBackground}"/>`,n+=`<defs>\n\t\t<symbol id="blinky" viewBox="0 0 100 100">\n <image href="${r.blinky.imgDate}" width="100" height="100"/>\n\t\t</symbol>\n\t\t<symbol id="clyde" viewBox="0 0 100 100">\n <image href="${r.clyde.imgDate}" width="100" height="100"/>\n\t\t</symbol>\n\t\t<symbol id="inky" viewBox="0 0 100 100">\n <image href="${r.inky.imgDate}" width="100" height="100"/>\n\t\t</symbol>\n\t\t<symbol id="pinky" viewBox="0 0 100 100">\n <image href="${r.pinky.imgDate}" width="100" height="100"/>\n\t\t</symbol>\n\t\t<symbol id="scared" viewBox="0 0 100 100">\n <image href="${r.scared.imgDate}" width="100" height="100"/>\n\t\t</symbol>\n\t</defs>`;let i="";for(let a=0;a<e;a++)t.monthLabels[a]!==i&&(n+=`<text x="${22*a+10}" y="10" text-anchor="middle" font-size="10" fill="${f(t).textColor}">${t.monthLabels[a]}</text>`,i=t.monthLabels[a]);for(let a=0;a<7;a++)for(let o=0;o<e;o++){const e=22*o,i=22*a+15,s=t.gameHistory[0].grid[a][o],c=s>0?M(t,s):f(t).emptyContributionBoxColor;n+=`<rect id="cell-${a}-${o}" x="${e}" y="${i}" width="20" height="20" rx="5" fill="${c}">\n <animate attributeName="fill" dur="${300*t.gameHistory.length}ms" repeatCount="indefinite" \n values="${w(t,a,o)}" \n keyTimes="${C(t)}"/>\n </rect>`}return n+=`<path id="pacman" d="${b(.35)}"\n transform="translate(${22*t.pacman.y}, ${22*t.pacman.x+15})">\n\t\t<animate attributeName="fill" dur="${300*t.gameHistory.length}ms" repeatCount="indefinite"\n keyTimes="${C(t)}"\n values="${(t=>t.gameHistory.map((t=>t.pacman.deadRemainingDuration?o:t.pacman.powerupRemainingDuration?"red":a)).join(";"))(t)}"/>\n <animateTransform attributeName="transform" type="translate" dur="${300*t.gameHistory.length}ms" repeatCount="indefinite"\n keyTimes="${C(t)}"\n values="${(t=>t.gameHistory.map((t=>`${22*t.pacman.y},${22*t.pacman.x+15}`)).join(";"))(t)}"/>\n <animate attributeName="d" dur="0.2s" repeatCount="indefinite"\n values="${b(.25)};${b(.05)};${b(.25)}"/>\n </path>`,t.ghosts.forEach(((e,a)=>{n+=`<use id="ghost${a}" width="20" height="20" href="#ghost-${e.name}">\n <animateTransform attributeName="transform" type="translate" dur="${300*t.gameHistory.length}ms" repeatCount="indefinite"\n keyTimes="${C(t)}"\n values="${((t,n)=>t.gameHistory.map((t=>{const e=t.ghosts[n];return`${22*e.y},${22*e.x+15}`})).join(";"))(t,a)}"/>\n <animate attributeName="href" dur="${300*t.gameHistory.length}ms" repeatCount="indefinite"\n keyTimes="${C(t)}"\n values="${((t,n)=>t.gameHistory.map((t=>{const e=t.ghosts[n];return e.scared?"#scared":"#"+e.name})).join(";"))(t,a)}"/>\n </use>`})),n+="</svg>",n};var S=function(t,n,e,a){return new(e||(e=Promise))((function(o,i){function s(t){try{r(a.next(t))}catch(t){i(t)}}function c(t){try{r(a.throw(t))}catch(t){i(t)}}function r(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(s,c)}r((a=a.apply(t,n||[])).next())}))};const I=t=>S(void 0,void 0,void 0,(function*(){if(t.frameCount++,t.frameCount%t.config.gameSpeed==0)if(t.pacman.deadRemainingDuration&&(t.pacman.deadRemainingDuration--,t.pacman.deadRemainingDuration||"canvas"==t.config.outputFormat&&d.getInstance().play(g.GAME_OVER).then((()=>d.getInstance().startDefaultSound()))),t.pacman.powerupRemainingDuration&&(t.pacman.powerupRemainingDuration--,t.pacman.powerupRemainingDuration||(t.ghosts.forEach((t=>t.scared=!1)),t.pacman.points=0)),t.grid.some((t=>t.some((t=>t.intensity>0)))))k(t),B(t),E(t),t.pacmanMouthOpen=!t.pacmanMouthOpen,t.gameHistory.push({pacman:Object.assign({},t.pacman),ghosts:t.ghosts.map((t=>Object.assign({},t))),grid:t.grid.map((t=>[...t.map((t=>t.intensity))]))}),"canvas"==t.config.outputFormat&&y(t),"canvas"==t.config.outputFormat&&v(t),"canvas"==t.config.outputFormat&&A(t),"canvas"==t.config.outputFormat&&(t=>{if(!t.config.enableSounds)return;const n=t.config.canvas.width-30-10;t.config.canvas.getContext("2d").fillStyle=`rgba(0, 0, 0, ${d.getInstance().isMuted?.3:.5})`,t.config.canvas.getContext("2d").beginPath(),t.config.canvas.getContext("2d").moveTo(n+10,20),t.config.canvas.getContext("2d").lineTo(n+20,15),t.config.canvas.getContext("2d").lineTo(n+20,35),t.config.canvas.getContext("2d").lineTo(n+10,30),t.config.canvas.getContext("2d").closePath(),t.config.canvas.getContext("2d").fill(),d.getInstance().isMuted?(t.config.canvas.getContext("2d").strokeStyle="rgba(255, 0, 0, 0.6)",t.config.canvas.getContext("2d").lineWidth=3,t.config.canvas.getContext("2d").beginPath(),t.config.canvas.getContext("2d").moveTo(n+25,15),t.config.canvas.getContext("2d").lineTo(n+5,35),t.config.canvas.getContext("2d").stroke()):(t.config.canvas.getContext("2d").strokeStyle="rgba(0, 0, 0, 0.4)",t.config.canvas.getContext("2d").lineWidth=2,t.config.canvas.getContext("2d").beginPath(),t.config.canvas.getContext("2d").arc(n+25,25,5,0,2*Math.PI),t.config.canvas.getContext("2d").stroke(),t.config.canvas.getContext("2d").beginPath(),t.config.canvas.getContext("2d").arc(n+25,25,8,0,2*Math.PI),t.config.canvas.getContext("2d").stroke())})(t);else{if("canvas"==t.config.outputFormat&&(clearInterval(t.gameInterval),"canvas"==t.config.outputFormat&&((t=>{t.config.canvas.getContext("2d").fillStyle=f(t).textColor,t.config.canvas.getContext("2d").font="20px Arial",t.config.canvas.getContext("2d").textAlign="center",t.config.canvas.getContext("2d").fillText("Game Over",t.config.canvas.width/2,t.config.canvas.height/2)})(t),d.getInstance().play(g.BEGINNING).then((()=>d.getInstance().stopDefaultSound())))),"svg"==t.config.outputFormat){const n=D(t);t.config.svgCallback(n)}t.config.gameOverCallback()}else t.gameHistory.push({pacman:Object.assign({},t.pacman),ghosts:t.ghosts.map((t=>Object.assign({},t))),grid:t.grid.map((t=>[...t.map((t=>t.intensity))]))})})),k=t=>{if(t.pacman.deadRemainingDuration)return;let n=[];if(t.pacman.powerupRemainingDuration)n=t.ghosts.map((t=>({x:t.x,y:t.y,distance:1/0})));else for(let a=0;a<7;a++)for(let o=0;o<e;o++)t.grid[a][o].intensity>0&&n.push({x:a,y:o,distance:1/0});if(0===n.length)return;const a=n.reduce(((n,e)=>{const a=Math.abs(e.x-t.pacman.x)+Math.abs(e.y-t.pacman.y);return a<n.distance?Object.assign(Object.assign({},e),{distance:a}):n}),{x:t.pacman.x,y:t.pacman.y,distance:1/0}),o=a.x-t.pacman.x,i=a.y-t.pacman.y;Math.abs(o)>Math.abs(i)?(t.pacman.x+=Math.sign(o),t.pacman.direction=o>0?"down":"up"):(t.pacman.y+=Math.sign(i),t.pacman.direction=i>0?"right":"left"),t.grid[t.pacman.x][t.pacman.y].intensity>0&&(t.pacman.totalPoints+=t.grid[t.pacman.x][t.pacman.y].commitsCount,t.pacman.points++,t.config.pointsIncreasedCallback(t.pacman.totalPoints),t.grid[t.pacman.x][t.pacman.y].intensity=0,t.pacman.points>=30&&R(t))},B=t=>{t.ghosts.forEach(((n,a)=>{if(n.scared){n.target||(n.target=$(n.x,n.y));const t=n.target.x-n.x,a=n.target.y-n.y,o=Math.abs(t)>Math.abs(a)?Math.sign(t):0,i=Math.abs(a)>=Math.abs(t)?Math.sign(a):0,s=n.x+o,c=n.y+i;s>=0&&s<7&&c>=0&&c<e&&(n.x=s,n.y=c),n.x===n.target.x&&n.y===n.target.y&&(n.target=$(n.x,n.y))}else{const a=[[-1,0],[1,0],[0,-1],[0,1]],[o,i]=a[Math.floor(Math.random()*a.length)];if(t.pacman.powerupRemainingDuration&&Math.random()<.5)return;const s=n.x+o,c=n.y+i;s>=0&&s<7&&c>=0&&c<e&&(n.x=s,n.y=c)}}))},$=(t,n)=>{const e=t+Math.floor(21*Math.random())-10,a=n+Math.floor(21*Math.random())-10;return{x:Math.max(0,Math.min(e,6)),y:Math.max(0,Math.min(a,51))}},E=t=>{t.pacman.deadRemainingDuration||t.ghosts.forEach(((n,e)=>{n.x===t.pacman.x&&n.y===t.pacman.y&&(t.pacman.powerupRemainingDuration&&n.scared?(O(t,e),t.pacman.points+=10,"canvas"==t.config.outputFormat&&d.getInstance().play(g.EAT_GHOST)):(t.pacman.points=0,t.pacman.powerupRemainingDuration=0,t.pacman.deadRemainingDuration=10,"canvas"==t.config.outputFormat&&d.getInstance().play(g.GAME_OVER).then((()=>d.getInstance().stopDefaultSound()))))}))},O=(t,n)=>{let a,o;do{a=Math.floor(7*Math.random()),o=Math.floor(Math.random()*e)}while(Math.abs(a-t.pacman.x)<=2&&Math.abs(o-t.pacman.y)<=2||0===t.grid[a][o].intensity);t.ghosts[n]={x:a,y:o,name:i[n%i.length],scared:!1,target:void 0}},R=t=>{t.pacman.powerupRemainingDuration=15,t.ghosts.forEach((t=>t.scared=!0))},T={frameCount:0,contributions:[],pacman:{x:0,y:0,direction:"right",points:0,totalPoints:0,deadRemainingDuration:0,powerupRemainingDuration:0},ghosts:[],grid:[],monthLabels:[],pacmanMouthOpen:!0,gameInterval:0,scaredGhostsDestinations:[],gameHistory:[],config:void 0};class P{constructor(t){this.store=Object.assign({},T),this.conf=Object.assign({},t)}start(){return t=this,n=void 0,o=function*(){switch(this.store.config=Object.assign(Object.assign({},{platform:"github",username:"",canvas:void 0,outputFormat:"svg",svgCallback:t=>{},gameOverCallback:()=>()=>{},gameTheme:"github",gameSpeed:1,enableSounds:!0,pointsIncreasedCallback:t=>{}}),this.conf),this.conf.platform){case"gitlab":this.store.contributions=yield l(this.store);break;case"github":this.store.contributions=yield h(this.store)}var t;t=this.store,S(void 0,void 0,void 0,(function*(){"canvas"==t.config.outputFormat&&(t.config.canvas=t.config.canvas,(t=>{t.config.canvas.width=1144,t.config.canvas.height=174})(t),x(t)),t.frameCount=0,t.ghosts.forEach((t=>t.scared=!1)),(t=>{t.pacman.points=0,t.pacman.totalPoints=0,t.grid=Array.from({length:7},(()=>Array.from({length:e},(()=>({commitsCount:0,intensity:0}))))),t.monthLabels=Array(e).fill("");let n=1;const a=new Date,o=new Date(a);o.setDate(a.getDate()-a.getDay()),t.contributions.forEach((a=>{const i=new Date(a.date),s=i.getDay(),c=Math.floor((+o-+i)/6048e5);c>=0&&c<e&&s>=0&&s<7&&(t.grid[s][51-c]={commitsCount:a.count,intensity:0},a.count>n&&(n=a.count))}));for(let a=0;a<7;a++)for(let o=0;o<e;o++)t.grid[a][o].commitsCount>0&&(t.grid[a][o].intensity=t.grid[a][o].commitsCount/n);for(let n=0;n<e;n++){const e=51-n,a=new Date(o);a.setDate(a.getDate()-7*e),t.monthLabels[n]=s[a.getMonth()]}})(t),"canvas"==t.config.outputFormat&&y(t),"canvas"==t.config.outputFormat&&(t.config.enableSounds||d.getInstance().mute(),yield d.getInstance().preloadSounds(),d.getInstance().startDefaultSound(),yield d.getInstance().play(g.BEGINNING));const n=()=>t.grid.some((t=>t.some((t=>t.intensity>0))));if(n()&&((t=>{let n=[];for(let a=0;a<7;a++)for(let o=0;o<e;o++)t.grid[a][o].intensity>0&&n.push({x:a,y:o});if(n.length>0){const e=n[Math.floor(Math.random()*n.length)];t.pacman={x:e.x,y:e.y,direction:"right",points:0,totalPoints:0,deadRemainingDuration:0,powerupRemainingDuration:0}}"canvas"==t.config.outputFormat&&v(t)})(t),(t=>{t.ghosts=[],t.scaredGhostsDestinations=[];for(let n=0;n<4;n++){let a,o;do{a=Math.floor(7*Math.random()),o=Math.floor(Math.random()*e)}while(0===t.grid[a][o].intensity);t.ghosts.push({x:a,y:o,name:i[n],scared:!1,target:void 0}),t.scaredGhostsDestinations.push({x:0,y:0})}"canvas"==t.config.outputFormat&&A(t)})(t)),"canvas"==t.config.outputFormat&&(r.blinky.img=new Image,r.clyde.img=new Image,r.inky.img=new Image,r.pinky.img=new Image,r.scared.img=new Image,r.blinky.img.src=r.blinky.imgDate,r.clyde.img.src=r.clyde.imgDate,r.inky.img.src=r.inky.imgDate,r.pinky.img.src=r.pinky.imgDate,r.scared.img.src=r.scared.imgDate),"svg"==t.config.outputFormat){for(;n();)yield I(t);yield I(t)}else clearInterval(t.gameInterval),t.gameInterval=setInterval((()=>S(void 0,void 0,void 0,(function*(){return yield I(t)}))),250)}))},new((a=void 0)||(a=Promise))((function(e,i){function s(t){try{r(o.next(t))}catch(t){i(t)}}function c(t){try{r(o.throw(t))}catch(t){i(t)}}function r(t){var n;t.done?e(t.value):(n=t.value,n instanceof a?n:new a((function(t){t(n)}))).then(s,c)}r((o=o.apply(t,n||[])).next())}));var t,n,a,o}stop(){var t;t=this.store,S(void 0,void 0,void 0,(function*(){clearInterval(t.gameInterval)}))}}var F=n.C;export{F as PacmanRenderer};
|