diff --git a/game.js b/game.js index 5cfdd96..5848b98 100644 --- a/game.js +++ b/game.js @@ -6,6 +6,7 @@ const gameCanvas = document.getElementById("gameCanvas"); const ctx = gameCanvas.getContext("2d"); const gameWorld = new GameWorld(); +let monacoEditor; let pyodideWorker = startPyodideWorker(); let robots = null;//createInitialRobots(); @@ -114,7 +115,7 @@ function gameLoop(timestamp) { const deltaTime = timestamp - lastFrameTime; // If enough time has passed since the last frame, update and draw if (deltaTime >= targetInterval) { - lastFrameTime = timestamp; + lastFrameTime = timestamp; if (!paused) { ctx.resetTransform(); // Fill the entire visible canvas to remove artifacts @@ -132,7 +133,7 @@ function gameLoop(timestamp) { state: gameWorld }); - + } } requestAnimationFrame(gameLoop); @@ -158,11 +159,13 @@ function updateSensorData() { //setInterval(updateSensorData, 2000); // Call every 2 seconds -// ✅ Button Event Listeners document.getElementById("compile-button").addEventListener("click", () => { if (paused) return; - let code = document.getElementById("python-code").value; + + // Use the Monaco Editor instance to get the code + let code = monacoEditor.getValue(); // Get text from the editor console.log(code); + code = code.replace(/time\.sleep\(/g, "await time.sleep("); console.log(code); consoleElement.innerHTML = ""; @@ -172,6 +175,7 @@ document.getElementById("compile-button").addEventListener("click", () => { }); }); + document.getElementById("pause-button").addEventListener("click", togglePause); document.getElementById("reset-button").addEventListener("click", resetGame); @@ -218,3 +222,57 @@ gameCanvas.addEventListener("mouseup", () => { isPanning = false; }); +const textarea = document.getElementById('python-code'); + +// textarea.addEventListener('keydown', function (event) { +// if (event.key === 'Tab') { +// event.preventDefault(); +// const start = this.selectionStart; +// const end = this.selectionEnd; +// this.value = this.value.substring(0, start) + ' ' + this.value.substring(end); +// this.selectionStart = this.selectionEnd = start + 1; +// } +// }); + +// game.js + +export function initializeMonaco() { + require.config({ paths: { vs: "https://cdn.jsdelivr.net/npm/monaco-editor@0.39.0/min/vs" } }); + + require(["vs/editor/editor.main"], function () { + // Store the editor instance in the global variable + monacoEditor = monaco.editor.create(document.getElementById("monaco-editor"), { + value: "# Type your Python code here\n", + language: "python", + theme: "vs-dark", + automaticLayout: true + }); + }); +} + +function setupCanvas() { + const canvas = document.getElementById("gameCanvas"); + const context = canvas.getContext("2d"); + + // Get the device pixel ratio + const dpr = window.devicePixelRatio || 1; + + // Adjust the canvas size for high-DPI displays + const rect = canvas.getBoundingClientRect(); + canvas.width = rect.width * dpr; + canvas.height = rect.height * dpr; + + // Scale the drawing context + context.scale(dpr, dpr); + + // Optional: Clear the canvas for better visuals + context.clearRect(0, 0, canvas.width, canvas.height); +} + +// Call this function when the page loads +setupCanvas(); + + + + + diff --git a/index.html b/index.html index 7f32990..a47d571 100644 --- a/index.html +++ b/index.html @@ -7,43 +7,81 @@