test-direct.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <!DOCTYPE html>
  2. <html lang="fr">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Test Direct - Map Editor</title>
  6. <style>
  7. * { margin: 0; padding: 0; box-sizing: border-box; }
  8. body { padding: 20px; font-family: Arial, sans-serif; }
  9. #info { padding: 10px; background: #e3f2fd; border-radius: 5px; margin-bottom: 20px; }
  10. .map-canvas-container {
  11. position: relative;
  12. overflow: hidden;
  13. height: 600px;
  14. background-color: #f8f9fa;
  15. border: 2px solid #333;
  16. }
  17. #mapCanvas {
  18. position: absolute;
  19. top: 0;
  20. left: 0;
  21. }
  22. .hexagon {
  23. position: absolute;
  24. border: 1px solid #666;
  25. background-color: #fff;
  26. cursor: pointer;
  27. transition: background-color 0.2s;
  28. }
  29. .hexagon:hover {
  30. background-color: #e3f2fd;
  31. }
  32. #mapLoading {
  33. position: absolute;
  34. top: 0;
  35. left: 0;
  36. width: 100%;
  37. height: 100%;
  38. background-color: rgba(255,255,255,0.9);
  39. display: flex;
  40. align-items: center;
  41. justify-content: center;
  42. font-size: 20px;
  43. }
  44. </style>
  45. </head>
  46. <body>
  47. <h1>🗺️ Test Direct - Map Editor</h1>
  48. <div id="info">Chargement en cours...</div>
  49. <div class="map-canvas-container">
  50. <div id="mapCanvas"></div>
  51. <div id="mapLoading">⏳ Chargement de la carte...</div>
  52. </div>
  53. <script>
  54. console.log('=== TEST DIRECT MAP EDITOR ===');
  55. // Données de test
  56. const mapData = {"id":5,"name":"Carte de test","width":5,"height":5};
  57. const mapWidth = mapData.width;
  58. const mapHeight = mapData.height;
  59. console.log('1. mapData:', mapData);
  60. console.log('2. Dimensions:', mapWidth, 'x', mapHeight);
  61. class MapEditor {
  62. constructor() {
  63. console.log('3. MapEditor constructor appelé');
  64. this.canvas = document.getElementById('mapCanvas');
  65. this.container = document.querySelector('.map-canvas-container');
  66. this.tileSize = 40;
  67. console.log('4. canvas:', this.canvas);
  68. console.log('5. container:', this.container);
  69. if (!this.canvas || !this.container) {
  70. console.error('❌ Éléments manquants!');
  71. document.getElementById('info').innerHTML = '❌ <strong>ERREUR:</strong> Éléments DOM non trouvés!';
  72. return;
  73. }
  74. this.init();
  75. }
  76. init() {
  77. console.log('6. init() appelé');
  78. this.setupCanvas();
  79. this.renderMap();
  80. this.hideLoading();
  81. console.log('7. init() terminé');
  82. }
  83. setupCanvas() {
  84. const hexWidth = this.tileSize * 1.5;
  85. const hexHeight = this.tileSize * Math.sqrt(3);
  86. const canvasWidth = (mapWidth + 0.5) * hexWidth;
  87. const canvasHeight = (mapHeight + 0.5) * hexHeight;
  88. this.canvas.style.width = canvasWidth + 'px';
  89. this.canvas.style.height = canvasHeight + 'px';
  90. console.log('8. Canvas configuré:', canvasWidth, 'x', canvasHeight);
  91. }
  92. renderMap() {
  93. console.log('9. renderMap() appelé');
  94. this.canvas.innerHTML = '';
  95. let count = 0;
  96. for (let q = 0; q < mapWidth; q++) {
  97. for (let r = 0; r < mapHeight; r++) {
  98. this.renderHexagon(q, r);
  99. count++;
  100. }
  101. }
  102. console.log('10. Hexagones créés:', count);
  103. document.getElementById('info').innerHTML =
  104. `✅ <strong>Succès!</strong> ${count} hexagones créés (${mapWidth}×${mapHeight})`;
  105. }
  106. renderHexagon(q, r) {
  107. const hex = document.createElement('div');
  108. hex.className = 'hexagon';
  109. hex.dataset.q = q;
  110. hex.dataset.r = r;
  111. hex.title = `Q:${q}, R:${r}`;
  112. const x = q * this.tileSize * 1.5;
  113. const y = r * this.tileSize * Math.sqrt(3) + (q % 2) * this.tileSize * Math.sqrt(3) / 2;
  114. hex.style.left = x + 'px';
  115. hex.style.top = y + 'px';
  116. hex.style.width = this.tileSize + 'px';
  117. hex.style.height = this.tileSize + 'px';
  118. hex.style.clipPath = 'polygon(50% 0%, 93.3% 25%, 93.3% 75%, 50% 100%, 6.7% 75%, 6.7% 25%)';
  119. hex.addEventListener('click', () => {
  120. alert(`Hexagone cliqué: Q=${q}, R=${r}`);
  121. });
  122. this.canvas.appendChild(hex);
  123. }
  124. hideLoading() {
  125. const loading = document.getElementById('mapLoading');
  126. if (loading) {
  127. loading.style.display = 'none';
  128. console.log('11. Loader masqué');
  129. }
  130. }
  131. }
  132. // INITIALISATION IMMÉDIATE (pas de DOMContentLoaded)
  133. console.log('12. Création de MapEditor...');
  134. try {
  135. const editor = new MapEditor();
  136. console.log('13. ✅ MapEditor créé avec succès!');
  137. } catch (error) {
  138. console.error('14. ❌ Erreur:', error);
  139. document.getElementById('info').innerHTML =
  140. `❌ <strong>ERREUR:</strong> ${error.message}`;
  141. }
  142. console.log('=== FIN DU TEST ===');
  143. </script>
  144. </body>
  145. </html>