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