From 2991e96a54e24804f4d5cf74291741a86f9c9f87 Mon Sep 17 00:00:00 2001 From: Didictateur Date: Sun, 13 Apr 2025 15:27:45 +0200 Subject: [PATCH] fixe all offset --- build/dp2.js | 2 +- build/dp3.js | 2 +- src/display/dp2.ts | 4 ++-- src/display/dp3.ts | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build/dp2.js b/build/dp2.js index 33ba4fb..a859f8a 100644 --- a/build/dp2.js +++ b/build/dp2.js @@ -1 +1 @@ -(()=>{"use strict";class t{constructor(t,i,e){this.family=t,this.value=i,this.red=e,this.imgFront=new Image,this.imgBack=new Image,this.imgGray=new Image,this.img=new Image,this.imgSrc="",this.tilt=0,this.setImgSrc()}getFamily(){return this.family}getValue(){return this.value}isEqual(t,i){return this.family===t&&this.value===i}isRed(){return this.red}compare(t){return this.family!==t.family?this.family{t.onload=null,t.onerror=null}))}preloadImg(){return t=this,i=void 0,s=function*(){const t=[{img:this.imgFront,src:"img/Regular/Front.svg"},{img:this.imgBack,src:"img/Regular/Back.svg"},{img:this.imgGray,src:"img/Regular/Gray.svg"},{img:this.img,src:this.imgSrc}];yield Promise.all(t.map((({img:t,src:i})=>this.loadImg(t,i))))},new((e=void 0)||(e=Promise))((function(n,h){function l(t){try{r(s.next(t))}catch(t){h(t)}}function a(t){try{r(s.throw(t))}catch(t){h(t)}}function r(t){var i;t.done?n(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(l,a)}r((s=s.apply(t,i||[])).next())}));var t,i,e,s}loadImg(t,i){return new Promise(((e,s)=>{t.onload=()=>e(),t.onerror=()=>s(),t.src=i}))}setImgSrc(){if(this.imgSrc="img/Regular/",this.family<=3){const t=["","Man","Pin","Sou"];this.imgSrc+=t[this.family]+String(this.value),this.red&&(this.imgSrc+="-Dora")}else if(4===this.family){const t=["","Ton","Nan","Shaa","Pei"];this.imgSrc+=t[this.value]}else if(5===this.family){const t=["","Chun","Hatsu","Haku"];this.imgSrc+=t[this.value]}this.imgSrc+=".svg"}}class i{constructor(t,i,e){this.tiles=t,this.stolenFrom=i,this.belongsTo=e}push(t){this.tiles.push(t)}pop(){return this.tiles.pop()}getTiles(){return this.tiles}compare(t){const i=this.tiles[0].compare(t.tiles[0]);return 0!==i?i:this.tiles[1].compare(t.tiles[1])}drawGroup(t,i,e,s,n,h,l){t.save(),t.translate(525,525),t.rotate(h),t.translate(-525,-525);const a=75*n,r=90*n,o=25*n/2,c=(this.belongsTo-this.stolenFrom-1+4)%4,d=void 0===l?-1:l.getFamily(),u=void 0===l?0:l.getValue(),f=(i,e,s,h)=>{i.drawTile(t,e,s,n,!1,h,i.isEqual(d,u))},m=Math.PI/2;switch(c){case 0:f(this.tiles[0],i,e+o,m),f(this.tiles[1],i+r,e,0),f(this.tiles[2],i+r+a+s*n,e,0);break;case 1:f(this.tiles[0],i,e,0),f(this.tiles[1],i+r,e+o,-m),f(this.tiles[2],i+r+a+3*s*n,e,0);break;case 2:f(this.tiles[0],i,e,0),f(this.tiles[1],i+a+s*n,e,0),f(this.tiles[2],i+r+a+s*n,e+o,-m);break;default:console.error(`Position non prise en charge: ${c}`)}t.restore()}}const e="m",s=1,n="p",h=2,l="s",a=3,r="w",o=4,c="d",d=5;class u{constructor(t=""){this.isolate=!1,this.tiles=[],this.initializeFromString(t)}initializeFromString(t){for(let i=0;ie.getFamily()===t&&e.getValue()===i))}eject(t){if(t<0||t>=this.tiles.length)throw new Error("Invalid tile index");[this.tiles[0],this.tiles[t]]=[this.tiles[t],this.tiles[0]];const i=this.tiles.shift();return this.sort(),i}get(t){if(!(void 0===t||t<0||t>=this.tiles.length))return this.tiles[t]}sort(){this.tiles.sort(((t,i)=>t.isLessThan(i)?-1:1))}count(t,i){return this.tiles.filter((e=>e.getFamily()===t&&e.getValue()===i)).length}toGroup(t=!1){if(0===this.tiles.length)return[];const i=this.tiles.pop(),e=i.getFamily(),s=i.getValue();if(this.count(e,s)>=1&&!t){const t=this.tryFormPair(i);if(t)return t}if(this.count(e,s)>=2){const e=this.tryFormTriplet(i,t);if(e)return e}const n=this.count(e,s-1)>0,h=this.count(e,s-2)>0;if(n&&h){const e=this.tryFormSequence(i,t);if(e)return e}this.tiles.push(i),this.sort()}tryFormPair(t){const e=this.find(t.getFamily(),t.getValue()),s=this.toGroup(!0);if(this.tiles.push(e),this.sort(),void 0!==s)return this.tiles.push(t),this.sort(),s.push(new i([t,e],0,0)),s}tryFormTriplet(t,e){const s=this.find(t.getFamily(),t.getValue()),n=this.find(t.getFamily(),t.getValue()),h=this.toGroup(e);if(this.tiles.push(s),this.tiles.push(n),this.sort(),void 0!==h)return h.push(new i([t,s,n],0,0)),this.tiles.push(t),this.sort(),h}tryFormSequence(t,e){const s=this.find(t.getFamily(),t.getValue()-1),n=this.find(t.getFamily(),t.getValue()-2),h=this.toGroup(e);if(this.tiles.push(s),this.tiles.push(n),this.sort(),void 0!==h)return h.push(new i([n,s,t],0,0)),this.tiles.push(t),this.sort(),h}drawHand(t,i,e,s,n,h=void 0,l=!1,a=0){const r=(75+s)*n,o=Math.cos(a)*r,c=Math.sin(a)*r;for(let s=0;st.preloadImg())))},new((e=void 0)||(e=Promise))((function(n,h){function l(t){try{r(s.next(t))}catch(t){h(t)}}function a(t){try{r(s.throw(t))}catch(t){h(t)}}function r(t){var i;t.done?n(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(l,a)}r((s=s.apply(t,i||[])).next())}));var t,i,e,s}cleanup(){this.tiles.forEach((t=>t.cleanup())),this.tiles=[]}}class f{constructor(t=!1){this.tiles=[],this.tileIndexMap=new Map,this.initTiles(t)}displayFamilies(t,i,e,s,n=0,h=0){let l=i,a=e;const r=[{family:1,start:1,end:9},{family:2,start:1,end:9},{family:3,start:1,end:9},{family:4,start:1,end:4},{family:5,start:1,end:3}];for(const e of r){for(let i=e.start;i<=e.end;i++){const h=this.find(e.family,i);h&&(h.drawTile(t,l,a,s,!1,0,!1),l+=(75+n)*s)}l=i,a+=(100+h)*s}}length(){return this.tiles.length}pop(){if(0===this.tiles.length)throw new Error("Cannot pop from an empty deck");const t=this.tiles.pop(),i=this.getTileKey(t.getFamily(),t.getValue()),e=this.tileIndexMap.get(i);return e&&e.length>0&&(e.pop(),0===e.length?this.tileIndexMap.delete(i):this.tileIndexMap.set(i,e)),t}push(t){const i=this.tiles.length;this.tiles.push(t);const e=this.getTileKey(t.getFamily(),t.getValue()),s=this.tileIndexMap.get(e)||[];s.push(i),this.tileIndexMap.set(e,s)}find(t,i){const e=this.getTileKey(t,i),s=this.tileIndexMap.get(e);if(!s||0===s.length)return;const n=s[0];if(n>=this.tiles.length)return this.rebuildIndexMap(),this.find(t,i);[this.tiles[n],this.tiles[0]]=[this.tiles[0],this.tiles[n]],this.updateIndicesAfterSwap(0,n);const h=this.tiles.shift();return this.decrementIndicesAfterShift(),h}count(t,i){const e=this.getTileKey(t,i),s=this.tileIndexMap.get(e);return s?s.length:0}shuffle(){for(let t=this.tiles.length-1;t>0;t--){const i=Math.floor(Math.random()*(t+1));[this.tiles[t],this.tiles[i]]=[this.tiles[i],this.tiles[t]]}this.rebuildIndexMap()}getRandomHand(){const t=new u;if(this.shuffle(),this.tiles.length<13)throw new Error("Not enough tiles in deck to create a hand");for(let i=0;i<13;i++)t.push(this.pop());return t}cleanup(){this.tiles.forEach((t=>t.cleanup())),this.tiles=[],this.tileIndexMap.clear()}preload(){return t=this,i=void 0,s=function*(){const t=this.tiles.map((t=>t.preloadImg()));yield Promise.all(t)},new((e=void 0)||(e=Promise))((function(n,h){function l(t){try{r(s.next(t))}catch(t){h(t)}}function a(t){try{r(s.throw(t))}catch(t){h(t)}}function r(t){var i;t.done?n(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(l,a)}r((s=s.apply(t,i||[])).next())}));var t,i,e,s}getTileKey(t,i){return`${t}-${i}`}updateIndicesAfterSwap(t,i){if(t===i)return;const e=this.tiles[t],s=this.tiles[i],n=this.getTileKey(e.getFamily(),e.getValue()),h=this.getTileKey(s.getFamily(),s.getValue()),l=this.tileIndexMap.get(n)||[],a=this.tileIndexMap.get(h)||[],r=l.indexOf(i),o=a.indexOf(t);-1!==r&&(l[r]=t),-1!==o&&(a[o]=i),this.tileIndexMap.set(n,l),this.tileIndexMap.set(h,a)}decrementIndicesAfterShift(){var t;for(const[i,e]of this.tileIndexMap.entries())this.tileIndexMap.set(i,e.filter((t=>0!==t)).map((t=>t>0?t-1:t))),0===(null===(t=this.tileIndexMap.get(i))||void 0===t?void 0:t.length)&&this.tileIndexMap.delete(i)}rebuildIndexMap(){this.tileIndexMap.clear();for(let t=0;t=i.x&&e<=i.x+i.width&&s>=i.y&&s<=i.y+i.height){this.selectedTile=t;break}}n!==this.selectedTile&&(this.isDirty=!0)}handleMouseDown(){void 0!==this.selectedTile&&(this.edeck.push(this.ehand.eject(this.selectedTile)),this.edeck.shuffle(),this.ehand.sort(),this.ehand.push(this.edeck.pop()),this.isDirty=!0)}initialize(){return t=this,i=void 0,s=function*(){yield Promise.all([this.deck.preload(),this.edeck.preload()]);for(let t=0;t<4;t++){const t=this.deck.getRandomHand();t.sort(),this.hands.push(t)}this.ehand=this.edeck.getRandomHand(),this.ehand.push(this.edeck.pop()),this.ehand.sort(),this.drawCanvas(),this.startAnimationLoop()},new((e=void 0)||(e=Promise))((function(n,h){function l(t){try{r(s.next(t))}catch(t){h(t)}}function a(t){try{r(s.throw(t))}catch(t){h(t)}}function r(t){var i;t.done?n(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(l,a)}r((s=s.apply(t,i||[])).next())}));var t,i,e,s}drawCanvas(){if(!this.isDirty)return;const t=this.offScreenCtx;t.clearRect(0,0,this.offScreenCanvas.width,this.offScreenCanvas.height),t.fillStyle="#007730",t.fillRect(50,50,1e3,1e3),t.fillStyle="#DFDFFF",t.font="50px serif",t.fillText("Exemples de main:",65,100);for(let i=0;i{const s=e-t;s>=this.INTERVAL&&(t=e-s%this.INTERVAL,this.drawCanvas()),this.animationFrameId=requestAnimationFrame(i)};this.animationFrameId=requestAnimationFrame(i)}cleanup(){null!==this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.deck.cleanup(),this.hands.forEach((t=>t.cleanup())),this.hands=[],this.edeck.cleanup(),this.ehand.cleanup(),this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.offScreenCtx.clearRect(0,0,this.offScreenCanvas.width,this.offScreenCanvas.height),this.selectedTile=void 0,this.isDirty=!0}};m.initialize().catch((t=>{console.error("Erreur lors de l'initialisation:",t)})),window.cleanup=()=>{m.cleanup()}})(); \ No newline at end of file +(()=>{"use strict";class t{constructor(t,i,e){this.family=t,this.value=i,this.red=e,this.imgFront=new Image,this.imgBack=new Image,this.imgGray=new Image,this.img=new Image,this.imgSrc="",this.tilt=0,this.setImgSrc()}getFamily(){return this.family}getValue(){return this.value}isEqual(t,i){return this.family===t&&this.value===i}isRed(){return this.red}compare(t){return this.family!==t.family?this.family{t.onload=null,t.onerror=null}))}preloadImg(){return t=this,i=void 0,s=function*(){const t=[{img:this.imgFront,src:"img/Regular/Front.svg"},{img:this.imgBack,src:"img/Regular/Back.svg"},{img:this.imgGray,src:"img/Regular/Gray.svg"},{img:this.img,src:this.imgSrc}];yield Promise.all(t.map((({img:t,src:i})=>this.loadImg(t,i))))},new((e=void 0)||(e=Promise))((function(n,h){function l(t){try{r(s.next(t))}catch(t){h(t)}}function a(t){try{r(s.throw(t))}catch(t){h(t)}}function r(t){var i;t.done?n(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(l,a)}r((s=s.apply(t,i||[])).next())}));var t,i,e,s}loadImg(t,i){return new Promise(((e,s)=>{t.onload=()=>e(),t.onerror=()=>s(),t.src=i}))}setImgSrc(){if(this.imgSrc="img/Regular/",this.family<=3){const t=["","Man","Pin","Sou"];this.imgSrc+=t[this.family]+String(this.value),this.red&&(this.imgSrc+="-Dora")}else if(4===this.family){const t=["","Ton","Nan","Shaa","Pei"];this.imgSrc+=t[this.value]}else if(5===this.family){const t=["","Chun","Hatsu","Haku"];this.imgSrc+=t[this.value]}this.imgSrc+=".svg"}}class i{constructor(t,i,e){this.tiles=t,this.stolenFrom=i,this.belongsTo=e}push(t){this.tiles.push(t)}pop(){return this.tiles.pop()}getTiles(){return this.tiles}compare(t){const i=this.tiles[0].compare(t.tiles[0]);return 0!==i?i:this.tiles[1].compare(t.tiles[1])}drawGroup(t,i,e,s,n,h,l){t.save(),t.translate(525,525),t.rotate(h),t.translate(-525,-525);const a=75*n,r=90*n,o=25*n/2,c=(this.belongsTo-this.stolenFrom-1+4)%4,d=void 0===l?-1:l.getFamily(),u=void 0===l?0:l.getValue(),f=(i,e,s,h)=>{i.drawTile(t,e,s,n,!1,h,i.isEqual(d,u))},m=Math.PI/2;switch(c){case 0:f(this.tiles[0],i,e+o,m),f(this.tiles[1],i+r,e,0),f(this.tiles[2],i+r+a+s*n,e,0);break;case 1:f(this.tiles[0],i,e,0),f(this.tiles[1],i+r,e+o,-m),f(this.tiles[2],i+r+a+3*s*n,e,0);break;case 2:f(this.tiles[0],i,e,0),f(this.tiles[1],i+a+s*n,e,0),f(this.tiles[2],i+r+a+s*n,e+o,-m);break;default:console.error(`Position non prise en charge: ${c}`)}t.restore()}}const e="m",s=1,n="p",h=2,l="s",a=3,r="w",o=4,c="d",d=5;class u{constructor(t=""){this.isolate=!1,this.tiles=[],this.initializeFromString(t)}initializeFromString(t){for(let i=0;ie.getFamily()===t&&e.getValue()===i))}eject(t){if(t<0||t>=this.tiles.length)throw new Error("Invalid tile index");[this.tiles[0],this.tiles[t]]=[this.tiles[t],this.tiles[0]];const i=this.tiles.shift();return this.sort(),i}get(t){if(!(void 0===t||t<0||t>=this.tiles.length))return this.tiles[t]}sort(){this.tiles.sort(((t,i)=>t.isLessThan(i)?-1:1))}count(t,i){return this.tiles.filter((e=>e.getFamily()===t&&e.getValue()===i)).length}toGroup(t=!1){if(0===this.tiles.length)return[];const i=this.tiles.pop(),e=i.getFamily(),s=i.getValue();if(this.count(e,s)>=1&&!t){const t=this.tryFormPair(i);if(t)return t}if(this.count(e,s)>=2){const e=this.tryFormTriplet(i,t);if(e)return e}const n=this.count(e,s-1)>0,h=this.count(e,s-2)>0;if(n&&h){const e=this.tryFormSequence(i,t);if(e)return e}this.tiles.push(i),this.sort()}tryFormPair(t){const e=this.find(t.getFamily(),t.getValue()),s=this.toGroup(!0);if(this.tiles.push(e),this.sort(),void 0!==s)return this.tiles.push(t),this.sort(),s.push(new i([t,e],0,0)),s}tryFormTriplet(t,e){const s=this.find(t.getFamily(),t.getValue()),n=this.find(t.getFamily(),t.getValue()),h=this.toGroup(e);if(this.tiles.push(s),this.tiles.push(n),this.sort(),void 0!==h)return h.push(new i([t,s,n],0,0)),this.tiles.push(t),this.sort(),h}tryFormSequence(t,e){const s=this.find(t.getFamily(),t.getValue()-1),n=this.find(t.getFamily(),t.getValue()-2),h=this.toGroup(e);if(this.tiles.push(s),this.tiles.push(n),this.sort(),void 0!==h)return h.push(new i([n,s,t],0,0)),this.tiles.push(t),this.sort(),h}drawHand(t,i,e,s,n,h=void 0,l=!1,a=0){const r=(75+s)*n,o=Math.cos(a)*r,c=Math.sin(a)*r;for(let s=0;st.preloadImg())))},new((e=void 0)||(e=Promise))((function(n,h){function l(t){try{r(s.next(t))}catch(t){h(t)}}function a(t){try{r(s.throw(t))}catch(t){h(t)}}function r(t){var i;t.done?n(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(l,a)}r((s=s.apply(t,i||[])).next())}));var t,i,e,s}cleanup(){this.tiles.forEach((t=>t.cleanup())),this.tiles=[]}}class f{constructor(t=!1){this.tiles=[],this.tileIndexMap=new Map,this.initTiles(t)}displayFamilies(t,i,e,s,n=0,h=0){let l=i,a=e;const r=[{family:1,start:1,end:9},{family:2,start:1,end:9},{family:3,start:1,end:9},{family:4,start:1,end:4},{family:5,start:1,end:3}];for(const e of r){for(let i=e.start;i<=e.end;i++){const h=this.find(e.family,i);h&&(h.drawTile(t,l,a,s,!1,0,!1),l+=(75+n)*s)}l=i,a+=(100+h)*s}}length(){return this.tiles.length}pop(){if(0===this.tiles.length)throw new Error("Cannot pop from an empty deck");const t=this.tiles.pop(),i=this.getTileKey(t.getFamily(),t.getValue()),e=this.tileIndexMap.get(i);return e&&e.length>0&&(e.pop(),0===e.length?this.tileIndexMap.delete(i):this.tileIndexMap.set(i,e)),t}push(t){const i=this.tiles.length;this.tiles.push(t);const e=this.getTileKey(t.getFamily(),t.getValue()),s=this.tileIndexMap.get(e)||[];s.push(i),this.tileIndexMap.set(e,s)}find(t,i){const e=this.getTileKey(t,i),s=this.tileIndexMap.get(e);if(!s||0===s.length)return;const n=s[0];if(n>=this.tiles.length)return this.rebuildIndexMap(),this.find(t,i);[this.tiles[n],this.tiles[0]]=[this.tiles[0],this.tiles[n]],this.updateIndicesAfterSwap(0,n);const h=this.tiles.shift();return this.decrementIndicesAfterShift(),h}count(t,i){const e=this.getTileKey(t,i),s=this.tileIndexMap.get(e);return s?s.length:0}shuffle(){for(let t=this.tiles.length-1;t>0;t--){const i=Math.floor(Math.random()*(t+1));[this.tiles[t],this.tiles[i]]=[this.tiles[i],this.tiles[t]]}this.rebuildIndexMap()}getRandomHand(){const t=new u;if(this.shuffle(),this.tiles.length<13)throw new Error("Not enough tiles in deck to create a hand");for(let i=0;i<13;i++)t.push(this.pop());return t}cleanup(){this.tiles.forEach((t=>t.cleanup())),this.tiles=[],this.tileIndexMap.clear()}preload(){return t=this,i=void 0,s=function*(){const t=this.tiles.map((t=>t.preloadImg()));yield Promise.all(t)},new((e=void 0)||(e=Promise))((function(n,h){function l(t){try{r(s.next(t))}catch(t){h(t)}}function a(t){try{r(s.throw(t))}catch(t){h(t)}}function r(t){var i;t.done?n(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(l,a)}r((s=s.apply(t,i||[])).next())}));var t,i,e,s}getTileKey(t,i){return`${t}-${i}`}updateIndicesAfterSwap(t,i){if(t===i)return;const e=this.tiles[t],s=this.tiles[i],n=this.getTileKey(e.getFamily(),e.getValue()),h=this.getTileKey(s.getFamily(),s.getValue()),l=this.tileIndexMap.get(n)||[],a=this.tileIndexMap.get(h)||[],r=l.indexOf(i),o=a.indexOf(t);-1!==r&&(l[r]=t),-1!==o&&(a[o]=i),this.tileIndexMap.set(n,l),this.tileIndexMap.set(h,a)}decrementIndicesAfterShift(){var t;for(const[i,e]of this.tileIndexMap.entries())this.tileIndexMap.set(i,e.filter((t=>0!==t)).map((t=>t>0?t-1:t))),0===(null===(t=this.tileIndexMap.get(i))||void 0===t?void 0:t.length)&&this.tileIndexMap.delete(i)}rebuildIndexMap(){this.tileIndexMap.clear();for(let t=0;t=i.x&&e<=i.x+i.width&&s>=i.y&&s<=i.y+i.height){this.selectedTile=t;break}}n!==this.selectedTile&&(this.isDirty=!0)}handleMouseDown(){void 0!==this.selectedTile&&(this.edeck.push(this.ehand.eject(this.selectedTile)),this.edeck.shuffle(),this.ehand.sort(),this.ehand.push(this.edeck.pop()),this.isDirty=!0)}initialize(){return t=this,i=void 0,s=function*(){yield Promise.all([this.deck.preload(),this.edeck.preload()]);for(let t=0;t<4;t++){const t=this.deck.getRandomHand();t.sort(),this.hands.push(t)}this.ehand=this.edeck.getRandomHand(),this.ehand.push(this.edeck.pop()),this.ehand.sort(),this.drawCanvas(),this.startAnimationLoop()},new((e=void 0)||(e=Promise))((function(n,h){function l(t){try{r(s.next(t))}catch(t){h(t)}}function a(t){try{r(s.throw(t))}catch(t){h(t)}}function r(t){var i;t.done?n(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(l,a)}r((s=s.apply(t,i||[])).next())}));var t,i,e,s}drawCanvas(){if(!this.isDirty)return;const t=this.offScreenCtx;t.clearRect(0,0,this.offScreenCanvas.width,this.offScreenCanvas.height),t.fillStyle="#007730",t.fillRect(50,50,1e3,1e3),t.fillStyle="#DFDFFF",t.font="50px serif",t.fillText("Exemples de main:",65,100);for(let i=0;i{const s=e-t;s>=this.INTERVAL&&(t=e-s%this.INTERVAL,this.drawCanvas()),this.animationFrameId=requestAnimationFrame(i)};this.animationFrameId=requestAnimationFrame(i)}cleanup(){null!==this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.deck.cleanup(),this.hands.forEach((t=>t.cleanup())),this.hands=[],this.edeck.cleanup(),this.ehand.cleanup(),this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.offScreenCtx.clearRect(0,0,this.offScreenCanvas.width,this.offScreenCanvas.height),this.selectedTile=void 0,this.isDirty=!0}};m.initialize().catch((t=>{console.error("Erreur lors de l'initialisation:",t)})),window.cleanup=()=>{m.cleanup()}})(); \ No newline at end of file diff --git a/build/dp3.js b/build/dp3.js index 8989019..a617009 100644 --- a/build/dp3.js +++ b/build/dp3.js @@ -1 +1 @@ -(()=>{"use strict";class t{constructor(t,i,s){this.family=t,this.value=i,this.red=s,this.imgFront=new Image,this.imgBack=new Image,this.imgGray=new Image,this.img=new Image,this.imgSrc="",this.tilt=0,this.setImgSrc()}getFamily(){return this.family}getValue(){return this.value}isEqual(t,i){return this.family===t&&this.value===i}isRed(){return this.red}compare(t){return this.family!==t.family?this.family{t.onload=null,t.onerror=null}))}preloadImg(){return t=this,i=void 0,e=function*(){const t=[{img:this.imgFront,src:"img/Regular/Front.svg"},{img:this.imgBack,src:"img/Regular/Back.svg"},{img:this.imgGray,src:"img/Regular/Gray.svg"},{img:this.img,src:this.imgSrc}];yield Promise.all(t.map((({img:t,src:i})=>this.loadImg(t,i))))},new((s=void 0)||(s=Promise))((function(h,n){function a(t){try{r(e.next(t))}catch(t){n(t)}}function l(t){try{r(e.throw(t))}catch(t){n(t)}}function r(t){var i;t.done?h(t.value):(i=t.value,i instanceof s?i:new s((function(t){t(i)}))).then(a,l)}r((e=e.apply(t,i||[])).next())}));var t,i,s,e}loadImg(t,i){return new Promise(((s,e)=>{t.onload=()=>s(),t.onerror=()=>e(),t.src=i}))}setImgSrc(){if(this.imgSrc="img/Regular/",this.family<=3){const t=["","Man","Pin","Sou"];this.imgSrc+=t[this.family]+String(this.value),this.red&&(this.imgSrc+="-Dora")}else if(4===this.family){const t=["","Ton","Nan","Shaa","Pei"];this.imgSrc+=t[this.value]}else if(5===this.family){const t=["","Chun","Hatsu","Haku"];this.imgSrc+=t[this.value]}this.imgSrc+=".svg"}}class i{constructor(t,i,s){this.tiles=t,this.stolenFrom=i,this.belongsTo=s}push(t){this.tiles.push(t)}pop(){return this.tiles.pop()}getTiles(){return this.tiles}compare(t){const i=this.tiles[0].compare(t.tiles[0]);return 0!==i?i:this.tiles[1].compare(t.tiles[1])}drawGroup(t,i,s,e,h,n,a){t.save(),t.translate(525,525),t.rotate(n),t.translate(-525,-525);const l=75*h,r=90*h,o=25*h/2,c=(this.belongsTo-this.stolenFrom-1+4)%4,d=void 0===a?-1:a.getFamily(),u=void 0===a?0:a.getValue(),m=(i,s,e,n)=>{i.drawTile(t,s,e,h,!1,n,i.isEqual(d,u))},p=Math.PI/2;switch(c){case 0:m(this.tiles[0],i,s+o,p),m(this.tiles[1],i+r,s,0),m(this.tiles[2],i+r+l+e*h,s,0);break;case 1:m(this.tiles[0],i,s,0),m(this.tiles[1],i+r,s+o,-p),m(this.tiles[2],i+r+l+3*e*h,s,0);break;case 2:m(this.tiles[0],i,s,0),m(this.tiles[1],i+l+e*h,s,0),m(this.tiles[2],i+r+l+e*h,s+o,-p);break;default:console.error(`Position non prise en charge: ${c}`)}t.restore()}}const s="m",e=1,h="p",n=2,a="s",l=3,r="w",o=4,c="d",d=5;class u{constructor(t=""){this.isolate=!1,this.tiles=[],this.initializeFromString(t)}initializeFromString(t){for(let i=0;is.getFamily()===t&&s.getValue()===i))}eject(t){if(t<0||t>=this.tiles.length)throw new Error("Invalid tile index");[this.tiles[0],this.tiles[t]]=[this.tiles[t],this.tiles[0]];const i=this.tiles.shift();return this.sort(),i}get(t){if(!(void 0===t||t<0||t>=this.tiles.length))return this.tiles[t]}sort(){this.tiles.sort(((t,i)=>t.isLessThan(i)?-1:1))}count(t,i){return this.tiles.filter((s=>s.getFamily()===t&&s.getValue()===i)).length}toGroup(t=!1){if(0===this.tiles.length)return[];const i=this.tiles.pop(),s=i.getFamily(),e=i.getValue();if(this.count(s,e)>=1&&!t){const t=this.tryFormPair(i);if(t)return t}if(this.count(s,e)>=2){const s=this.tryFormTriplet(i,t);if(s)return s}const h=this.count(s,e-1)>0,n=this.count(s,e-2)>0;if(h&&n){const s=this.tryFormSequence(i,t);if(s)return s}this.tiles.push(i),this.sort()}tryFormPair(t){const s=this.find(t.getFamily(),t.getValue()),e=this.toGroup(!0);if(this.tiles.push(s),this.sort(),void 0!==e)return this.tiles.push(t),this.sort(),e.push(new i([t,s],0,0)),e}tryFormTriplet(t,s){const e=this.find(t.getFamily(),t.getValue()),h=this.find(t.getFamily(),t.getValue()),n=this.toGroup(s);if(this.tiles.push(e),this.tiles.push(h),this.sort(),void 0!==n)return n.push(new i([t,e,h],0,0)),this.tiles.push(t),this.sort(),n}tryFormSequence(t,s){const e=this.find(t.getFamily(),t.getValue()-1),h=this.find(t.getFamily(),t.getValue()-2),n=this.toGroup(s);if(this.tiles.push(e),this.tiles.push(h),this.sort(),void 0!==n)return n.push(new i([h,e,t],0,0)),this.tiles.push(t),this.sort(),n}drawHand(t,i,s,e,h,n=void 0,a=!1,l=0){const r=(75+e)*h,o=Math.cos(l)*r,c=Math.sin(l)*r;for(let e=0;et.preloadImg())))},new((s=void 0)||(s=Promise))((function(h,n){function a(t){try{r(e.next(t))}catch(t){n(t)}}function l(t){try{r(e.throw(t))}catch(t){n(t)}}function r(t){var i;t.done?h(t.value):(i=t.value,i instanceof s?i:new s((function(t){t(i)}))).then(a,l)}r((e=e.apply(t,i||[])).next())}));var t,i,s,e}cleanup(){this.tiles.forEach((t=>t.cleanup())),this.tiles=[]}}class m{constructor(t=!1){this.tiles=[],this.tileIndexMap=new Map,this.initTiles(t)}displayFamilies(t,i,s,e,h=0,n=0){let a=i,l=s;const r=[{family:1,start:1,end:9},{family:2,start:1,end:9},{family:3,start:1,end:9},{family:4,start:1,end:4},{family:5,start:1,end:3}];for(const s of r){for(let i=s.start;i<=s.end;i++){const n=this.find(s.family,i);n&&(n.drawTile(t,a,l,e,!1,0,!1),a+=(75+h)*e)}a=i,l+=(100+n)*e}}length(){return this.tiles.length}pop(){if(0===this.tiles.length)throw new Error("Cannot pop from an empty deck");const t=this.tiles.pop(),i=this.getTileKey(t.getFamily(),t.getValue()),s=this.tileIndexMap.get(i);return s&&s.length>0&&(s.pop(),0===s.length?this.tileIndexMap.delete(i):this.tileIndexMap.set(i,s)),t}push(t){const i=this.tiles.length;this.tiles.push(t);const s=this.getTileKey(t.getFamily(),t.getValue()),e=this.tileIndexMap.get(s)||[];e.push(i),this.tileIndexMap.set(s,e)}find(t,i){const s=this.getTileKey(t,i),e=this.tileIndexMap.get(s);if(!e||0===e.length)return;const h=e[0];if(h>=this.tiles.length)return this.rebuildIndexMap(),this.find(t,i);[this.tiles[h],this.tiles[0]]=[this.tiles[0],this.tiles[h]],this.updateIndicesAfterSwap(0,h);const n=this.tiles.shift();return this.decrementIndicesAfterShift(),n}count(t,i){const s=this.getTileKey(t,i),e=this.tileIndexMap.get(s);return e?e.length:0}shuffle(){for(let t=this.tiles.length-1;t>0;t--){const i=Math.floor(Math.random()*(t+1));[this.tiles[t],this.tiles[i]]=[this.tiles[i],this.tiles[t]]}this.rebuildIndexMap()}getRandomHand(){const t=new u;if(this.shuffle(),this.tiles.length<13)throw new Error("Not enough tiles in deck to create a hand");for(let i=0;i<13;i++)t.push(this.pop());return t}cleanup(){this.tiles.forEach((t=>t.cleanup())),this.tiles=[],this.tileIndexMap.clear()}preload(){return t=this,i=void 0,e=function*(){const t=this.tiles.map((t=>t.preloadImg()));yield Promise.all(t)},new((s=void 0)||(s=Promise))((function(h,n){function a(t){try{r(e.next(t))}catch(t){n(t)}}function l(t){try{r(e.throw(t))}catch(t){n(t)}}function r(t){var i;t.done?h(t.value):(i=t.value,i instanceof s?i:new s((function(t){t(i)}))).then(a,l)}r((e=e.apply(t,i||[])).next())}));var t,i,s,e}getTileKey(t,i){return`${t}-${i}`}updateIndicesAfterSwap(t,i){if(t===i)return;const s=this.tiles[t],e=this.tiles[i],h=this.getTileKey(s.getFamily(),s.getValue()),n=this.getTileKey(e.getFamily(),e.getValue()),a=this.tileIndexMap.get(h)||[],l=this.tileIndexMap.get(n)||[],r=a.indexOf(i),o=l.indexOf(t);-1!==r&&(a[r]=t),-1!==o&&(l[o]=i),this.tileIndexMap.set(h,a),this.tileIndexMap.set(n,l)}decrementIndicesAfterShift(){var t;for(const[i,s]of this.tileIndexMap.entries())this.tileIndexMap.set(i,s.filter((t=>0!==t)).map((t=>t>0?t-1:t))),0===(null===(t=this.tileIndexMap.get(i))||void 0===t?void 0:t.length)&&this.tileIndexMap.delete(i)}rebuildIndexMap(){this.tileIndexMap.clear();for(let t=0;t{this.animationFrameId=requestAnimationFrame(t);const s=i-this.lastFrameTime;s{this.canvas.removeEventListener("mousemove",t),this.canvas.removeEventListener("mousedown",i)}))}handleMouseMove(t){const i=this.canvas.getBoundingClientRect(),s=t.clientX-i.left,e=t.clientY-i.top,h=this.selectedTile;this.selectedTile=void 0;for(let t=0;t=i.x&&s<=i.x+i.width&&e>=i.y&&e<=i.y+i.height){this.selectedTile=t;break}}h!==this.selectedTile&&(this.isDirty=!0)}handleMouseDown(){void 0!==this.selectedTile&&(this.decks[0].push(this.hands[8].eject(this.selectedTile)),this.decks[0].shuffle(),this.hands[8].sort(),this.hands[8].push(this.decks[0].pop()),this.isDirty=!0)}preloadDeck(t){return p(this,void 0,void 0,(function*(){yield t.preload()}))}preloadHand(t){return p(this,void 0,void 0,(function*(){yield t.preload()}))}initialize(){return p(this,void 0,void 0,(function*(){try{this.decks.push(new m(!1)),this.hands.push(new u("s1s2s3"),new u("m2m3m4"),new u("p5p5p5"),new u("w2w2w2"),new u("d3d3d3"),new u("s4p5m6"),new u("m9s9p9"),new u("d1d2d3"),this.decks[0].getRandomHand()),yield Promise.all([...this.decks.map((t=>this.preloadDeck(t))),...this.hands.map((t=>this.preloadHand(t)))]),this.hands[8].push(this.decks[0].pop()),this.hands[8].sort(),this.initEventListeners(),this.isDirty=!0,this.drawFrame(),this.startAnimationLoop()}catch(t){console.error("Erreur d'initialisation:",t)}}))}cleanup(){null!==this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.cleanupCallbacks.forEach((t=>t())),this.cleanupCallbacks=[],this.decks.forEach((t=>t.cleanup())),this.hands.forEach((t=>t.cleanup())),this.decks=[],this.hands=[],this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.staticCtx.clearRect(0,0,this.staticCanvas.width,this.staticCanvas.height)}}let E=null;function v(){E&&(E.cleanup(),E=null)}"undefined"!=typeof window&&function(){return p(this,void 0,void 0,(function*(){try{E=new I(g),yield E.initialize(),window.cleanup=v}catch(t){console.error("Erreur lors de l'initialisation:",t)}}))}().catch(console.error)})(); \ No newline at end of file +(()=>{"use strict";class t{constructor(t,i,s){this.family=t,this.value=i,this.red=s,this.imgFront=new Image,this.imgBack=new Image,this.imgGray=new Image,this.img=new Image,this.imgSrc="",this.tilt=0,this.setImgSrc()}getFamily(){return this.family}getValue(){return this.value}isEqual(t,i){return this.family===t&&this.value===i}isRed(){return this.red}compare(t){return this.family!==t.family?this.family{t.onload=null,t.onerror=null}))}preloadImg(){return t=this,i=void 0,e=function*(){const t=[{img:this.imgFront,src:"img/Regular/Front.svg"},{img:this.imgBack,src:"img/Regular/Back.svg"},{img:this.imgGray,src:"img/Regular/Gray.svg"},{img:this.img,src:this.imgSrc}];yield Promise.all(t.map((({img:t,src:i})=>this.loadImg(t,i))))},new((s=void 0)||(s=Promise))((function(h,n){function a(t){try{r(e.next(t))}catch(t){n(t)}}function l(t){try{r(e.throw(t))}catch(t){n(t)}}function r(t){var i;t.done?h(t.value):(i=t.value,i instanceof s?i:new s((function(t){t(i)}))).then(a,l)}r((e=e.apply(t,i||[])).next())}));var t,i,s,e}loadImg(t,i){return new Promise(((s,e)=>{t.onload=()=>s(),t.onerror=()=>e(),t.src=i}))}setImgSrc(){if(this.imgSrc="img/Regular/",this.family<=3){const t=["","Man","Pin","Sou"];this.imgSrc+=t[this.family]+String(this.value),this.red&&(this.imgSrc+="-Dora")}else if(4===this.family){const t=["","Ton","Nan","Shaa","Pei"];this.imgSrc+=t[this.value]}else if(5===this.family){const t=["","Chun","Hatsu","Haku"];this.imgSrc+=t[this.value]}this.imgSrc+=".svg"}}class i{constructor(t,i,s){this.tiles=t,this.stolenFrom=i,this.belongsTo=s}push(t){this.tiles.push(t)}pop(){return this.tiles.pop()}getTiles(){return this.tiles}compare(t){const i=this.tiles[0].compare(t.tiles[0]);return 0!==i?i:this.tiles[1].compare(t.tiles[1])}drawGroup(t,i,s,e,h,n,a){t.save(),t.translate(525,525),t.rotate(n),t.translate(-525,-525);const l=75*h,r=90*h,o=25*h/2,c=(this.belongsTo-this.stolenFrom-1+4)%4,d=void 0===a?-1:a.getFamily(),u=void 0===a?0:a.getValue(),m=(i,s,e,n)=>{i.drawTile(t,s,e,h,!1,n,i.isEqual(d,u))},p=Math.PI/2;switch(c){case 0:m(this.tiles[0],i,s+o,p),m(this.tiles[1],i+r,s,0),m(this.tiles[2],i+r+l+e*h,s,0);break;case 1:m(this.tiles[0],i,s,0),m(this.tiles[1],i+r,s+o,-p),m(this.tiles[2],i+r+l+3*e*h,s,0);break;case 2:m(this.tiles[0],i,s,0),m(this.tiles[1],i+l+e*h,s,0),m(this.tiles[2],i+r+l+e*h,s+o,-p);break;default:console.error(`Position non prise en charge: ${c}`)}t.restore()}}const s="m",e=1,h="p",n=2,a="s",l=3,r="w",o=4,c="d",d=5;class u{constructor(t=""){this.isolate=!1,this.tiles=[],this.initializeFromString(t)}initializeFromString(t){for(let i=0;is.getFamily()===t&&s.getValue()===i))}eject(t){if(t<0||t>=this.tiles.length)throw new Error("Invalid tile index");[this.tiles[0],this.tiles[t]]=[this.tiles[t],this.tiles[0]];const i=this.tiles.shift();return this.sort(),i}get(t){if(!(void 0===t||t<0||t>=this.tiles.length))return this.tiles[t]}sort(){this.tiles.sort(((t,i)=>t.isLessThan(i)?-1:1))}count(t,i){return this.tiles.filter((s=>s.getFamily()===t&&s.getValue()===i)).length}toGroup(t=!1){if(0===this.tiles.length)return[];const i=this.tiles.pop(),s=i.getFamily(),e=i.getValue();if(this.count(s,e)>=1&&!t){const t=this.tryFormPair(i);if(t)return t}if(this.count(s,e)>=2){const s=this.tryFormTriplet(i,t);if(s)return s}const h=this.count(s,e-1)>0,n=this.count(s,e-2)>0;if(h&&n){const s=this.tryFormSequence(i,t);if(s)return s}this.tiles.push(i),this.sort()}tryFormPair(t){const s=this.find(t.getFamily(),t.getValue()),e=this.toGroup(!0);if(this.tiles.push(s),this.sort(),void 0!==e)return this.tiles.push(t),this.sort(),e.push(new i([t,s],0,0)),e}tryFormTriplet(t,s){const e=this.find(t.getFamily(),t.getValue()),h=this.find(t.getFamily(),t.getValue()),n=this.toGroup(s);if(this.tiles.push(e),this.tiles.push(h),this.sort(),void 0!==n)return n.push(new i([t,e,h],0,0)),this.tiles.push(t),this.sort(),n}tryFormSequence(t,s){const e=this.find(t.getFamily(),t.getValue()-1),h=this.find(t.getFamily(),t.getValue()-2),n=this.toGroup(s);if(this.tiles.push(e),this.tiles.push(h),this.sort(),void 0!==n)return n.push(new i([h,e,t],0,0)),this.tiles.push(t),this.sort(),n}drawHand(t,i,s,e,h,n=void 0,a=!1,l=0){const r=(75+e)*h,o=Math.cos(l)*r,c=Math.sin(l)*r;for(let e=0;et.preloadImg())))},new((s=void 0)||(s=Promise))((function(h,n){function a(t){try{r(e.next(t))}catch(t){n(t)}}function l(t){try{r(e.throw(t))}catch(t){n(t)}}function r(t){var i;t.done?h(t.value):(i=t.value,i instanceof s?i:new s((function(t){t(i)}))).then(a,l)}r((e=e.apply(t,i||[])).next())}));var t,i,s,e}cleanup(){this.tiles.forEach((t=>t.cleanup())),this.tiles=[]}}class m{constructor(t=!1){this.tiles=[],this.tileIndexMap=new Map,this.initTiles(t)}displayFamilies(t,i,s,e,h=0,n=0){let a=i,l=s;const r=[{family:1,start:1,end:9},{family:2,start:1,end:9},{family:3,start:1,end:9},{family:4,start:1,end:4},{family:5,start:1,end:3}];for(const s of r){for(let i=s.start;i<=s.end;i++){const n=this.find(s.family,i);n&&(n.drawTile(t,a,l,e,!1,0,!1),a+=(75+h)*e)}a=i,l+=(100+n)*e}}length(){return this.tiles.length}pop(){if(0===this.tiles.length)throw new Error("Cannot pop from an empty deck");const t=this.tiles.pop(),i=this.getTileKey(t.getFamily(),t.getValue()),s=this.tileIndexMap.get(i);return s&&s.length>0&&(s.pop(),0===s.length?this.tileIndexMap.delete(i):this.tileIndexMap.set(i,s)),t}push(t){const i=this.tiles.length;this.tiles.push(t);const s=this.getTileKey(t.getFamily(),t.getValue()),e=this.tileIndexMap.get(s)||[];e.push(i),this.tileIndexMap.set(s,e)}find(t,i){const s=this.getTileKey(t,i),e=this.tileIndexMap.get(s);if(!e||0===e.length)return;const h=e[0];if(h>=this.tiles.length)return this.rebuildIndexMap(),this.find(t,i);[this.tiles[h],this.tiles[0]]=[this.tiles[0],this.tiles[h]],this.updateIndicesAfterSwap(0,h);const n=this.tiles.shift();return this.decrementIndicesAfterShift(),n}count(t,i){const s=this.getTileKey(t,i),e=this.tileIndexMap.get(s);return e?e.length:0}shuffle(){for(let t=this.tiles.length-1;t>0;t--){const i=Math.floor(Math.random()*(t+1));[this.tiles[t],this.tiles[i]]=[this.tiles[i],this.tiles[t]]}this.rebuildIndexMap()}getRandomHand(){const t=new u;if(this.shuffle(),this.tiles.length<13)throw new Error("Not enough tiles in deck to create a hand");for(let i=0;i<13;i++)t.push(this.pop());return t}cleanup(){this.tiles.forEach((t=>t.cleanup())),this.tiles=[],this.tileIndexMap.clear()}preload(){return t=this,i=void 0,e=function*(){const t=this.tiles.map((t=>t.preloadImg()));yield Promise.all(t)},new((s=void 0)||(s=Promise))((function(h,n){function a(t){try{r(e.next(t))}catch(t){n(t)}}function l(t){try{r(e.throw(t))}catch(t){n(t)}}function r(t){var i;t.done?h(t.value):(i=t.value,i instanceof s?i:new s((function(t){t(i)}))).then(a,l)}r((e=e.apply(t,i||[])).next())}));var t,i,s,e}getTileKey(t,i){return`${t}-${i}`}updateIndicesAfterSwap(t,i){if(t===i)return;const s=this.tiles[t],e=this.tiles[i],h=this.getTileKey(s.getFamily(),s.getValue()),n=this.getTileKey(e.getFamily(),e.getValue()),a=this.tileIndexMap.get(h)||[],l=this.tileIndexMap.get(n)||[],r=a.indexOf(i),o=l.indexOf(t);-1!==r&&(a[r]=t),-1!==o&&(l[o]=i),this.tileIndexMap.set(h,a),this.tileIndexMap.set(n,l)}decrementIndicesAfterShift(){var t;for(const[i,s]of this.tileIndexMap.entries())this.tileIndexMap.set(i,s.filter((t=>0!==t)).map((t=>t>0?t-1:t))),0===(null===(t=this.tileIndexMap.get(i))||void 0===t?void 0:t.length)&&this.tileIndexMap.delete(i)}rebuildIndexMap(){this.tileIndexMap.clear();for(let t=0;t{this.animationFrameId=requestAnimationFrame(t);const s=i-this.lastFrameTime;s{this.canvas.removeEventListener("mousemove",t),this.canvas.removeEventListener("mousedown",i)}))}handleMouseMove(t){const i=this.canvas.getBoundingClientRect(),s=t.clientX-i.left,e=t.clientY-i.top,h=this.selectedTile;this.selectedTile=void 0;for(let t=0;t=i.x&&s<=i.x+i.width&&e>=i.y&&e<=i.y+i.height){this.selectedTile=t;break}}h!==this.selectedTile&&(this.isDirty=!0)}handleMouseDown(){void 0!==this.selectedTile&&(this.decks[0].push(this.hands[8].eject(this.selectedTile)),this.decks[0].shuffle(),this.hands[8].sort(),this.hands[8].push(this.decks[0].pop()),this.isDirty=!0)}preloadDeck(t){return p(this,void 0,void 0,(function*(){yield t.preload()}))}preloadHand(t){return p(this,void 0,void 0,(function*(){yield t.preload()}))}initialize(){return p(this,void 0,void 0,(function*(){try{this.decks.push(new m(!1)),this.hands.push(new u("s1s2s3"),new u("m2m3m4"),new u("p5p5p5"),new u("w2w2w2"),new u("d3d3d3"),new u("s4p5m6"),new u("m9s9p9"),new u("d1d2d3"),this.decks[0].getRandomHand()),yield Promise.all([...this.decks.map((t=>this.preloadDeck(t))),...this.hands.map((t=>this.preloadHand(t)))]),this.hands[8].push(this.decks[0].pop()),this.hands[8].sort(),this.initEventListeners(),this.isDirty=!0,this.drawFrame(),this.startAnimationLoop()}catch(t){console.error("Erreur d'initialisation:",t)}}))}cleanup(){null!==this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.cleanupCallbacks.forEach((t=>t())),this.cleanupCallbacks=[],this.decks.forEach((t=>t.cleanup())),this.hands.forEach((t=>t.cleanup())),this.decks=[],this.hands=[],this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.staticCtx.clearRect(0,0,this.staticCanvas.width,this.staticCanvas.height)}}let E=null;function v(){E&&(E.cleanup(),E=null)}"undefined"!=typeof window&&function(){return p(this,void 0,void 0,(function*(){try{E=new I(g),yield E.initialize(),window.cleanup=v}catch(t){console.error("Erreur lors de l'initialisation:",t)}}))}().catch(console.error)})(); \ No newline at end of file diff --git a/src/display/dp2.ts b/src/display/dp2.ts index 6f452a8..5a257f7 100644 --- a/src/display/dp2.ts +++ b/src/display/dp2.ts @@ -31,7 +31,7 @@ class RiichiDisplay { private readonly Y: number = 150; private readonly OS: number = 75; private readonly SIZE: number = 0.75; - private readonly TILE_WIDTH: number = 80 * this.SIZE; + private readonly TILE_WIDTH: number = 78 * this.SIZE; private readonly MAX_TILES: number = 14; // Cache for mouse hit detection @@ -78,7 +78,7 @@ class RiichiDisplay { this.tileRects = []; for (let i = 0; i < this.MAX_TILES; i++) { this.tileRects.push({ - x: this.X + i * this.TILE_WIDTH, + x: this.X + i * this.TILE_WIDTH + (i === this.MAX_TILES - 1 ? 10 : 0), y: 800, width: 75, height: 100 * this.SIZE diff --git a/src/display/dp3.ts b/src/display/dp3.ts index 72af497..7ca20e3 100644 --- a/src/display/dp3.ts +++ b/src/display/dp3.ts @@ -42,7 +42,7 @@ class RiichiDisplay { private readonly INTERACTIVE_X: number = 100; private readonly INTERACTIVE_Y: number = 800; private readonly SIZE: number = 0.75; - private readonly TILE_WIDTH: number = 80 * this.SIZE; + private readonly TILE_WIDTH: number = 78 * this.SIZE; private readonly MAX_TILES: number = 14; // Zones de détection pour l'interaction souris @@ -85,7 +85,7 @@ class RiichiDisplay { this.tileRects = []; for (let i = 0; i < this.MAX_TILES; i++) { this.tileRects.push({ - x: this.INTERACTIVE_X + i * this.TILE_WIDTH, + x: this.INTERACTIVE_X + i * this.TILE_WIDTH + (i === this.MAX_TILES - 1 ? 10 : 0), y: this.INTERACTIVE_Y, width: 75, height: 100 * this.SIZE