51 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| <!DOCTYPE html>
 | |
| <html lang="en">
 | |
| <head>
 | |
|   <meta charset="UTF-8">
 | |
|   <meta name="viewport" content="width=device-width, initial-scale=1.0">
 | |
|   <title>Conversion json to js let</title>
 | |
|   <script>
 | |
|     function convertInput() {
 | |
|       const jsonString = document.getElementById('jsonInput').value;
 | |
|       const z = document.getElementById('numberInput').value;
 | |
| 
 | |
|       const data = JSON.parse(jsonString);
 | |
| 
 | |
|       data.squares.forEach(s => {
 | |
|         if(s.h<0) {
 | |
|           s.h=-1*s.h
 | |
|           s.y=s.y-s.h
 | |
|         }
 | |
|         if(s.w<0) {
 | |
|           s.w=-1*s.w
 | |
|           s.x=s.x-s.w
 | |
|         }
 | |
|       })
 | |
| 
 | |
|       const squareArray = data.squares.map(square => `new Square(${Math.round(square.x)},${Math.round(square.y)},${z},${Math.round(square.w)},${Math.round(square.h)})`);
 | |
|       const circleArray = data.circles.map(circle => `new Circle(${Math.round(circle.x)},${Math.round(circle.y)},${z},${Math.round(circle.r)})`);
 | |
| 
 | |
|       const resultString = `let map${z}Squares = [${squareArray.join(',')}]<br>let map${z}Circles = [${circleArray.join(',')}]`;
 | |
|       document.getElementById('output').innerHTML = resultString;
 | |
|     }
 | |
|   </script>
 | |
| </head>
 | |
| <body>
 | |
|   <h1>Conversion json to js let</h1>
 | |
| 
 | |
|   <label for="jsonInput">Entrée JSON :</label>
 | |
|   <textarea id="jsonInput" rows="5" cols="50" placeholder='{"squares":[{"x":100.96875,"y":64,"w":47,"h":45},{"x":280.96875,"y":46,"w":42,"h":39}],"circles":[{"x":882.96875,"y":133,"r":14.142135623730951},{"x":890.96875,"y":249,"r":17.029386365926403}]}'></textarea>
 | |
| 
 | |
|   <br>
 | |
| 
 | |
|   <label for="numberInput">z :</label>
 | |
|   <input type="number" id="numberInput" placeholder="Entrez le z de la map">
 | |
| 
 | |
|   <br>
 | |
| 
 | |
|   <button onclick="convertInput()">Convertir</button>
 | |
| 
 | |
|   <h2>Résultat :</h2>
 | |
|   <div id="output"></div>
 | |
| </body>
 | |
| </html>
 |