diff --git a/index.html b/index.html index be97f45..84a2a5d 100644 --- a/index.html +++ b/index.html @@ -78,6 +78,7 @@ +
diff --git a/script.js b/script.js index 364947a..e6bc672 100644 --- a/script.js +++ b/script.js @@ -171,6 +171,7 @@ const maxSpeedOutput = document.getElementById('max-speed-value'); // Get button elements const resetBtn = document.getElementById('reset-btn'); const generateInputsBtn = document.getElementById('generate-inputs-btn'); +const clearInputsBtn = document.getElementById('delete-inputs-btn'); const applyCustomBtn = document.getElementById('apply-custom-btn'); // Preset buttons @@ -266,11 +267,77 @@ preset8WheelBtn.addEventListener('click', () => { updateModuleDisplays(robot); }); +generateInputsBtn.addEventListener('click', () => { + const count = parseInt(moduleCountInput.value); + + if (isNaN(count) || count < 2) { + alert('Please enter a valid number of modules between 2 and 12.'); + return; + } + generateModuleInputs(count); + applyCustomBtn.style.display = 'block'; +}); + +clearInputsBtn.addEventListener('click', () => { + generateModuleInputs(0); + applyCustomBtn.style.display = 'none'; +}); + +applyCustomBtn.addEventListener('click', () => { + const container = document.getElementById('module-position-inputs'); + const moduleElements = container.childNodes; + + const customModules = []; + for (let i = 0; i < moduleElements.length; i++) { + const xInput = document.getElementById(`module-${i}-x`); + const yInput = document.getElementById(`module-${i}-y`); + const nameInput = document.getElementById(`module-${i}-name`); + + const x = parseFloat(xInput.value); + const y = parseFloat(yInput.value); + const name = nameInput.value.trim(); + + customModules.push({ x, y, name }); + } + + robot.setModules(customModules); + robot.setName("Custom Configuration"); + createModuleDisplays(robot); + updateModuleDisplays(robot); +}); + /* * END LISTENER CODE * BEGIN DYNAMIC DOM FUNCTIONS */ +function generateModuleInputs(count) { + const container = document.getElementById('module-position-inputs'); + container.innerHTML = ''; // Clear existing inputs + + for (let i = 0; i < count; i++) { + const moduleFieldset = document.createElement('fieldset'); + moduleFieldset.className = 'module-input-group'; + moduleFieldset.innerHTML = ` + Module ${i + 1} + +
+ + +
+
+ + +
+
+ + +
+ `; + container.appendChild(moduleFieldset); + } +} + function createModuleDisplays(robot) { const grid = document.getElementById('module-grid'); grid.innerHTML = ''; // Delete any pre-existing elements before creating new ones