test-map.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <!DOCTYPE html>
  2. <html lang="fr">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Test Map Editor</title>
  7. <style>
  8. body {
  9. margin: 20px;
  10. font-family: Arial, sans-serif;
  11. }
  12. .map-canvas-container {
  13. position: relative;
  14. overflow: hidden;
  15. height: 600px;
  16. background-color: #f8f9fa;
  17. border: 1px solid #ccc;
  18. }
  19. #mapCanvas {
  20. position: absolute;
  21. top: 0;
  22. left: 0;
  23. cursor: grab;
  24. }
  25. #mapLoading {
  26. position: absolute;
  27. top: 0;
  28. left: 0;
  29. width: 100%;
  30. height: 100%;
  31. background-color: rgba(255,255,255,0.8);
  32. display: flex;
  33. align-items: center;
  34. justify-content: center;
  35. }
  36. .hexagon {
  37. position: absolute;
  38. border: 1px solid #ddd;
  39. background-color: #fff;
  40. cursor: pointer;
  41. transition: background-color 0.2s;
  42. }
  43. </style>
  44. </head>
  45. <body>
  46. <h1>Test de l'éditeur de carte</h1>
  47. <div id="info"></div>
  48. <div class="map-canvas-container">
  49. <div id="mapCanvas">
  50. <!-- Les hexagones seront rendus ici -->
  51. </div>
  52. <div id="mapLoading">
  53. <div>Chargement de la carte...</div>
  54. </div>
  55. </div>
  56. <script>
  57. // Données de test
  58. const mapData = {
  59. "id": 5,
  60. "name": "Carte de test",
  61. "width": 5,
  62. "height": 5
  63. };
  64. const mapWidth = mapData.width;
  65. const mapHeight = mapData.height;
  66. // Configuration de l'éditeur de carte
  67. class MapEditor {
  68. constructor() {
  69. console.log('MapEditor: Initialisation en cours...');
  70. this.canvas = document.getElementById('mapCanvas');
  71. this.container = document.querySelector('.map-canvas-container');
  72. this.tileSize = 30;
  73. console.log('Canvas element:', this.canvas);
  74. console.log('Container element:', this.container);
  75. if (!this.canvas || !this.container) {
  76. console.error('Éléments manquants!');
  77. return;
  78. }
  79. this.init();
  80. }
  81. init() {
  82. console.log('Début de l\'initialisation...');
  83. this.setupCanvas();
  84. this.renderMap();
  85. this.hideLoading();
  86. console.log('Initialisation terminée');
  87. }
  88. setupCanvas() {
  89. const hexWidth = this.tileSize * 1.5;
  90. const hexHeight = this.tileSize * Math.sqrt(3);
  91. const canvasWidth = (mapWidth + 0.5) * hexWidth;
  92. const canvasHeight = (mapHeight + 0.5) * hexHeight;
  93. this.canvas.style.width = canvasWidth + 'px';
  94. this.canvas.style.height = canvasHeight + 'px';
  95. console.log('Canvas dimensions:', canvasWidth, 'x', canvasHeight);
  96. }
  97. renderMap() {
  98. console.log('Début du rendu...');
  99. this.canvas.innerHTML = '';
  100. let hexCount = 0;
  101. for (let q = 0; q < mapWidth; q++) {
  102. for (let r = 0; r < mapHeight; r++) {
  103. this.renderHexagon(q, r);
  104. hexCount++;
  105. }
  106. }
  107. console.log(hexCount + ' hexagones créés');
  108. // Afficher les infos
  109. document.getElementById('info').innerHTML =
  110. `<p>✓ Carte: ${mapData.name}</p>
  111. <p>✓ Dimensions: ${mapWidth} × ${mapHeight}</p>
  112. <p>✓ Hexagones rendus: ${hexCount}</p>`;
  113. }
  114. renderHexagon(q, r) {
  115. const hex = document.createElement('div');
  116. hex.className = 'hexagon';
  117. hex.dataset.q = q;
  118. hex.dataset.r = r;
  119. const x = q * this.tileSize * 1.5;
  120. const y = r * this.tileSize * Math.sqrt(3) + (q % 2) * this.tileSize * Math.sqrt(3) / 2;
  121. hex.style.left = x + 'px';
  122. hex.style.top = y + 'px';
  123. hex.style.width = this.tileSize + 'px';
  124. hex.style.height = this.tileSize + 'px';
  125. hex.style.clipPath = 'polygon(50% 0%, 93.3% 25%, 93.3% 75%, 50% 100%, 6.7% 75%, 6.7% 25%)';
  126. hex.addEventListener('click', () => {
  127. alert(`Hexagone cliqué: Q=${q}, R=${r}`);
  128. });
  129. this.canvas.appendChild(hex);
  130. }
  131. hideLoading() {
  132. document.getElementById('mapLoading').style.display = 'none';
  133. }
  134. }
  135. // Initialiser
  136. document.addEventListener('DOMContentLoaded', function() {
  137. console.log('DOM chargé');
  138. try {
  139. const editor = new MapEditor();
  140. console.log('MapEditor créé:', editor);
  141. } catch (error) {
  142. console.error('Erreur:', error);
  143. document.getElementById('info').innerHTML =
  144. `<p style="color: red;">❌ Erreur: ${error.message}</p>`;
  145. }
  146. });
  147. </script>
  148. </body>
  149. </html>