|
|
@@ -127,6 +127,9 @@
|
|
|
hex.style.backgroundColor = '#ffffff';
|
|
|
hex.style.clipPath = 'polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%)';
|
|
|
|
|
|
+ // Ajouter le SVG selon le type de tuile
|
|
|
+ this.updateHexagonContent(hex, q, r);
|
|
|
+
|
|
|
hex.addEventListener('click', (e) => {
|
|
|
e.stopPropagation();
|
|
|
this.selectTile(q, r);
|
|
|
@@ -147,6 +150,47 @@
|
|
|
this.canvas.appendChild(hex);
|
|
|
}
|
|
|
|
|
|
+ updateHexagonContent(hex, q, r) {
|
|
|
+ // Vider le contenu existant
|
|
|
+ hex.innerHTML = '';
|
|
|
+
|
|
|
+ // Récupérer le type de tuile
|
|
|
+ let type = null;
|
|
|
+ try {
|
|
|
+ if (window.mapData && window.mapData.tiles) {
|
|
|
+ const key = `${q},${r}`;
|
|
|
+ const tileData = window.mapData.tiles[key];
|
|
|
+ if (tileData && tileData.type) {
|
|
|
+ type = tileData.type;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ // ignore
|
|
|
+ }
|
|
|
+
|
|
|
+ if (type && type !== 'empty') {
|
|
|
+ // Récupérer le SVG depuis les options de la sidebar
|
|
|
+ const radio = document.querySelector(`.tile-type-radio[value="${type}"]`);
|
|
|
+ if (radio) {
|
|
|
+ const label = radio.parentElement.querySelector('.form-check-label');
|
|
|
+ if (label) {
|
|
|
+ const svg = label.querySelector('svg');
|
|
|
+ if (svg) {
|
|
|
+ const svgClone = svg.cloneNode(true);
|
|
|
+ // Ajuster la taille du SVG pour la tuile
|
|
|
+ svgClone.setAttribute('width', '100%');
|
|
|
+ svgClone.setAttribute('height', '100%');
|
|
|
+ svgClone.style.position = 'absolute';
|
|
|
+ svgClone.style.top = '0';
|
|
|
+ svgClone.style.left = '0';
|
|
|
+ svgClone.style.pointerEvents = 'none';
|
|
|
+ hex.appendChild(svgClone);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
selectTile(q, r) {
|
|
|
if (this.selectedTile) {
|
|
|
const prevHex = this.canvas.querySelector(`[data-q="${this.selectedTile.q}"][data-r="${this.selectedTile.r}"]`);
|
|
|
@@ -300,12 +344,60 @@
|
|
|
window.mapData.tiles[key] = window.mapData.tiles[key] || {};
|
|
|
window.mapData.tiles[key].type = type;
|
|
|
|
|
|
+ // Mettre à jour visuellement la tuile
|
|
|
+ const hex = document.querySelector(`.hexagon[data-q="${q}"][data-r="${r}"]`);
|
|
|
+ if (hex) {
|
|
|
+ updateHexagonContent(hex, q, r);
|
|
|
+ }
|
|
|
+
|
|
|
// Dispatch event pour signaler changement de type
|
|
|
try { window.dispatchEvent(new CustomEvent('mg:tileTypeChanged', { detail: { q, r, type } })); } catch(e){}
|
|
|
}
|
|
|
} catch (err){ console.error('Erreur lors du changement de type de tuile', err); }
|
|
|
}
|
|
|
|
|
|
+ // Fonction pour mettre à jour le contenu d'un hexagone selon son type
|
|
|
+ function updateHexagonContent(hex, q, r) {
|
|
|
+ // Vider le contenu existant
|
|
|
+ hex.innerHTML = '';
|
|
|
+
|
|
|
+ // Récupérer le type de tuile
|
|
|
+ let type = null;
|
|
|
+ try {
|
|
|
+ if (window.mapData && window.mapData.tiles) {
|
|
|
+ const key = `${q},${r}`;
|
|
|
+ const tileData = window.mapData.tiles[key];
|
|
|
+ if (tileData && tileData.type) {
|
|
|
+ type = tileData.type;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ // ignore
|
|
|
+ }
|
|
|
+
|
|
|
+ if (type && type !== 'empty') {
|
|
|
+ // Récupérer le SVG depuis les options de la sidebar
|
|
|
+ const radio = document.querySelector(`.tile-type-radio[value="${type}"]`);
|
|
|
+ if (radio) {
|
|
|
+ const label = radio.parentElement.querySelector('.form-check-label');
|
|
|
+ if (label) {
|
|
|
+ const svg = label.querySelector('svg');
|
|
|
+ if (svg) {
|
|
|
+ const svgClone = svg.cloneNode(true);
|
|
|
+ // Ajuster la taille du SVG pour la tuile
|
|
|
+ svgClone.setAttribute('width', '100%');
|
|
|
+ svgClone.setAttribute('height', '100%');
|
|
|
+ svgClone.style.position = 'absolute';
|
|
|
+ svgClone.style.top = '0';
|
|
|
+ svgClone.style.left = '0';
|
|
|
+ svgClone.style.pointerEvents = 'none';
|
|
|
+ hex.appendChild(svgClone);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// Fonction pour mettre à jour les checkboxes selon le type de la tuile sélectionnée
|
|
|
function updateTileTypeCheckboxes(type) {
|
|
|
const radios = document.querySelectorAll('.tile-type-radio');
|
|
|
@@ -335,8 +427,14 @@
|
|
|
|
|
|
// Écouter les changements de type de tuile pour mettre à jour les checkboxes
|
|
|
window.addEventListener('mg:tileTypeChanged', function(ev){
|
|
|
- const { type } = ev.detail;
|
|
|
+ const { type, q, r } = ev.detail;
|
|
|
updateTileTypeCheckboxes(type);
|
|
|
+
|
|
|
+ // Mettre à jour visuellement la tuile
|
|
|
+ const hex = document.querySelector(`.hexagon[data-q="${q}"][data-r="${r}"]`);
|
|
|
+ if (hex) {
|
|
|
+ updateHexagonContent(hex, q, r);
|
|
|
+ }
|
|
|
});
|
|
|
});
|
|
|
})();
|