Riichi/build/dp1.js
2025-03-07 17:50:37 +01:00

1 line
No EOL
12 KiB
JavaScript

(()=>{"use strict";var t=function(){function t(t,e,n){this.family=t,this.value=e,this.red=n,this.loadded=!1,this.imgSrc="",this.imgFront=new Image,this.imgBack=new Image,this.img=new Image,this.setImgSrc()}return t.prototype.getFamily=function(){return this.family},t.prototype.getValue=function(){return this.value},t.prototype.isRed=function(){return this.red},t.prototype.drawTile=function(t,e,n,i){t.drawImage(this.imgFront,e,n,75*i,100*i),t.drawImage(this.img,e,n,75*i,100*i)},t.prototype.isLessThan=function(t){return this.family<t.family||this.family===t.family&&this.value<=t.value},t.prototype.cleanup=function(){this.imgFront.onload=null,this.imgFront.onerror=null,this.imgBack.onload=null,this.imgBack.onerror=null,this.img.onload=null,this.img.onerror=null},t.prototype.setImgSrc=function(){this.imgSrc="/img/Regular/",this.family<=3?(this.imgSrc+=["","Man","Pin","Sou"][this.family],this.imgSrc+=String(this.value),this.red&&(this.imgSrc+="-Dora"),this.imgSrc+=".svg"):4===this.family?this.imgSrc+=["","Ton","Nan","Shaa","Pei"][this.value]+".svg":5===this.family&&(this.imgSrc+=["","Chun","Hatsu","Haku"][this.value]+".svg")},t.prototype.preloadImg=function(){return t=this,e=void 0,i=function(){return function(t,e){var n,i,r,o={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return l.next=s(0),l.throw=s(1),l.return=s(2),"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function s(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;l&&(l=0,s[0]&&(o=0)),o;)try{if(n=1,i&&(r=2&s[0]?i.return:s[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,s[1])).done)return r;switch(i=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,i=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!((r=(r=o.trys).length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){o.label=s[1];break}if(6===s[0]&&o.label<r[1]){o.label=r[1],r=s;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(s);break}r[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],i=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}(this,(function(t){switch(t.label){case 0:return[4,Promise.all([this.loadImg(this.imgFront,"/img/Regular/Front.svg"),this.loadImg(this.imgBack,"/img/Regular/Back.svg"),this.loadImg(this.img,this.imgSrc)])];case 1:return t.sent(),[2]}}))},new((n=void 0)||(n=Promise))((function(r,o){function l(t){try{a(i.next(t))}catch(t){o(t)}}function s(t){try{a(i.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(l,s)}a((i=i.apply(t,e||[])).next())}));var t,e,n,i},t.prototype.loadImg=function(t,e){return new Promise((function(n,i){t.onload=function(){return n()},t.onerror=function(){return i()},t.src=e}))},t}(),e=function(){function e(e){void 0===e&&(e=""),this.tiles=[];for(var n=0;2*n+1<e.length;n++){var i=e.substring(2*n,2*(n+1));"m"===i[0]?this.tiles.push(new t(1,Number(i[1]),!1)):"p"===i[0]?this.tiles.push(new t(2,Number(i[1]),!1)):"s"===i[0]?this.tiles.push(new t(3,Number(i[1]),!1)):"w"===i[0]?this.tiles.push(new t(4,Number(i[1]),!1)):"d"===i[0]&&this.tiles.push(new t(5,Number(i[1]),!1))}}return e.prototype.push=function(t){this.tiles.push(t)},e.prototype.pop=function(){return this.tiles.pop()},e.prototype.sort=function(){for(var t,e=0;e<this.tiles.length;e++)for(var n=0;n<this.tiles.length-1;n++)this.tiles[n].isLessThan(this.tiles[n+1])||(t=[this.tiles[n+1],this.tiles[n]],this.tiles[n]=t[0],this.tiles[n+1]=t[1])},e.prototype.drawHand=function(t,e,n,i,r,o){void 0===o&&(o=void 0);for(var l=0;l<this.tiles.length;l++)l===o?this.tiles[l].drawTile(t,e+75*l*r+l*i*r,n-25*r,r):this.tiles[l].drawTile(t,e+75*l*r+l*i*r,n,r)},e.prototype.preload=function(){return t=this,e=void 0,i=function(){var t;return function(t,e){var n,i,r,o={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return l.next=s(0),l.throw=s(1),l.return=s(2),"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function s(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;l&&(l=0,s[0]&&(o=0)),o;)try{if(n=1,i&&(r=2&s[0]?i.return:s[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,s[1])).done)return r;switch(i=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,i=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!((r=(r=o.trys).length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){o.label=s[1];break}if(6===s[0]&&o.label<r[1]){o.label=r[1],r=s;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(s);break}r[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],i=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}(this,(function(e){switch(e.label){case 0:t=0,e.label=1;case 1:return t<this.tiles.length?[4,this.tiles[t].preloadImg()]:[3,4];case 2:e.sent(),e.label=3;case 3:return t++,[3,1];case 4:return[2]}}))},new((n=void 0)||(n=Promise))((function(r,o){function l(t){try{a(i.next(t))}catch(t){o(t)}}function s(t){try{a(i.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(l,s)}a((i=i.apply(t,e||[])).next())}));var t,e,n,i},e.prototype.cleanup=function(){this.tiles.forEach((function(t){return t.cleanup()})),this.tiles=[]},e}(),n=function(){function n(t){this.tiles=[],this.initTiles(t)}return n.prototype.displayFamilies=function(t,e,n,i,r,o){void 0===r&&(r=0),void 0===o&&(o=0);for(var l=e,s=n,a=1;a<6;a++)if(a<4){for(var u=1;u<10;u++)this.find(a,u).drawTile(t,l,s,i),l+=(75+r)*i;l=e,s+=(100+o)*i}else if(4===a){for(u=1;u<5;u++)this.find(a,u).drawTile(t,l,s,i),l+=(75+r)*i;l=e,s+=(100+o)*i}else if(5===a)for(u=1;u<4;u++)this.find(a,u).drawTile(t,l,s,i),l+=(75+r)*i},n.prototype.pop=function(){return this.tiles.length,this.tiles.pop()},n.prototype.find=function(t,e){for(var n,i=void 0,r=0;r<this.tiles.length;r++)this.tiles[r].getFamily()===t&&this.tiles[r].getValue()===e&&(i=r);return void 0!==i?(n=[this.tiles[0],this.tiles[i]],this.tiles[i]=n[0],this.tiles[0]=n[1],this.tiles.shift()):void 0},n.prototype.count=function(t,e){for(var n=0,i=0;i<this.tiles.length;i++)this.tiles[i].getFamily()===t&&this.tiles[i].getValue()===e&&n++;return n},n.prototype.shuffle=function(){for(var t,e=[];this.tiles.length>0;){var n=Math.floor(Math.random()*this.tiles.length);t=[this.tiles[0],this.tiles[n]],this.tiles[n]=t[0],this.tiles[0]=t[1],e.push(this.tiles.shift())}this.tiles=e},n.prototype.getRandomHand=function(){var t=new e;this.shuffle();for(var n=0;n<13;n++)t.push(this.pop());return t},n.prototype.cleanup=function(){this.tiles.forEach((function(t){return t.cleanup()})),this.tiles=[]},n.prototype.preload=function(){return t=this,e=void 0,i=function(){var t;return function(t,e){var n,i,r,o={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return l.next=s(0),l.throw=s(1),l.return=s(2),"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function s(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;l&&(l=0,s[0]&&(o=0)),o;)try{if(n=1,i&&(r=2&s[0]?i.return:s[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,s[1])).done)return r;switch(i=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,i=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!((r=(r=o.trys).length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){o.label=s[1];break}if(6===s[0]&&o.label<r[1]){o.label=r[1],r=s;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(s);break}r[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],i=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}(this,(function(e){switch(e.label){case 0:t=0,e.label=1;case 1:return t<this.tiles.length?[4,this.tiles[t].preloadImg()]:[3,4];case 2:e.sent(),e.label=3;case 3:return t++,[3,1];case 4:return[2]}}))},new((n=void 0)||(n=Promise))((function(r,o){function l(t){try{a(i.next(t))}catch(t){o(t)}}function s(t){try{a(i.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(l,s)}a((i=i.apply(t,e||[])).next())}));var t,e,n,i},n.prototype.initTiles=function(e){for(var n=1;n<6;n++)if(n<4)for(var i=1;i<10;i++)this.tiles.push(new t(n,i,!1)),this.tiles.push(new t(n,i,!1)),this.tiles.push(new t(n,i,!1)),5===i&&e?this.tiles.push(new t(n,i,!0)):this.tiles.push(new t(n,i,!1));else if(4===n)for(i=1;i<5;i++)for(var r=0;r<4;r++)this.tiles.push(new t(n,i,!1));else if(5===n)for(i=1;i<4;i++)for(r=0;r<4;r++)this.tiles.push(new t(n,i,!1))},n}(),i=function(t,e,n,i){return new(n||(n=Promise))((function(r,o){function l(t){try{a(i.next(t))}catch(t){o(t)}}function s(t){try{a(i.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(l,s)}a((i=i.apply(t,e||[])).next())}))},r=function(t,e){var n,i,r,o={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return l.next=s(0),l.throw=s(1),l.return=s(2),"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function s(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;l&&(l=0,s[0]&&(o=0)),o;)try{if(n=1,i&&(r=2&s[0]?i.return:s[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,s[1])).done)return r;switch(i=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,i=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!((r=(r=o.trys).length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){o.label=s[1];break}if(6===s[0]&&o.label<r[1]){o.label=r[1],r=s;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(s);break}r[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],i=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}};function o(t){return i(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,t.preload()];case 1:return e.sent(),[2]}}))}))}!function(){i(this,void 0,void 0,(function(){var t,e,i,l,s,a,u,c,f,h,p,y;return r(this,(function(r){switch(r.label){case 0:return(t=document.getElementById("myCanvas"))?(e=t.getContext("2d"))?(e.fillStyle="#007730",e.fillRect(50,50,1e3,1e3),i=180,l=80,s=.75,a=50,u=100,[4,o(c=new n(!1))]):[3,2]:[3,4];case 1:for(r.sent(),c.displayFamilies(e,i,l,s,a,u),e.fillStyle="#DFDFFF",e.font="30px serif",f=50*s,h=30*s,e.fillText("Caractère:",55,l+f+h),e.fillText("Rond:",55,l+3*f+u*s+h),e.fillText("Bambou:",55,l+5*f+2*u*s+h),e.fillText("Vent:",55,l+7*f+3*u*s+h),e.fillText("Dragon:",55,l+9*f+4*u*s+h),p=0;p<3;p++)for(y=0;y<9;y++)e.fillText(String(y+1),i+y*(a+75)*s+30*s,l+p*(u+100)*s+150*s);return e.fillText("Est",i+0*(a+75)*s,l+3*(u+100)*s+150*s),e.fillText("Sud",i+1*(a+75)*s,l+3*(u+100)*s+150*s),e.fillText("Ouest",i+2*(a+75)*s,l+3*(u+100)*s+150*s),e.fillText("Nord",i+3*(a+75)*s,l+3*(u+100)*s+150*s),e.fillText("Rouge",i+0*(a+75)*s,l+4*(u+100)*s+150*s),e.fillText("Vert",i+1*(a+75)*s,l+4*(u+100)*s+150*s),e.fillText("Blanc",i+2*(a+75)*s,l+4*(u+100)*s+150*s),window.cleanup=function(){c.cleanup()},[3,3];case 2:console.error("Impossible d'obtenir le contexte du canvas."),r.label=3;case 3:return[3,5];case 4:console.error("Canvas introuvable dans le DOM."),r.label=5;case 5:return[2]}}))}))}()})();