From 15a0d4f4d7aa109e72ff46ca5d0a147257a8b08f Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Mon, 9 Oct 2023 18:44:34 +0700 Subject: [PATCH 01/76] test getPreset --- main-dev.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/main-dev.js b/main-dev.js index d43021b..34d7ec2 100644 --- a/main-dev.js +++ b/main-dev.js @@ -29,6 +29,7 @@ class ARMMane{ ]; } + this.serverURL = "https://pi.nicezki.com/"; this.appStatus = { "connected" : false, @@ -1063,6 +1064,23 @@ class ARMMane{ console.error(`Element with ID '${uniqueElementId}' not found.`); } } + + getPreset() { + // send GET api to {server}/api/train + fetch(this.serverURL + "/config", { + method: "GET", + headers: { + "Content-Type": "application/json" + } + }).then((response) => { + if (response.status == 200) { + this.consoleLog("Train request sent successfully", "SUCCESS"); + } + else { + this.consoleLog("Train request sent failed", "ERROR"); + } + }); + } //This will change the property of the element after click save button From 7643e677b31ace520cdf6f419b1f232343616c2d Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Mon, 9 Oct 2023 18:48:02 +0700 Subject: [PATCH 02/76] remove / --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index 34d7ec2..ad1c550 100644 --- a/main-dev.js +++ b/main-dev.js @@ -29,7 +29,7 @@ class ARMMane{ ]; } - this.serverURL = "https://pi.nicezki.com/"; + this.serverURL = "https://pi.nicezki.com"; this.appStatus = { "connected" : false, From 0c506fcbd920b3c517a1fd38ae54a0d4531e2ea0 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 11:02:16 +0700 Subject: [PATCH 03/76] testing getPreset --- main-dev.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/main-dev.js b/main-dev.js index ad1c550..76437dc 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1066,22 +1066,33 @@ class ARMMane{ } getPreset() { - // send GET api to {server}/api/train - fetch(this.serverURL + "/config", { + // Send GET request to {server}/config + fetch(`${this.serverURL}/config`, { method: "GET", headers: { "Content-Type": "application/json" } - }).then((response) => { - if (response.status == 200) { - this.consoleLog("Train request sent successfully", "SUCCESS"); - } - else { + }) + .then((response) => { + if (response.status === 200) { + return response.json(); // Parse the response body as JSON + } else { this.consoleLog("Train request sent failed", "ERROR"); + throw new Error("Request failed with status: " + response.status); } + }) + .then((data) => { + // Handle the retrieved data here + console.log("Received data:", data); + + // You can now use 'data' to update your application state or UI + }) + .catch((error) => { + console.error("Error:", error); }); } + //This will change the property of the element after click save button openConfigBox(element_name) { From 691efd85a77694fd08c2dadbfd863ebc30c43a69 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 13:27:37 +0700 Subject: [PATCH 04/76] Try to get preset name --- main-dev.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index 76437dc..ec8cdac 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1085,7 +1085,19 @@ class ARMMane{ // Handle the retrieved data here console.log("Received data:", data); - // You can now use 'data' to update your application state or UI + // Check if 'config' and 'instructions' exist in the data + if (data.config && data.config.instructions) { + const instructions = data.config.instructions; + + // Extract preset names from the 'instructions' object + const presetNames = Object.keys(instructions); + + console.log("Preset Names:", presetNames); + + // You can now use 'presetNames' to work with the names of presets + } else { + console.error("Data format is invalid. Missing 'config' or 'instructions'."); + } }) .catch((error) => { console.error("Error:", error); From d89e9b2421eeb399367c11c80e03791202985aa0 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 13:56:06 +0700 Subject: [PATCH 05/76] Try to clone preset elements --- main-dev.js | 94 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 29 deletions(-) diff --git a/main-dev.js b/main-dev.js index ec8cdac..0775804 100644 --- a/main-dev.js +++ b/main-dev.js @@ -79,6 +79,7 @@ class ARMMane{ "status_conv01_backward" : this.querySel(".status-conv01-bw"), "command_area" : document.querySelectorAll(".ins-command-area"), "function_box" : document.querySelectorAll(".ins-func-box"), + "preset_box" : document.querySelectorAll(".ins-preset-box"), "livepreview" : this.querySel(".livepreview"), }, "btn" : { @@ -110,6 +111,7 @@ class ARMMane{ "btn_serverlist" : this.querySel(".tp-btn-server"), "log_alert" : this.querySel(".tp-log-alert"), "ins_function" : document.querySelectorAll(".tp-ins-func"), + "ins_preset" : document.querySelectorAll(".tp-ins-preset"), "code_block" : this.querySel(".tp-ins-code-block"), }, "text" : { @@ -1065,42 +1067,76 @@ class ARMMane{ } } - getPreset() { - // Send GET request to {server}/config - fetch(`${this.serverURL}/config`, { - method: "GET", - headers: { - "Content-Type": "application/json" - } - }) - .then((response) => { + async getPreset() { + try { + // Send GET request to {server}/config + const response = await fetch(`${this.serverURL}/config`, { + method: "GET", + headers: { + "Content-Type": "application/json" + } + }); + if (response.status === 200) { - return response.json(); // Parse the response body as JSON + const data = await response.json(); // Parse the response body as JSON + + // Check if 'config' and 'instructions' exist in the data + if (data.config && data.config.instructions) { + const instructions = data.config.instructions; + + // Extract preset names from the 'instructions' object + const presetNames = Object.keys(instructions); + + console.log("Preset Names:", presetNames); + + // Resolve the promise with preset names + return presetNames; + } else { + console.error("Data format is invalid. Missing 'config' or 'instructions'."); + throw new Error("Data format is invalid."); + } } else { - this.consoleLog("Train request sent failed", "ERROR"); + console.error("Train request sent failed", "ERROR"); throw new Error("Request failed with status: " + response.status); } - }) - .then((data) => { - // Handle the retrieved data here - console.log("Received data:", data); + } catch (error) { + console.error("Error:", error); + throw error; // Re-throw the error to propagate it + } + } - // Check if 'config' and 'instructions' exist in the data - if (data.config && data.config.instructions) { - const instructions = data.config.instructions; - - // Extract preset names from the 'instructions' object - const presetNames = Object.keys(instructions); - - console.log("Preset Names:", presetNames); + async initializePresetElements() { + try { + // Get the preset names using getPreset() + const presetNames = await this.getPreset(); - // You can now use 'presetNames' to work with the names of presets - } else { - console.error("Data format is invalid. Missing 'config' or 'instructions'."); - } - }) - .catch((error) => { + // Call clonePresetElements to populate the preset elements + this.clonePresetElements(presetNames); + } catch (error) { console.error("Error:", error); + } + } + + clonePresetElements(presetNames) { + const presetBox = this.elements["ui"]["preset_box"][0]; + const insPresetTemplate = this.elements["ui"]["ins_preset"][0]; + + // Clear existing elements in the preset box + presetBox.innerHTML = ""; + + // Iterate through the preset names + presetNames.forEach((presetName, index) => { + const clonedPreset = insPresetTemplate.cloneNode(true); + clonedPreset.classList.remove("ins_preset_template"); + clonedPreset.classList.add("ins_preset"); + + // Set the preset name in the element + clonedPreset.querySelector(".preset_name").textContent = presetName; + + // Add any additional logic or event listeners if needed + + // Append the cloned element to the preset box + presetBox.appendChild(clonedPreset); }); } From 94401e9cc020fd27c2b96b8a2d178882e526868d Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:04:56 +0700 Subject: [PATCH 06/76] second attempt --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index 0775804..5107aab 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1119,7 +1119,7 @@ class ARMMane{ clonePresetElements(presetNames) { const presetBox = this.elements["ui"]["preset_box"][0]; - const insPresetTemplate = this.elements["ui"]["ins_preset"][0]; + const insPresetTemplate = this.elements["ui"]["ins_preset"]; // Clear existing elements in the preset box presetBox.innerHTML = ""; From 8cfb28082ba794149c0dd9f3077bc25824a9b2b3 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:12:36 +0700 Subject: [PATCH 07/76] Third attempt --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index 5107aab..2a46411 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1125,7 +1125,7 @@ class ARMMane{ presetBox.innerHTML = ""; // Iterate through the preset names - presetNames.forEach((presetName, index) => { + presetNames.forEach((presetNames, index) => { const clonedPreset = insPresetTemplate.cloneNode(true); clonedPreset.classList.remove("ins_preset_template"); clonedPreset.classList.add("ins_preset"); From 64c6b8bb47f4f3591f2b6322453d807af75501ec Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:16:25 +0700 Subject: [PATCH 08/76] forth attempt --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index 2a46411..2c3b6fb 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1127,7 +1127,7 @@ class ARMMane{ // Iterate through the preset names presetNames.forEach((presetNames, index) => { const clonedPreset = insPresetTemplate.cloneNode(true); - clonedPreset.classList.remove("ins_preset_template"); + clonedPreset.classList.remove("ins_preset"); clonedPreset.classList.add("ins_preset"); // Set the preset name in the element From 44506a23854419133e6132f11113dd2f002e4ed3 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:20:09 +0700 Subject: [PATCH 09/76] fifth attempt --- main-dev.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main-dev.js b/main-dev.js index 2c3b6fb..d0088c2 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1125,9 +1125,8 @@ class ARMMane{ presetBox.innerHTML = ""; // Iterate through the preset names - presetNames.forEach((presetNames, index) => { + presetNames.forEach((presetName, index) => { const clonedPreset = insPresetTemplate.cloneNode(true); - clonedPreset.classList.remove("ins_preset"); clonedPreset.classList.add("ins_preset"); // Set the preset name in the element From b77a93db601bd6f591c357c5b5c6f88294db7378 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:23:28 +0700 Subject: [PATCH 10/76] sixth attempt --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index d0088c2..e538554 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1119,7 +1119,7 @@ class ARMMane{ clonePresetElements(presetNames) { const presetBox = this.elements["ui"]["preset_box"][0]; - const insPresetTemplate = this.elements["ui"]["ins_preset"]; + const insPresetTemplate = this.elements["ui"]["ins_preset"][0]; // Clear existing elements in the preset box presetBox.innerHTML = ""; From ed0f41cbe2138af600f531c0d21ca7cbfd8a2b3b Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:26:09 +0700 Subject: [PATCH 11/76] 7th attempt --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index e538554..56f7c5d 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1130,7 +1130,7 @@ class ARMMane{ clonedPreset.classList.add("ins_preset"); // Set the preset name in the element - clonedPreset.querySelector(".preset_name").textContent = presetName; + clonedPreset.querySelector("h4").textContent = presetName; // Add any additional logic or event listeners if needed From a442fd51a15bd1fe3d7fddea5878d9af48c22b97 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:29:53 +0700 Subject: [PATCH 12/76] 8th attempt --- main-dev.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main-dev.js b/main-dev.js index 56f7c5d..7adfe69 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1119,14 +1119,14 @@ class ARMMane{ clonePresetElements(presetNames) { const presetBox = this.elements["ui"]["preset_box"][0]; - const insPresetTemplate = this.elements["ui"]["ins_preset"][0]; + const insPresetTemplate = this.elements["template"]["ins_preset"][0]; // Clear existing elements in the preset box presetBox.innerHTML = ""; // Iterate through the preset names presetNames.forEach((presetName, index) => { - const clonedPreset = insPresetTemplate.cloneNode(true); + const clonedPreset = this.elements["template"]["ins_preset"].cloneNode(true); clonedPreset.classList.add("ins_preset"); // Set the preset name in the element From cdd79b669f2a80fe256b8e83efc35defae2ba1a3 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:36:35 +0700 Subject: [PATCH 13/76] hope copilot work --- main-dev.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/main-dev.js b/main-dev.js index 7adfe69..aadf6d4 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1118,24 +1118,24 @@ class ARMMane{ } clonePresetElements(presetNames) { - const presetBox = this.elements["ui"]["preset_box"][0]; - const insPresetTemplate = this.elements["template"]["ins_preset"][0]; - - // Clear existing elements in the preset box - presetBox.innerHTML = ""; + // Get the spawn area of the preset elements + const spawnArea = this.elements["ui"]["preset_box"][0].querySelector("div"); // Iterate through the preset names - presetNames.forEach((presetName, index) => { - const clonedPreset = this.elements["template"]["ins_preset"].cloneNode(true); - clonedPreset.classList.add("ins_preset"); + presetNames.forEach(presetName => { + // Clone the preset element template + const newDiv = this.elements["template"]["preset"][0].cloneNode(true); + const uniqueId = `preset_${presetName}`; + newDiv.id = uniqueId; - // Set the preset name in the element - clonedPreset.querySelector("h4").textContent = presetName; + // Add the preset name to the element + newDiv.querySelector(".tp-preset > div > h4").textContent = presetName; - // Add any additional logic or event listeners if needed + // Show the element + newDiv.style.display = "flex"; - // Append the cloned element to the preset box - presetBox.appendChild(clonedPreset); + // Add the element to the spawn area + spawnArea.appendChild(newDiv); }); } From 66fb253de0f85ec1eaa16f9588448a13f79e9751 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:39:58 +0700 Subject: [PATCH 14/76] wrong selector --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index aadf6d4..f976ad5 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1124,7 +1124,7 @@ class ARMMane{ // Iterate through the preset names presetNames.forEach(presetName => { // Clone the preset element template - const newDiv = this.elements["template"]["preset"][0].cloneNode(true); + const newDiv = this.elements["template"]["ins_preset"][0].cloneNode(true); const uniqueId = `preset_${presetName}`; newDiv.id = uniqueId; From 32da6d33ee0fdfcefb6d10a63d408e50ddbfd374 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:47:05 +0700 Subject: [PATCH 15/76] Hope this thing work --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index f976ad5..4b2b9b0 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1129,7 +1129,7 @@ class ARMMane{ newDiv.id = uniqueId; // Add the preset name to the element - newDiv.querySelector(".tp-preset > div > h4").textContent = presetName; + newDiv.querySelector(".ins-preset-box > div > h4").textContent = presetName; // Show the element newDiv.style.display = "flex"; From e7e49fba84e38429526c77ad532f8d97913f8dcb Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 15:26:22 +0700 Subject: [PATCH 16/76] plz god --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index 4b2b9b0..497fb34 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1129,7 +1129,7 @@ class ARMMane{ newDiv.id = uniqueId; // Add the preset name to the element - newDiv.querySelector(".ins-preset-box > div > h4").textContent = presetName; + newDiv.querySelector(".tp-ins-preset > div > h4").textContent = presetName; // Show the element newDiv.style.display = "flex"; From ee73ad93bfaf51132d744f69ef7153f07f1629e0 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 15:51:08 +0700 Subject: [PATCH 17/76] Update getPreset() --- main-dev.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/main-dev.js b/main-dev.js index 497fb34..da521f8 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1087,10 +1087,19 @@ class ARMMane{ // Extract preset names from the 'instructions' object const presetNames = Object.keys(instructions); - console.log("Preset Names:", presetNames); + // Iterate through preset names and extract step instructions + const presetsWithSteps = presetNames.map(presetName => { + const steps = instructions[presetName].step; + return { + presetName, + steps + }; + }); - // Resolve the promise with preset names - return presetNames; + console.log("Presets with Steps:", presetsWithSteps); + + // Resolve the promise with presets and step instructions + return presetsWithSteps; } else { console.error("Data format is invalid. Missing 'config' or 'instructions'."); throw new Error("Data format is invalid."); @@ -1105,6 +1114,7 @@ class ARMMane{ } } + async initializePresetElements() { try { // Get the preset names using getPreset() @@ -1138,6 +1148,8 @@ class ARMMane{ spawnArea.appendChild(newDiv); }); } + + From 6f468ad860ac28246e3f235e1e7d0156dbd01dc5 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:23:39 +0700 Subject: [PATCH 18/76] Try to make preset elements work --- main-dev.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index da521f8..2ee9ab2 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1020,7 +1020,7 @@ class ARMMane{ return clonedCodeBlock; } - attachCodeBlockEventListeners(clonedCodeBlock, newDiv) { + attachCodeBlockEventListeners(clonedCodeBlock, newDiv, codeBlock) { clonedCodeBlock.querySelector(".cmd-del").addEventListener("click", () => { clonedCodeBlock.remove(); }); @@ -1067,6 +1067,62 @@ class ARMMane{ } } + attachPresetClickEventListeners() { + const presetElements = this.elements["ui"]["preset_box"][0].querySelectorAll(".ins-preset"); + presetElements.forEach(presetElement => { + presetElement.addEventListener("click", () => { + this.handlePresetElementClick(presetElement); + }); + }); + } + + // Handle click on a preset element + handlePresetElementClick(presetElement) { + // Get the preset name associated with the clicked element + const presetName = presetElement.querySelector(".ins-preset-box > div > h4").textContent; + + // Find the preset in the presetsWithSteps array + const selectedPreset = this.presetsWithSteps.find(preset => preset.presetName === presetName); + + if (selectedPreset) { + // Clear existing code blocks + this.clearCodeBlocks(); + + // Create code blocks based on the step instructions + selectedPreset.steps.forEach(instruction => { + const codeBlock = this.createCodeBlockElement(instruction); + this.attachCodeBlockEventListeners(codeBlock); + this.addElementToSwimLane(codeBlock); + }); + } else { + console.error(`Preset with name '${presetName}' not found.`); + } + } + + addElementToSwimLane(element) { + const swimLane = this.elements["ui"]["command_area"][0]; + swimLane.appendChild(element); + } + + // Clear existing code blocks from the swim lane + clearCodeBlocks() { + const swimLane = this.elements["ui"]["command_area"][0]; + swimLane.innerHTML = ""; + } + + // Create a code block element based on an instruction + createCodeBlockElement(instruction) { + const codeBlock = this.elements["template"]["code_block"].cloneNode(true); + const codeBlockUniqueId = `code_block_${Date.now()}`; + codeBlock.id = codeBlockUniqueId; + codeBlock.style.display = "flex"; + + // Set the instruction as the code block content + codeBlock.querySelector(".cmd-text > div > h2").textContent = instruction; + + return codeBlock; + } + async getPreset() { try { // Send GET request to {server}/config From 311b2ded5ba73bf10e1f50f232ac6f0aea43e770 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:29:57 +0700 Subject: [PATCH 19/76] Revert "Try to make preset elements work" This reverts commit 6f468ad860ac28246e3f235e1e7d0156dbd01dc5. --- main-dev.js | 58 +---------------------------------------------------- 1 file changed, 1 insertion(+), 57 deletions(-) diff --git a/main-dev.js b/main-dev.js index 2ee9ab2..da521f8 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1020,7 +1020,7 @@ class ARMMane{ return clonedCodeBlock; } - attachCodeBlockEventListeners(clonedCodeBlock, newDiv, codeBlock) { + attachCodeBlockEventListeners(clonedCodeBlock, newDiv) { clonedCodeBlock.querySelector(".cmd-del").addEventListener("click", () => { clonedCodeBlock.remove(); }); @@ -1067,62 +1067,6 @@ class ARMMane{ } } - attachPresetClickEventListeners() { - const presetElements = this.elements["ui"]["preset_box"][0].querySelectorAll(".ins-preset"); - presetElements.forEach(presetElement => { - presetElement.addEventListener("click", () => { - this.handlePresetElementClick(presetElement); - }); - }); - } - - // Handle click on a preset element - handlePresetElementClick(presetElement) { - // Get the preset name associated with the clicked element - const presetName = presetElement.querySelector(".ins-preset-box > div > h4").textContent; - - // Find the preset in the presetsWithSteps array - const selectedPreset = this.presetsWithSteps.find(preset => preset.presetName === presetName); - - if (selectedPreset) { - // Clear existing code blocks - this.clearCodeBlocks(); - - // Create code blocks based on the step instructions - selectedPreset.steps.forEach(instruction => { - const codeBlock = this.createCodeBlockElement(instruction); - this.attachCodeBlockEventListeners(codeBlock); - this.addElementToSwimLane(codeBlock); - }); - } else { - console.error(`Preset with name '${presetName}' not found.`); - } - } - - addElementToSwimLane(element) { - const swimLane = this.elements["ui"]["command_area"][0]; - swimLane.appendChild(element); - } - - // Clear existing code blocks from the swim lane - clearCodeBlocks() { - const swimLane = this.elements["ui"]["command_area"][0]; - swimLane.innerHTML = ""; - } - - // Create a code block element based on an instruction - createCodeBlockElement(instruction) { - const codeBlock = this.elements["template"]["code_block"].cloneNode(true); - const codeBlockUniqueId = `code_block_${Date.now()}`; - codeBlock.id = codeBlockUniqueId; - codeBlock.style.display = "flex"; - - // Set the instruction as the code block content - codeBlock.querySelector(".cmd-text > div > h2").textContent = instruction; - - return codeBlock; - } - async getPreset() { try { // Send GET request to {server}/config From 159bc91c38c2bbfb24a78b6ce91b748ba47cd5f0 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:37:11 +0700 Subject: [PATCH 20/76] fix preset name --- main-dev.js | 1 + 1 file changed, 1 insertion(+) diff --git a/main-dev.js b/main-dev.js index da521f8..2154861 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1100,6 +1100,7 @@ class ARMMane{ // Resolve the promise with presets and step instructions return presetsWithSteps; + return presetNames; } else { console.error("Data format is invalid. Missing 'config' or 'instructions'."); throw new Error("Data format is invalid."); From 1ed787c07fb30ca6f4c474c5dffb042ba5595a21 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:40:51 +0700 Subject: [PATCH 21/76] still trying --- main-dev.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main-dev.js b/main-dev.js index 2154861..7ed0cf6 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1100,7 +1100,6 @@ class ARMMane{ // Resolve the promise with presets and step instructions return presetsWithSteps; - return presetNames; } else { console.error("Data format is invalid. Missing 'config' or 'instructions'."); throw new Error("Data format is invalid."); @@ -1118,8 +1117,12 @@ class ARMMane{ async initializePresetElements() { try { - // Get the preset names using getPreset() - const presetNames = await this.getPreset(); + // Get the preset names with steps using getPreset() + const presetsWithSteps = await this.getPreset(); + + // Extract and display only the preset names + const presetNames = presetsWithSteps.map(preset => preset.presetName); + console.log("Preset Names:", presetNames); // Call clonePresetElements to populate the preset elements this.clonePresetElements(presetNames); From 5aca4b0fc6f538cffa34c6ef082c08685edfa6b3 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:54:28 +0700 Subject: [PATCH 22/76] Put initializePresetElements() in init --- main-dev.js | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index 7ed0cf6..e353d68 100644 --- a/main-dev.js +++ b/main-dev.js @@ -211,6 +211,8 @@ class ARMMane{ this.createDraggableList(this.elements["ui"]["function_box"][0].querySelector("div")); this.initializeSortable(); + + this.initializePresetElements(); } @@ -1020,7 +1022,7 @@ class ARMMane{ return clonedCodeBlock; } - attachCodeBlockEventListeners(clonedCodeBlock, newDiv) { + attachCodeBlockEventListeners(clonedCodeBlock, newDiv, codeBlock) { clonedCodeBlock.querySelector(".cmd-del").addEventListener("click", () => { clonedCodeBlock.remove(); }); @@ -1031,6 +1033,16 @@ class ARMMane{ clonedCodeBlock.querySelector(".cmd-play").addEventListener("click", () => { this.consoleLog("「ARMMANE」 Run command"); }); + codeBlock.querySelector(".cmd-edit").addEventListener("click", () => { + this.consoleLog("「ARMMANE」 Edit command"); + this.openConfigBox(codeBlock.id); + }); + codeBlock.querySelector(".cmd-play").addEventListener("click", () => { + this.consoleLog("「ARMMANE」 Run command"); + }); + codeBlock.querySelector(".cmd-del").addEventListener("click", () => { + codeBlock.remove(); + }); clonedCodeBlock.setAttribute("data-type", newDiv.type); clonedCodeBlock.setAttribute("data-value", newDiv.value); @@ -1153,6 +1165,64 @@ class ARMMane{ }); } + // Add an event listener to preset elements + attachPresetClickEventListeners() { + const presetElements = this.elements["ui"]["preset_box"][0].querySelectorAll(".ins-preset"); + presetElements.forEach(presetElement => { + presetElement.addEventListener("click", () => { + this.handlePresetElementClick(presetElement); + }); + }); + } + + // Handle click on a preset element + handlePresetElementClick(presetElement) { + // Get the preset name associated with the clicked element + const presetName = presetElement.querySelector(".ins-preset-box > div > h4").textContent; + + // Find the preset in the presetsWithSteps array + const selectedPreset = this.presetsWithSteps.find(preset => preset.presetName === presetName); + + if (selectedPreset) { + // Clear existing code blocks + this.clearCodeBlocks(); + + // Create code blocks based on the step instructions + selectedPreset.steps.forEach(instruction => { + const codeBlock = this.createCodeBlockElement(instruction); + this.attachCodeBlockEventListeners(codeBlock); + this.addElementToSwimLane(codeBlock); + }); + } else { + console.error(`Preset with name '${presetName}' not found.`); + } + } + + // Clear existing code blocks from the swim lane + clearCodeBlocks() { + const swimLane = this.elements["ui"]["command_area"][0]; + swimLane.innerHTML = ""; + } + + // Create a code block element based on an instruction + createCodeBlockElement(instruction) { + const codeBlock = this.elements["template"]["code_block"].cloneNode(true); + const codeBlockUniqueId = `code_block_${Date.now()}`; + codeBlock.id = codeBlockUniqueId; + codeBlock.style.display = "flex"; + + // Set the instruction as the code block content + codeBlock.querySelector(".cmd-text > div > h2").textContent = instruction; + + return codeBlock; + } + + // Add a code block element to the swim lane + addElementToSwimLane(element) { + const swimLane = this.elements["ui"]["command_area"][0]; + swimLane.appendChild(element); + } + From dfc202f299a4712fae1070970975cb57fa020ee9 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:57:55 +0700 Subject: [PATCH 23/76] remove edit in codeBlock --- main-dev.js | 1 - 1 file changed, 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index e353d68..6ba048b 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1035,7 +1035,6 @@ class ARMMane{ }); codeBlock.querySelector(".cmd-edit").addEventListener("click", () => { this.consoleLog("「ARMMANE」 Edit command"); - this.openConfigBox(codeBlock.id); }); codeBlock.querySelector(".cmd-play").addEventListener("click", () => { this.consoleLog("「ARMMANE」 Run command"); From a6d7e461667a760dc232624273b8a9e996a3b522 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:00:36 +0700 Subject: [PATCH 24/76] comment out error --- main-dev.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/main-dev.js b/main-dev.js index 6ba048b..9551851 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1033,15 +1033,16 @@ class ARMMane{ clonedCodeBlock.querySelector(".cmd-play").addEventListener("click", () => { this.consoleLog("「ARMMANE」 Run command"); }); - codeBlock.querySelector(".cmd-edit").addEventListener("click", () => { - this.consoleLog("「ARMMANE」 Edit command"); - }); - codeBlock.querySelector(".cmd-play").addEventListener("click", () => { - this.consoleLog("「ARMMANE」 Run command"); - }); - codeBlock.querySelector(".cmd-del").addEventListener("click", () => { - codeBlock.remove(); - }); + // codeBlock.querySelector(".cmd-edit").addEventListener("click", () => { + // this.consoleLog("「ARMMANE」 Edit command"); + // this.openConfigBox(clonedCodeBlock.id); + // }); + // codeBlock.querySelector(".cmd-play").addEventListener("click", () => { + // this.consoleLog("「ARMMANE」 Run command"); + // }); + // codeBlock.querySelector(".cmd-del").addEventListener("click", () => { + // codeBlock.remove(); + // }); clonedCodeBlock.setAttribute("data-type", newDiv.type); clonedCodeBlock.setAttribute("data-value", newDiv.value); From bfcd4aa2b53cebcc39d532c9218b5dee105641ad Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:10:33 +0700 Subject: [PATCH 25/76] Make it back to normal --- main-dev.js | 61 ----------------------------------------------------- 1 file changed, 61 deletions(-) diff --git a/main-dev.js b/main-dev.js index 9551851..9bc13fa 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1035,7 +1035,6 @@ class ARMMane{ }); // codeBlock.querySelector(".cmd-edit").addEventListener("click", () => { // this.consoleLog("「ARMMANE」 Edit command"); - // this.openConfigBox(clonedCodeBlock.id); // }); // codeBlock.querySelector(".cmd-play").addEventListener("click", () => { // this.consoleLog("「ARMMANE」 Run command"); @@ -1165,66 +1164,6 @@ class ARMMane{ }); } - // Add an event listener to preset elements - attachPresetClickEventListeners() { - const presetElements = this.elements["ui"]["preset_box"][0].querySelectorAll(".ins-preset"); - presetElements.forEach(presetElement => { - presetElement.addEventListener("click", () => { - this.handlePresetElementClick(presetElement); - }); - }); - } - - // Handle click on a preset element - handlePresetElementClick(presetElement) { - // Get the preset name associated with the clicked element - const presetName = presetElement.querySelector(".ins-preset-box > div > h4").textContent; - - // Find the preset in the presetsWithSteps array - const selectedPreset = this.presetsWithSteps.find(preset => preset.presetName === presetName); - - if (selectedPreset) { - // Clear existing code blocks - this.clearCodeBlocks(); - - // Create code blocks based on the step instructions - selectedPreset.steps.forEach(instruction => { - const codeBlock = this.createCodeBlockElement(instruction); - this.attachCodeBlockEventListeners(codeBlock); - this.addElementToSwimLane(codeBlock); - }); - } else { - console.error(`Preset with name '${presetName}' not found.`); - } - } - - // Clear existing code blocks from the swim lane - clearCodeBlocks() { - const swimLane = this.elements["ui"]["command_area"][0]; - swimLane.innerHTML = ""; - } - - // Create a code block element based on an instruction - createCodeBlockElement(instruction) { - const codeBlock = this.elements["template"]["code_block"].cloneNode(true); - const codeBlockUniqueId = `code_block_${Date.now()}`; - codeBlock.id = codeBlockUniqueId; - codeBlock.style.display = "flex"; - - // Set the instruction as the code block content - codeBlock.querySelector(".cmd-text > div > h2").textContent = instruction; - - return codeBlock; - } - - // Add a code block element to the swim lane - addElementToSwimLane(element) { - const swimLane = this.elements["ui"]["command_area"][0]; - swimLane.appendChild(element); - } - - - //This will change the property of the element after click save button From c4b7f3ca3caea08ddefebd1ce5e9dda4219bd0d2 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:15:09 +0700 Subject: [PATCH 26/76] try to get the step --- main-dev.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/main-dev.js b/main-dev.js index 9bc13fa..f0a0770 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1128,26 +1128,24 @@ class ARMMane{ async initializePresetElements() { try { - // Get the preset names with steps using getPreset() + // Get the presets with steps using getPreset() const presetsWithSteps = await this.getPreset(); - // Extract and display only the preset names - const presetNames = presetsWithSteps.map(preset => preset.presetName); - console.log("Preset Names:", presetNames); - // Call clonePresetElements to populate the preset elements - this.clonePresetElements(presetNames); + this.clonePresetElements(presetsWithSteps); } catch (error) { console.error("Error:", error); } } - clonePresetElements(presetNames) { + clonePresetElements(presetsWithSteps) { // Get the spawn area of the preset elements const spawnArea = this.elements["ui"]["preset_box"][0].querySelector("div"); - // Iterate through the preset names - presetNames.forEach(presetName => { + // Iterate through the presets with steps + presetsWithSteps.forEach(preset => { + const { presetName, steps } = preset; + // Clone the preset element template const newDiv = this.elements["template"]["ins_preset"][0].cloneNode(true); const uniqueId = `preset_${presetName}`; @@ -1161,6 +1159,9 @@ class ARMMane{ // Add the element to the spawn area spawnArea.appendChild(newDiv); + + // Log the step instructions for this preset + console.log(`Step Instructions for ${presetName}:`, steps); }); } From c0ed59f204fbb39d141190755c340f6cf98a79e3 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:24:38 +0700 Subject: [PATCH 27/76] update initializePresetElements() --- main-dev.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/main-dev.js b/main-dev.js index f0a0770..18352e9 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1033,15 +1033,6 @@ class ARMMane{ clonedCodeBlock.querySelector(".cmd-play").addEventListener("click", () => { this.consoleLog("「ARMMANE」 Run command"); }); - // codeBlock.querySelector(".cmd-edit").addEventListener("click", () => { - // this.consoleLog("「ARMMANE」 Edit command"); - // }); - // codeBlock.querySelector(".cmd-play").addEventListener("click", () => { - // this.consoleLog("「ARMMANE」 Run command"); - // }); - // codeBlock.querySelector(".cmd-del").addEventListener("click", () => { - // codeBlock.remove(); - // }); clonedCodeBlock.setAttribute("data-type", newDiv.type); clonedCodeBlock.setAttribute("data-value", newDiv.value); @@ -1133,11 +1124,25 @@ class ARMMane{ // Call clonePresetElements to populate the preset elements this.clonePresetElements(presetsWithSteps); + + // Assuming you have a list of elements in "ins-preset-box" + const insPresetElements = document.querySelectorAll(".ins-preset"); + + // Attach a click event listener to each ins-preset element + insPresetElements.forEach(insPreset => { + insPreset.addEventListener("click", () => { + // Call the existing function to clone the code block when an ins-preset is clicked + const newDiv = this.createFunctionElement(/* provide the index or other data needed */); + // You may need to customize the newDiv based on the ins-preset that was clicked + this.cloneCodeBlockElement(newDiv); // Call the existing function + }); + }); } catch (error) { console.error("Error:", error); } } + clonePresetElements(presetsWithSteps) { // Get the spawn area of the preset elements const spawnArea = this.elements["ui"]["preset_box"][0].querySelector("div"); From 1bb6d8c3f9a8d148f44c01ae31927d7c09954159 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:28:03 +0700 Subject: [PATCH 28/76] add debug line --- main-dev.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index 18352e9..e382398 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1132,7 +1132,8 @@ class ARMMane{ insPresetElements.forEach(insPreset => { insPreset.addEventListener("click", () => { // Call the existing function to clone the code block when an ins-preset is clicked - const newDiv = this.createFunctionElement(/* provide the index or other data needed */); + console.log("Clicked on an ins-preset element"); + const newDiv = this.createFunctionElement(); // You may need to customize the newDiv based on the ins-preset that was clicked this.cloneCodeBlockElement(newDiv); // Call the existing function }); From c3bacc3cd86076240ed2b146a5b977a2b374b09e Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:31:54 +0700 Subject: [PATCH 29/76] add tp --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index e382398..48ad057 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1126,7 +1126,7 @@ class ARMMane{ this.clonePresetElements(presetsWithSteps); // Assuming you have a list of elements in "ins-preset-box" - const insPresetElements = document.querySelectorAll(".ins-preset"); + const insPresetElements = document.querySelectorAll(".tp-ins-preset"); // Attach a click event listener to each ins-preset element insPresetElements.forEach(insPreset => { From 52a8f8bf739c2c6eb4cf0df6941640e09fc3eabb Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:34:16 +0700 Subject: [PATCH 30/76] Pass the index --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index 48ad057..d1d1ce3 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1133,7 +1133,7 @@ class ARMMane{ insPreset.addEventListener("click", () => { // Call the existing function to clone the code block when an ins-preset is clicked console.log("Clicked on an ins-preset element"); - const newDiv = this.createFunctionElement(); + const newDiv = this.createFunctionElement(index); // You may need to customize the newDiv based on the ins-preset that was clicked this.cloneCodeBlockElement(newDiv); // Call the existing function }); From f7f1cad7dffbf8e78db3980e65a338098f57257d Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:37:35 +0700 Subject: [PATCH 31/76] add index --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index d1d1ce3..180e249 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1129,7 +1129,7 @@ class ARMMane{ const insPresetElements = document.querySelectorAll(".tp-ins-preset"); // Attach a click event listener to each ins-preset element - insPresetElements.forEach(insPreset => { + insPresetElements.forEach((insPreset, index) => { insPreset.addEventListener("click", () => { // Call the existing function to clone the code block when an ins-preset is clicked console.log("Clicked on an ins-preset element"); From 6bead52a825395a0101473b9507dec1aba11784f Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:42:18 +0700 Subject: [PATCH 32/76] add self --- main-dev.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/main-dev.js b/main-dev.js index 180e249..0458514 100644 --- a/main-dev.js +++ b/main-dev.js @@ -966,15 +966,18 @@ class ARMMane{ createDraggableList() { const spawnArea = this.elements["ui"]["function_box"][0].querySelector("div"); - + + // Capture 'this' in another variable for use inside the event listener + const self = this; + for (let i = 0; i < this.conf_list.length; i++) { const newDiv = this.createFunctionElement(i); - - newDiv.addEventListener("click", () => { - this.handleFunctionElementClick(newDiv); - + + newDiv.addEventListener("click", function() { + // Inside this function, use 'self' instead of 'this' + self.handleFunctionElementClick(newDiv); }); - + spawnArea.appendChild(newDiv); } } From 39b76a1872f477d8df5afe06e364013925c27ec0 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:57:22 +0700 Subject: [PATCH 33/76] Add translateInstruction() --- main-dev.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index 0458514..45d5ea7 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1094,7 +1094,13 @@ class ARMMane{ // Iterate through preset names and extract step instructions const presetsWithSteps = presetNames.map(presetName => { - const steps = instructions[presetName].step; + const steps = instructions[presetName].step.map(step => { + // Translate each step instruction + const translatedStep = this.translateInstruction(step); + console.log(translatedStep); // Print the translated step + return translatedStep; + }); + return { presetName, steps @@ -1119,6 +1125,28 @@ class ARMMane{ } } + // Add the translateInstruction function to your class + translateInstruction(instruction) { + const type = instruction[0]; + const id = parseInt(instruction[1]); + const mode = parseInt(instruction[2]); + const value = parseInt(instruction.substring(3)); + + let command; + + if (type === 'C') { + command = `setConv(${id},${value});`; + } else if (type === 'S') { + command = `setServo(${id},${value});`; + } else { + // Handle unsupported instruction type + command = `Unsupported instruction type: ${type}`; + } + + return command; + } + + async initializePresetElements() { try { From 7c55c1e15bea3ac35ff80e741e86e71ac4a80772 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 18:05:09 +0700 Subject: [PATCH 34/76] Fix translateInstruction() --- main-dev.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/main-dev.js b/main-dev.js index 45d5ea7..0f58170 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1125,26 +1125,25 @@ class ARMMane{ } } + // Add the translateInstruction function to your class // Add the translateInstruction function to your class translateInstruction(instruction) { const type = instruction[0]; const id = parseInt(instruction[1]); - const mode = parseInt(instruction[2]); - const value = parseInt(instruction.substring(3)); - - let command; - - if (type === 'C') { - command = `setConv(${id},${value});`; - } else if (type === 'S') { - command = `setServo(${id},${value});`; + + if (type === 'S') { + const degree = parseInt(instruction.substring(3)); + return `setServo(${id},${degree});`; + } else if (type === 'C') { + const mode = parseInt(instruction[2]); + const speed = parseInt(instruction.substring(3)); + return `setConV(${id},${mode},${speed});`; } else { // Handle unsupported instruction type - command = `Unsupported instruction type: ${type}`; + return `Unsupported instruction type: ${type}`; } - - return command; } + From 50fc319da3dffbe267770efa4fa56b0a78041203 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 18:10:49 +0700 Subject: [PATCH 35/76] atill fixing translateInstruction() --- main-dev.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/main-dev.js b/main-dev.js index 0f58170..30bb329 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1129,14 +1129,15 @@ class ARMMane{ // Add the translateInstruction function to your class translateInstruction(instruction) { const type = instruction[0]; - const id = parseInt(instruction[1]); if (type === 'S') { - const degree = parseInt(instruction.substring(3)); + const id = parseInt(instruction[2]); + const degree = parseInt(instruction.substring(4)); return `setServo(${id},${degree});`; } else if (type === 'C') { - const mode = parseInt(instruction[2]); - const speed = parseInt(instruction.substring(3)); + const id = parseInt(instruction[1]); + const mode = parseInt(instruction[3]); + const speed = parseInt(instruction.substring(5)); return `setConV(${id},${mode},${speed});`; } else { // Handle unsupported instruction type From 1900f28576717b7c0f3e83b81d8304ca462fbe2a Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 18:20:37 +0700 Subject: [PATCH 36/76] Make initializePresetElements() better I guess --- main-dev.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/main-dev.js b/main-dev.js index 30bb329..72c2276 100644 --- a/main-dev.js +++ b/main-dev.js @@ -940,7 +940,7 @@ class ARMMane{ direction: 'vertical', // Only vertical sorting }); } - + getData(element_name="ins-command-area",code_block="tp-ins-code-block") { const commandArea = this.querySel("." + element_name); @@ -1157,17 +1157,21 @@ class ARMMane{ this.clonePresetElements(presetsWithSteps); // Assuming you have a list of elements in "ins-preset-box" - const insPresetElements = document.querySelectorAll(".tp-ins-preset"); + const insPresetBox = document.querySelector(".ins-preset-box"); + + // Attach a single click event listener to the parent element (insPresetBox) + insPresetBox.addEventListener("click", (event) => { + // Check if the clicked element is an "ins-preset" + if (event.target.classList.contains("tp-ins-preset")) { + // Find the index of the clicked ins-preset element (you may need to customize this logic) + const index = Array.from(insPresetBox.children).indexOf(event.target); - // Attach a click event listener to each ins-preset element - insPresetElements.forEach((insPreset, index) => { - insPreset.addEventListener("click", () => { // Call the existing function to clone the code block when an ins-preset is clicked console.log("Clicked on an ins-preset element"); const newDiv = this.createFunctionElement(index); // You may need to customize the newDiv based on the ins-preset that was clicked this.cloneCodeBlockElement(newDiv); // Call the existing function - }); + } }); } catch (error) { console.error("Error:", error); @@ -1175,6 +1179,7 @@ class ARMMane{ } + clonePresetElements(presetsWithSteps) { // Get the spawn area of the preset elements const spawnArea = this.elements["ui"]["preset_box"][0].querySelector("div"); From c9a563f7cce564069f31934782f9cfa9f783a7cc Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 10 Oct 2023 18:55:53 +0700 Subject: [PATCH 37/76] Trying new thing --- main-dev.js | 51 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/main-dev.js b/main-dev.js index 72c2276..03c96ad 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1156,28 +1156,47 @@ class ARMMane{ // Call clonePresetElements to populate the preset elements this.clonePresetElements(presetsWithSteps); - // Assuming you have a list of elements in "ins-preset-box" - const insPresetBox = document.querySelector(".ins-preset-box"); - - // Attach a single click event listener to the parent element (insPresetBox) - insPresetBox.addEventListener("click", (event) => { - // Check if the clicked element is an "ins-preset" - if (event.target.classList.contains("tp-ins-preset")) { - // Find the index of the clicked ins-preset element (you may need to customize this logic) - const index = Array.from(insPresetBox.children).indexOf(event.target); - - // Call the existing function to clone the code block when an ins-preset is clicked - console.log("Clicked on an ins-preset element"); - const newDiv = this.createFunctionElement(index); - // You may need to customize the newDiv based on the ins-preset that was clicked - this.cloneCodeBlockElement(newDiv); // Call the existing function - } + // Add click event listeners to preset elements + const presetElements = document.querySelectorAll(".ins-preset"); + presetElements.forEach(presetElement => { + presetElement.addEventListener("click", () => { + this.handlePresetElementClick(presetElement); + }); }); } catch (error) { console.error("Error:", error); } } + async handlePresetElementClick(presetElement) { + try { + // Get the preset name from the clicked element + const presetName = presetElement.querySelector(".preset_name").textContent; + + // Get the presets with steps using getPreset() + const presetsWithSteps = await this.getPreset(); + + // Find the selected preset by name + const selectedPreset = presetsWithSteps.find(preset => preset.presetName === presetName); + + if (selectedPreset) { + // Clear existing code blocks (if any) + const swimLane = this.elements["ui"]["command_area"][0]; + swimLane.innerHTML = ""; + + // Append code blocks for each step + selectedPreset.steps.forEach((step, index) => { + const newDiv = this.cloneCodeBlockElement(presetElement); + newDiv.querySelector(".cmd-text > div > h2").textContent = this.translateInstruction(step); + swimLane.appendChild(newDiv); + }); + } + } catch (error) { + console.error("Error:", error); + } + } + + clonePresetElements(presetsWithSteps) { From d4b55c574b25ba8b2310b98c0f5497822794bb00 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Wed, 11 Oct 2023 13:06:34 +0700 Subject: [PATCH 38/76] Try to make handlePresetElementClick() work --- main-dev.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main-dev.js b/main-dev.js index 03c96ad..c442316 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1180,12 +1180,14 @@ class ARMMane{ const selectedPreset = presetsWithSteps.find(preset => preset.presetName === presetName); if (selectedPreset) { - // Clear existing code blocks (if any) + // Get the swim lane (the container for code blocks) const swimLane = this.elements["ui"]["command_area"][0]; + + // Clear existing code blocks by setting innerHTML to an empty string swimLane.innerHTML = ""; - // Append code blocks for each step - selectedPreset.steps.forEach((step, index) => { + // Iterate through the steps and append code blocks for each step + selectedPreset.steps.forEach(step => { const newDiv = this.cloneCodeBlockElement(presetElement); newDiv.querySelector(".cmd-text > div > h2").textContent = this.translateInstruction(step); swimLane.appendChild(newDiv); @@ -1199,6 +1201,7 @@ class ARMMane{ + clonePresetElements(presetsWithSteps) { // Get the spawn area of the preset elements const spawnArea = this.elements["ui"]["preset_box"][0].querySelector("div"); From 7ccce028fa42ac4aa60f445b68020be4f0cad90a Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Wed, 11 Oct 2023 13:18:08 +0700 Subject: [PATCH 39/76] add consoleLog --- main-dev.js | 1 + 1 file changed, 1 insertion(+) diff --git a/main-dev.js b/main-dev.js index c442316..d6af915 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1189,6 +1189,7 @@ class ARMMane{ // Iterate through the steps and append code blocks for each step selectedPreset.steps.forEach(step => { const newDiv = this.cloneCodeBlockElement(presetElement); + this.consoleLog("「ARMMANE」 Add command " + step); newDiv.querySelector(".cmd-text > div > h2").textContent = this.translateInstruction(step); swimLane.appendChild(newDiv); }); From a9cc163863a4290d1f717bdcb79cb2f1c0d89209 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Wed, 11 Oct 2023 13:24:02 +0700 Subject: [PATCH 40/76] remove async function --- main-dev.js | 86 +++++++++++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 49 deletions(-) diff --git a/main-dev.js b/main-dev.js index d6af915..4636e7d 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1072,60 +1072,49 @@ class ARMMane{ } } - async getPreset() { + getPreset(callback) { try { // Send GET request to {server}/config - const response = await fetch(`${this.serverURL}/config`, { + fetch(`${this.serverURL}/config`, { method: "GET", headers: { "Content-Type": "application/json" } - }); - - if (response.status === 200) { - const data = await response.json(); // Parse the response body as JSON - - // Check if 'config' and 'instructions' exist in the data + }).then((response) => { + if (response.status === 200) { + return response.json(); + } else { + this.consoleLog("Train request sent failed", "ERROR"); + throw new Error("Request failed with status: " + response.status); + } + }).then((data) => { if (data.config && data.config.instructions) { const instructions = data.config.instructions; - - // Extract preset names from the 'instructions' object const presetNames = Object.keys(instructions); - - // Iterate through preset names and extract step instructions const presetsWithSteps = presetNames.map(presetName => { - const steps = instructions[presetName].step.map(step => { - // Translate each step instruction - const translatedStep = this.translateInstruction(step); - console.log(translatedStep); // Print the translated step - return translatedStep; - }); - + const steps = instructions[presetName].step; return { presetName, steps }; }); - console.log("Presets with Steps:", presetsWithSteps); - - // Resolve the promise with presets and step instructions - return presetsWithSteps; + // Execute the provided callback function with the data + callback(presetsWithSteps); } else { console.error("Data format is invalid. Missing 'config' or 'instructions'."); throw new Error("Data format is invalid."); } - } else { - console.error("Train request sent failed", "ERROR"); - throw new Error("Request failed with status: " + response.status); - } + }).catch((error) => { + console.error("Error:", error); + throw error; + }); } catch (error) { console.error("Error:", error); - throw error; // Re-throw the error to propagate it + throw error; } } - // Add the translateInstruction function to your class // Add the translateInstruction function to your class translateInstruction(instruction) { const type = instruction[0]; @@ -1168,32 +1157,31 @@ class ARMMane{ } } - async handlePresetElementClick(presetElement) { + handlePresetElementClick(presetElement) { try { // Get the preset name from the clicked element const presetName = presetElement.querySelector(".preset_name").textContent; - // Get the presets with steps using getPreset() - const presetsWithSteps = await this.getPreset(); + // Fetch the preset data and provide a callback function + this.getPreset((presetsWithSteps) => { + // Find the selected preset by name + const selectedPreset = presetsWithSteps.find(preset => preset.presetName === presetName); - // Find the selected preset by name - const selectedPreset = presetsWithSteps.find(preset => preset.presetName === presetName); + if (selectedPreset) { + // Get the swim lane (the container for code blocks) + const swimLane = this.elements["ui"]["command_area"][0]; - if (selectedPreset) { - // Get the swim lane (the container for code blocks) - const swimLane = this.elements["ui"]["command_area"][0]; - - // Clear existing code blocks by setting innerHTML to an empty string - swimLane.innerHTML = ""; - - // Iterate through the steps and append code blocks for each step - selectedPreset.steps.forEach(step => { - const newDiv = this.cloneCodeBlockElement(presetElement); - this.consoleLog("「ARMMANE」 Add command " + step); - newDiv.querySelector(".cmd-text > div > h2").textContent = this.translateInstruction(step); - swimLane.appendChild(newDiv); - }); - } + // Clear existing code blocks by setting innerHTML to an empty string + swimLane.innerHTML = ""; + + // Iterate through the steps and append code blocks for each step + selectedPreset.steps.forEach(step => { + const newDiv = this.cloneCodeBlockElement(presetElement); + newDiv.querySelector(".cmd-text > div > h2").textContent = this.translateInstruction(step); + swimLane.appendChild(newDiv); + }); + } + }); } catch (error) { console.error("Error:", error); } From 8ae12db82ed80b038767610ee8e44de27b83c12d Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Wed, 11 Oct 2023 13:29:28 +0700 Subject: [PATCH 41/76] fully remove async --- main-dev.js | 61 +++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/main-dev.js b/main-dev.js index 4636e7d..8923eb9 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1072,22 +1072,23 @@ class ARMMane{ } } - getPreset(callback) { - try { - // Send GET request to {server}/config - fetch(`${this.serverURL}/config`, { - method: "GET", - headers: { - "Content-Type": "application/json" - } - }).then((response) => { + getPreset() { + // Return the promise for the fetch operation + return fetch(`${this.serverURL}/config`, { + method: "GET", + headers: { + "Content-Type": "application/json" + } + }) + .then((response) => { if (response.status === 200) { return response.json(); } else { this.consoleLog("Train request sent failed", "ERROR"); throw new Error("Request failed with status: " + response.status); } - }).then((data) => { + }) + .then((data) => { if (data.config && data.config.instructions) { const instructions = data.config.instructions; const presetNames = Object.keys(instructions); @@ -1099,20 +1100,16 @@ class ARMMane{ }; }); console.log("Presets with Steps:", presetsWithSteps); - // Execute the provided callback function with the data - callback(presetsWithSteps); + return presetsWithSteps; } else { console.error("Data format is invalid. Missing 'config' or 'instructions'."); throw new Error("Data format is invalid."); } - }).catch((error) => { + }) + .catch((error) => { console.error("Error:", error); throw error; }); - } catch (error) { - console.error("Error:", error); - throw error; - } } // Add the translateInstruction function to your class @@ -1137,24 +1134,24 @@ class ARMMane{ - async initializePresetElements() { - try { - // Get the presets with steps using getPreset() - const presetsWithSteps = await this.getPreset(); - - // Call clonePresetElements to populate the preset elements - this.clonePresetElements(presetsWithSteps); + initializePresetElements() { + // Get the presets with steps using getPreset() + this.getPreset() + .then((presetsWithSteps) => { + // Call clonePresetElements to populate the preset elements + this.clonePresetElements(presetsWithSteps); - // Add click event listeners to preset elements - const presetElements = document.querySelectorAll(".ins-preset"); - presetElements.forEach(presetElement => { - presetElement.addEventListener("click", () => { - this.handlePresetElementClick(presetElement); + // Add click event listeners to preset elements + const presetElements = document.querySelectorAll(".ins-preset"); + presetElements.forEach(presetElement => { + presetElement.addEventListener("click", () => { + this.handlePresetElementClick(presetElement); + }); }); + }) + .catch((error) => { + console.error("Error:", error); }); - } catch (error) { - console.error("Error:", error); - } } handlePresetElementClick(presetElement) { From 78b75fd7f09b890771c852bc536238b75e752967 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Wed, 11 Oct 2023 13:35:14 +0700 Subject: [PATCH 42/76] add EventListener --- main-dev.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main-dev.js b/main-dev.js index 8923eb9..9e29cbb 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1206,6 +1206,10 @@ class ARMMane{ // Show the element newDiv.style.display = "flex"; + + newDiv.addEventListener("click", () => { + this.handlePresetElementClick(newDiv); + }); // Add the element to the spawn area spawnArea.appendChild(newDiv); From 5e9e55e10a46461234f706a774cdc52d21730981 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Wed, 11 Oct 2023 14:12:12 +0700 Subject: [PATCH 43/76] Add findPresetByName() --- main-dev.js | 82 +++++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/main-dev.js b/main-dev.js index 9e29cbb..aae8efc 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1135,56 +1135,69 @@ class ARMMane{ initializePresetElements() { - // Get the presets with steps using getPreset() - this.getPreset() - .then((presetsWithSteps) => { + try { + // Get the presets with steps using getPreset() + this.getPreset(presetsWithSteps => { // Call clonePresetElements to populate the preset elements this.clonePresetElements(presetsWithSteps); - + // Add click event listeners to preset elements const presetElements = document.querySelectorAll(".ins-preset"); presetElements.forEach(presetElement => { presetElement.addEventListener("click", () => { - this.handlePresetElementClick(presetElement); + const presetName = presetElement.getAttribute("data-preset-name"); + this.handlePresetElementClick(presetName); }); }); - }) - .catch((error) => { - console.error("Error:", error); }); + } catch (error) { + console.error("Error:", error); + } } - handlePresetElementClick(presetElement) { + handlePresetElementClick(presetName) { try { - // Get the preset name from the clicked element - const presetName = presetElement.querySelector(".preset_name").textContent; - - // Fetch the preset data and provide a callback function - this.getPreset((presetsWithSteps) => { - // Find the selected preset by name - const selectedPreset = presetsWithSteps.find(preset => preset.presetName === presetName); - - if (selectedPreset) { - // Get the swim lane (the container for code blocks) - const swimLane = this.elements["ui"]["command_area"][0]; - - // Clear existing code blocks by setting innerHTML to an empty string - swimLane.innerHTML = ""; - - // Iterate through the steps and append code blocks for each step - selectedPreset.steps.forEach(step => { - const newDiv = this.cloneCodeBlockElement(presetElement); - newDiv.querySelector(".cmd-text > div > h2").textContent = this.translateInstruction(step); - swimLane.appendChild(newDiv); - }); - } - }); + // Fetch the preset data based on the preset name + // (You may need to implement a search or filtering mechanism) + const selectedPreset = this.findPresetByName(presetName); + + if (selectedPreset) { + // Get the swim lane (the container for code blocks) + const swimLane = this.elements["ui"]["command_area"][0]; + + // Clear existing code blocks by setting innerHTML to an empty string + swimLane.innerHTML = ""; + + // Iterate through the steps and append code blocks for each step + selectedPreset.steps.forEach(step => { + const newDiv = this.cloneCodeBlockElement(presetElement); + newDiv.querySelector(".cmd-text > div > h2").textContent = this.translateInstruction(step); + swimLane.appendChild(newDiv); + }); + } } catch (error) { console.error("Error:", error); } } + findPresetByName(presetName) { + // Get all the preset elements + const presetElements = document.querySelectorAll(".ins-preset"); + // Iterate through the elements and find the one with a matching data-preset-name attribute + for (let i = 0; i < presetElements.length; i++) { + const element = presetElements[i]; + const elementPresetName = element.getAttribute("data-preset-name"); + + if (elementPresetName === presetName) { + // Match found, return the corresponding preset data + return presetsWithSteps.find(preset => preset.presetName === presetName); + } + } + + // If no match is found, return null or handle the case appropriately + return null; + } @@ -1206,11 +1219,6 @@ class ARMMane{ // Show the element newDiv.style.display = "flex"; - - newDiv.addEventListener("click", () => { - this.handlePresetElementClick(newDiv); - }); - // Add the element to the spawn area spawnArea.appendChild(newDiv); From ae88f0aef55c83a4488bf809d2e4f2dd00ad38a0 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Wed, 11 Oct 2023 14:16:12 +0700 Subject: [PATCH 44/76] fix findPresetByName() --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index aae8efc..1a8c8ed 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1191,7 +1191,7 @@ class ARMMane{ if (elementPresetName === presetName) { // Match found, return the corresponding preset data - return presetsWithSteps.find(preset => preset.presetName === presetName); + return element; } } From 6158293d7417c518f632cd85342eb6be4487bb3b Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Wed, 11 Oct 2023 14:33:29 +0700 Subject: [PATCH 45/76] Trying to fix it --- main-dev.js | 82 ++++++++++++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/main-dev.js b/main-dev.js index 1a8c8ed..9e29cbb 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1135,69 +1135,56 @@ class ARMMane{ initializePresetElements() { - try { - // Get the presets with steps using getPreset() - this.getPreset(presetsWithSteps => { + // Get the presets with steps using getPreset() + this.getPreset() + .then((presetsWithSteps) => { // Call clonePresetElements to populate the preset elements this.clonePresetElements(presetsWithSteps); - + // Add click event listeners to preset elements const presetElements = document.querySelectorAll(".ins-preset"); presetElements.forEach(presetElement => { presetElement.addEventListener("click", () => { - const presetName = presetElement.getAttribute("data-preset-name"); - this.handlePresetElementClick(presetName); + this.handlePresetElementClick(presetElement); }); }); + }) + .catch((error) => { + console.error("Error:", error); }); - } catch (error) { - console.error("Error:", error); - } } - handlePresetElementClick(presetName) { + handlePresetElementClick(presetElement) { try { - // Fetch the preset data based on the preset name - // (You may need to implement a search or filtering mechanism) - const selectedPreset = this.findPresetByName(presetName); - - if (selectedPreset) { - // Get the swim lane (the container for code blocks) - const swimLane = this.elements["ui"]["command_area"][0]; - - // Clear existing code blocks by setting innerHTML to an empty string - swimLane.innerHTML = ""; - - // Iterate through the steps and append code blocks for each step - selectedPreset.steps.forEach(step => { - const newDiv = this.cloneCodeBlockElement(presetElement); - newDiv.querySelector(".cmd-text > div > h2").textContent = this.translateInstruction(step); - swimLane.appendChild(newDiv); - }); - } + // Get the preset name from the clicked element + const presetName = presetElement.querySelector(".preset_name").textContent; + + // Fetch the preset data and provide a callback function + this.getPreset((presetsWithSteps) => { + // Find the selected preset by name + const selectedPreset = presetsWithSteps.find(preset => preset.presetName === presetName); + + if (selectedPreset) { + // Get the swim lane (the container for code blocks) + const swimLane = this.elements["ui"]["command_area"][0]; + + // Clear existing code blocks by setting innerHTML to an empty string + swimLane.innerHTML = ""; + + // Iterate through the steps and append code blocks for each step + selectedPreset.steps.forEach(step => { + const newDiv = this.cloneCodeBlockElement(presetElement); + newDiv.querySelector(".cmd-text > div > h2").textContent = this.translateInstruction(step); + swimLane.appendChild(newDiv); + }); + } + }); } catch (error) { console.error("Error:", error); } } - findPresetByName(presetName) { - // Get all the preset elements - const presetElements = document.querySelectorAll(".ins-preset"); - // Iterate through the elements and find the one with a matching data-preset-name attribute - for (let i = 0; i < presetElements.length; i++) { - const element = presetElements[i]; - const elementPresetName = element.getAttribute("data-preset-name"); - - if (elementPresetName === presetName) { - // Match found, return the corresponding preset data - return element; - } - } - - // If no match is found, return null or handle the case appropriately - return null; - } @@ -1219,6 +1206,11 @@ class ARMMane{ // Show the element newDiv.style.display = "flex"; + + newDiv.addEventListener("click", () => { + this.handlePresetElementClick(newDiv); + }); + // Add the element to the spawn area spawnArea.appendChild(newDiv); From 5beee932d78c8040e00ad00e1e56973b6ad6ef2f Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Wed, 11 Oct 2023 16:29:23 +0700 Subject: [PATCH 46/76] test new code --- main-dev.js | 121 ++++++++++++++++++++-------------------------------- 1 file changed, 46 insertions(+), 75 deletions(-) diff --git a/main-dev.js b/main-dev.js index 9e29cbb..498a480 100644 --- a/main-dev.js +++ b/main-dev.js @@ -982,6 +982,14 @@ class ARMMane{ } } + createPresetList() { + const spawnArea = this.element["ui"]["preset_box"][0].querySelector("div"); + + // Capture 'this' in another variable for use inside the event listener + const self = this; + + } + createFunctionElement(index) { const newDiv = this.elements["template"]["ins_function"][0].cloneNode(true); const uniqueId = `ins_function_${index}`; @@ -1025,7 +1033,7 @@ class ARMMane{ return clonedCodeBlock; } - attachCodeBlockEventListeners(clonedCodeBlock, newDiv, codeBlock) { + attachCodeBlockEventListeners(clonedCodeBlock, newDiv) { clonedCodeBlock.querySelector(".cmd-del").addEventListener("click", () => { clonedCodeBlock.remove(); }); @@ -1131,96 +1139,59 @@ class ARMMane{ } } + createPresetElements(presets) { + const spawnArea = this.elements["ui"]["preset_box"][0].querySelector("div"); + presets.forEach(preset => { + const newDiv = this.createPresetElement(preset.presetName); - - initializePresetElements() { - // Get the presets with steps using getPreset() - this.getPreset() - .then((presetsWithSteps) => { - // Call clonePresetElements to populate the preset elements - this.clonePresetElements(presetsWithSteps); - - // Add click event listeners to preset elements - const presetElements = document.querySelectorAll(".ins-preset"); - presetElements.forEach(presetElement => { - presetElement.addEventListener("click", () => { - this.handlePresetElementClick(presetElement); - }); - }); - }) - .catch((error) => { - console.error("Error:", error); + newDiv.addEventListener("click", () => { + this.handlePresetElementClick(newDiv); }); - } - - handlePresetElementClick(presetElement) { - try { - // Get the preset name from the clicked element - const presetName = presetElement.querySelector(".preset_name").textContent; - // Fetch the preset data and provide a callback function - this.getPreset((presetsWithSteps) => { - // Find the selected preset by name - const selectedPreset = presetsWithSteps.find(preset => preset.presetName === presetName); - - if (selectedPreset) { - // Get the swim lane (the container for code blocks) - const swimLane = this.elements["ui"]["command_area"][0]; - - // Clear existing code blocks by setting innerHTML to an empty string - swimLane.innerHTML = ""; - - // Iterate through the steps and append code blocks for each step - selectedPreset.steps.forEach(step => { - const newDiv = this.cloneCodeBlockElement(presetElement); - newDiv.querySelector(".cmd-text > div > h2").textContent = this.translateInstruction(step); - swimLane.appendChild(newDiv); - }); - } - }); - } catch (error) { - console.error("Error:", error); - } + spawnArea.appendChild(newDiv); + }); } + createPresetElement(presetName) { + const newDiv = this.createFunctionElement(presetName); // Reuse the existing createFunctionElement + newDiv.classList.remove("ins_function"); // Remove the "ins_function" class + newDiv.classList.add("ins-preset", "" + presetName); + newDiv.style.display = "flex"; + newDiv.querySelector(".tp-ins-func > div > h4").textContent = presetName; + newDiv.setAttribute("data-preset-name", presetName); + return newDiv; + } + createFunctionElement(name) { + const newDiv = this.elements["template"]["ins_function"][0].cloneNode(true); + const uniqueId = `ins_function_${name}`; + newDiv.id = uniqueId; + newDiv.querySelector(".tp-ins-func > div > h4").textContent = name; + newDiv.style.display = "flex"; + newDiv.setAttribute("data-preset-name", name); - clonePresetElements(presetsWithSteps) { - // Get the spawn area of the preset elements - const spawnArea = this.elements["ui"]["preset_box"][0].querySelector("div"); - - // Iterate through the presets with steps - presetsWithSteps.forEach(preset => { - const { presetName, steps } = preset; + return newDiv; + } - // Clone the preset element template - const newDiv = this.elements["template"]["ins_preset"][0].cloneNode(true); - const uniqueId = `preset_${presetName}`; - newDiv.id = uniqueId; + handlePresetElementClick(presetElement) { + const presetName = presetElement.getAttribute("data-preset-name"); + const presetSteps = findPresetStepsByName(presetName); // Implement this function - // Add the preset name to the element - newDiv.querySelector(".tp-ins-preset > div > h4").textContent = presetName; + if (presetSteps) { + const swimLane = this.elements["ui"]["command_area"][0]; + swimLane.innerHTML = ""; - // Show the element - newDiv.style.display = "flex"; - - newDiv.addEventListener("click", () => { - this.handlePresetElementClick(newDiv); + presetSteps.forEach(step => { + const newDiv = this.cloneCodeBlockElement(step); + newDiv.querySelector(".cmd-text > div > h2").textContent = this.translateInstruction(step); + swimLane.appendChild(newDiv); }); - - // Add the element to the spawn area - spawnArea.appendChild(newDiv); - - // Log the step instructions for this preset - console.log(`Step Instructions for ${presetName}:`, steps); - }); + } } - - //This will change the property of the element after click save button openConfigBox(element_name) { let element = document.getElementById(element_name); From dd483023a6b1fc2e51b384750ba183ae87f121df Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Wed, 11 Oct 2023 16:42:23 +0700 Subject: [PATCH 47/76] IDK --- main-dev.js | 83 ++++++++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 45 deletions(-) diff --git a/main-dev.js b/main-dev.js index 498a480..87e8821 100644 --- a/main-dev.js +++ b/main-dev.js @@ -212,7 +212,7 @@ class ARMMane{ this.initializeSortable(); - this.initializePresetElements(); + this.initialize() } @@ -982,14 +982,6 @@ class ARMMane{ } } - createPresetList() { - const spawnArea = this.element["ui"]["preset_box"][0].querySelector("div"); - - // Capture 'this' in another variable for use inside the event listener - const self = this; - - } - createFunctionElement(index) { const newDiv = this.elements["template"]["ins_function"][0].cloneNode(true); const uniqueId = `ins_function_${index}`; @@ -1139,57 +1131,58 @@ class ARMMane{ } } - createPresetElements(presets) { + createPresetList(presetsWithSteps) { const spawnArea = this.elements["ui"]["preset_box"][0].querySelector("div"); - - presets.forEach(preset => { - const newDiv = this.createPresetElement(preset.presetName); - - newDiv.addEventListener("click", () => { - this.handlePresetElementClick(newDiv); + + presetsWithSteps.forEach(preset => { + const newPresetElement = this.createPresetElement(preset.presetName); + newPresetElement.addEventListener("click", () => { + this.handlePresetElementClick(preset, newPresetElement); }); - spawnArea.appendChild(newDiv); + spawnArea.appendChild(newPresetElement); }); } createPresetElement(presetName) { - const newDiv = this.createFunctionElement(presetName); // Reuse the existing createFunctionElement - newDiv.classList.remove("ins_function"); // Remove the "ins_function" class - newDiv.classList.add("ins-preset", "" + presetName); - newDiv.style.display = "flex"; - newDiv.querySelector(".tp-ins-func > div > h4").textContent = presetName; - newDiv.setAttribute("data-preset-name", presetName); + const newPresetElement = this.elements["template"]["ins_preset"][0].cloneNode(true); + const uniqueId = `preset_${presetName}`; + newPresetElement.id = uniqueId; - return newDiv; - } + newPresetElement.classList.add("ins-preset", presetName); + newPresetElement.querySelector(".tp-ins-preset > div > h4").textContent = presetName; + newPresetElement.style.display = "flex"; + newPresetElement.setAttribute("data-preset-name", presetName); - createFunctionElement(name) { - const newDiv = this.elements["template"]["ins_function"][0].cloneNode(true); - const uniqueId = `ins_function_${name}`; - newDiv.id = uniqueId; + return newPresetElement; + } - newDiv.querySelector(".tp-ins-func > div > h4").textContent = name; - newDiv.style.display = "flex"; - newDiv.setAttribute("data-preset-name", name); + handlePresetElementClick(preset, newPresetElement) { + const swimLane = this.elements["ui"]["command_area"][0]; + swimLane.innerHTML = ""; - return newDiv; + preset.steps.forEach(step => { + const newDiv = this.cloneCodeBlockElement(); + newDiv.querySelector(".cmd-text > div > h2").textContent = this.translateInstruction(step); + swimLane.appendChild(newDiv); + }); } + + initialize() { + // Fetch the presets and steps + this.getPreset() + .then(presetsWithSteps => { + // Create the draggable list of elements + this.createDraggableList(); - handlePresetElementClick(presetElement) { - const presetName = presetElement.getAttribute("data-preset-name"); - const presetSteps = findPresetStepsByName(presetName); // Implement this function - - if (presetSteps) { - const swimLane = this.elements["ui"]["command_area"][0]; - swimLane.innerHTML = ""; + // Create the preset list in the preset_box + this.createPresetList(presetsWithSteps); - presetSteps.forEach(step => { - const newDiv = this.cloneCodeBlockElement(step); - newDiv.querySelector(".cmd-text > div > h2").textContent = this.translateInstruction(step); - swimLane.appendChild(newDiv); + // You can add other initialization code here. + }) + .catch(error => { + console.error("Error:", error); }); - } } //This will change the property of the element after click save button From 7a68a9df39c1a58cae5ae8d7298c232df83208df Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Wed, 11 Oct 2023 16:57:16 +0700 Subject: [PATCH 48/76] Add attachCodeBlockEventListeners() --- main-dev.js | 1 + 1 file changed, 1 insertion(+) diff --git a/main-dev.js b/main-dev.js index 87e8821..dd0961b 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1163,6 +1163,7 @@ class ARMMane{ preset.steps.forEach(step => { const newDiv = this.cloneCodeBlockElement(); + this.attachCodeBlockEventListeners(clonedCodeBlock, newDiv); newDiv.querySelector(".cmd-text > div > h2").textContent = this.translateInstruction(step); swimLane.appendChild(newDiv); }); From e0063cd86c29f11fe17c5f8ce356298d27e39f4d Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Wed, 11 Oct 2023 17:03:51 +0700 Subject: [PATCH 49/76] Update handlePresetElementClick() --- main-dev.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main-dev.js b/main-dev.js index dd0961b..ce998df 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1162,8 +1162,8 @@ class ARMMane{ swimLane.innerHTML = ""; preset.steps.forEach(step => { - const newDiv = this.cloneCodeBlockElement(); - this.attachCodeBlockEventListeners(clonedCodeBlock, newDiv); + const newDiv = this.cloneCodeBlockElement(newPresetElement); // Pass newPresetElement as an argument + this.attachCodeBlockEventListeners(newDiv, newPresetElement); // Pass newPresetElement as well newDiv.querySelector(".cmd-text > div > h2").textContent = this.translateInstruction(step); swimLane.appendChild(newDiv); }); From 8bddb408d163b31326219c0046c786c7a26a517f Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Wed, 11 Oct 2023 17:15:20 +0700 Subject: [PATCH 50/76] remove self --- main-dev.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/main-dev.js b/main-dev.js index ce998df..e9c4ed9 100644 --- a/main-dev.js +++ b/main-dev.js @@ -966,16 +966,13 @@ class ARMMane{ createDraggableList() { const spawnArea = this.elements["ui"]["function_box"][0].querySelector("div"); - - // Capture 'this' in another variable for use inside the event listener - const self = this; - + for (let i = 0; i < this.conf_list.length; i++) { const newDiv = this.createFunctionElement(i); newDiv.addEventListener("click", function() { // Inside this function, use 'self' instead of 'this' - self.handleFunctionElementClick(newDiv); + this.handleFunctionElementClick(newDiv); }); spawnArea.appendChild(newDiv); From e3b802f9d2e3588d10ce1b31d08488d8017d58b3 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Wed, 11 Oct 2023 17:17:14 +0700 Subject: [PATCH 51/76] Revert "remove self" This reverts commit 8bddb408d163b31326219c0046c786c7a26a517f. --- main-dev.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main-dev.js b/main-dev.js index e9c4ed9..ce998df 100644 --- a/main-dev.js +++ b/main-dev.js @@ -966,13 +966,16 @@ class ARMMane{ createDraggableList() { const spawnArea = this.elements["ui"]["function_box"][0].querySelector("div"); - + + // Capture 'this' in another variable for use inside the event listener + const self = this; + for (let i = 0; i < this.conf_list.length; i++) { const newDiv = this.createFunctionElement(i); newDiv.addEventListener("click", function() { // Inside this function, use 'self' instead of 'this' - this.handleFunctionElementClick(newDiv); + self.handleFunctionElementClick(newDiv); }); spawnArea.appendChild(newDiv); From 8b46ee3fa22a4b8ae9367433396e9bc2ba6faefc Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Wed, 11 Oct 2023 18:27:15 +0700 Subject: [PATCH 52/76] try to fix it --- main-dev.js | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/main-dev.js b/main-dev.js index df5e8db..df01d66 100644 --- a/main-dev.js +++ b/main-dev.js @@ -41,7 +41,6 @@ class ARMMane{ "port" : port, "protocol" : protocol, }, - "currentEditCodeBlock" : null, "currentScreen" : "screen_connect", "commandMode" : false, "manualControl" : false, // Trigger whwn manual control is active in 10 last second @@ -282,39 +281,6 @@ class ARMMane{ this.connect(); }); - // // Add event listener to save button - // this.elements["btn"]["cconf_btn_save"].addEventListener("click", saveButtonHandler); - - // // Add event listener to cancel button - // this.elements["btn"]["cconf_btn_cancel"].addEventListener("click", cancelButtonHandler); - // const saveButtonHandler = () => { - // element.setAttribute("data-type", this.elements["form"]["cconf_01"].value); - // element.setAttribute("data-device", this.elements["form"]["cconf_02"].value); - // element.setAttribute("data-value", this.elements["form"]["cconf_03"].value); - // this.consoleLog("「ARMMANE」 Command changed to " + this.elements["form"]["cconf_01"].value + "(" + this.elements["form"]["cconf_02"].value + "," + this.elements["form"]["cconf_03"].value + ");"); - // element.querySelector(".cmd-text > div > h2").textContent = this.elements["form"]["cconf_01"].value + "(" + this.elements["form"]["cconf_02"].value + "," + this.elements["form"]["cconf_03"].value + ");"; - // this.consoleLog("「ARMMANE」 Command changed to element " + element.id + " with value " + element.getAttribute("data-type") + "(" + element.getAttribute("data-device") + "," + element.getAttribute("data-value") + ");"); - // this.hideElement("ui", "cconfbox"); - // this.elements["btn"]["cconf_btn_save"].removeEventListener("click", saveButtonHandler); - // }; - - // const cancelButtonHandler = () => { - // this.hideElement("ui", "cconfbox"); - // this.elements["btn"]["cconf_btn_cancel"].removeEventListener("click", cancelButtonHandler); - // }; - - this.setTriggerEvent("btn", "cconf_btn_save", "click", () => { - var selectedElement = document.getElementById(this.appStatus["currentEditCodeBlock"]); - selectedElement.setAttribute("data-type", this.elements["form"]["cconf_01"].value); - selectedElement.setAttribute("data-device", this.elements["form"]["cconf_02"].value); - selectedElement.setAttribute("data-value", this.elements["form"]["cconf_03"].value); - this.consoleLog("「ARMMANE」 Command changed to " + this.elements["form"]["cconf_01"].value + "(" + this.elements["form"]["cconf_02"].value + "," + this.elements["form"]["cconf_03"].value + ");"); - }); - - this.setTriggerEvent("btn", "cconf_btn_cancel", "click", () => { - this.hideElement("ui", "cconfbox"); - }); - // let element_fw = this.elements["ui"]["status_conv" + conv + "_forward"].querySelector(".elementor-icon"); // let element_bw = this.elements["ui"]["status_conv" + conv + "_backward"].querySelector(".elementor-icon"); // let element_stop = this.elements["ui"]["status_conv" + conv + "_stop"].querySelector(".elementor-icon"); From 938c2bab5ff454027276f2cb0c45beafb933c570 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Thu, 12 Oct 2023 11:39:09 +0700 Subject: [PATCH 53/76] add init() --- main-dev.js | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/main-dev.js b/main-dev.js index c538f95..e97c62f 100644 --- a/main-dev.js +++ b/main-dev.js @@ -218,6 +218,8 @@ class ARMMane{ this.initializeSortable(); + this.initialize(); + } @@ -1110,6 +1112,120 @@ class ARMMane{ console.error(`Element with ID '${uniqueElementId}' not found.`); } } + + getPreset() { + // Return the promise for the fetch operation + return fetch(`${this.serverURL}/config`, { + method: "GET", + headers: { + "Content-Type": "application/json" + } + }) + .then((response) => { + if (response.status === 200) { + return response.json(); + } else { + this.consoleLog("Train request sent failed", "ERROR"); + throw new Error("Request failed with status: " + response.status); + } + }) + .then((data) => { + if (data.config && data.config.instructions) { + const instructions = data.config.instructions; + const presetNames = Object.keys(instructions); + const presetsWithSteps = presetNames.map(presetName => { + const steps = instructions[presetName].step; + return { + presetName, + steps + }; + }); + console.log("Presets with Steps:", presetsWithSteps); + return presetsWithSteps; + } else { + console.error("Data format is invalid. Missing 'config' or 'instructions'."); + throw new Error("Data format is invalid."); + } + }) + .catch((error) => { + console.error("Error:", error); + throw error; + }); + } + + // Add the translateInstruction function to your class + translateInstruction(instruction) { + const type = instruction[0]; + + if (type === 'S') { + const id = parseInt(instruction[2]); + const degree = parseInt(instruction.substring(4)); + return `setServo(${id},${degree});`; + } else if (type === 'C') { + const id = parseInt(instruction[1]); + const mode = parseInt(instruction[3]); + const speed = parseInt(instruction.substring(5)); + return `setConV(${id},${mode},${speed});`; + } else { + // Handle unsupported instruction type + return `Unsupported instruction type: ${type}`; + } + } + + createPresetList(presetsWithSteps) { + const spawnArea = this.elements["ui"]["preset_box"][0].querySelector("div"); + + presetsWithSteps.forEach(preset => { + const newPresetElement = this.createPresetElement(preset.presetName); + newPresetElement.addEventListener("click", () => { + this.handlePresetElementClick(preset, newPresetElement); + }); + + spawnArea.appendChild(newPresetElement); + }); + } + + createPresetElement(presetName) { + const newPresetElement = this.elements["template"]["ins_preset"][0].cloneNode(true); + const uniqueId = `preset_${presetName}`; + newPresetElement.id = uniqueId; + + newPresetElement.classList.add("ins-preset", presetName); + newPresetElement.querySelector(".tp-ins-preset > div > h4").textContent = presetName; + newPresetElement.style.display = "flex"; + newPresetElement.setAttribute("data-preset-name", presetName); + + return newPresetElement; + } + + handlePresetElementClick(preset, newPresetElement) { + const swimLane = this.elements["ui"]["command_area"][0]; + swimLane.innerHTML = ""; + + preset.steps.forEach(step => { + const newDiv = this.cloneCodeBlockElement(newPresetElement); // Pass newPresetElement as an argument + this.attachCodeBlockEventListeners(newDiv, newPresetElement); // Pass newPresetElement as well + newDiv.querySelector(".cmd-text > div > h2").textContent = this.translateInstruction(step); + swimLane.appendChild(newDiv); + }); + } + + initialize() { + // Fetch the presets and steps + this.getPreset() + .then(presetsWithSteps => { + // Create the draggable list of elements + this.createDraggableList(); + + // Create the preset list in the preset_box + this.createPresetList(presetsWithSteps); + + // You can add other initialization code here. + }) + .catch(error => { + console.error("Error:", error); + }); + } //This will change the property of the element after click save button From 16eb347fb7e835a7be794a282f53bf879d5a92ca Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Thu, 12 Oct 2023 15:44:02 +0700 Subject: [PATCH 54/76] remove init --- main-dev.js | 117 ---------------------------------------------------- 1 file changed, 117 deletions(-) diff --git a/main-dev.js b/main-dev.js index e97c62f..2430774 100644 --- a/main-dev.js +++ b/main-dev.js @@ -218,8 +218,6 @@ class ARMMane{ this.initializeSortable(); - this.initialize(); - } @@ -1113,121 +1111,6 @@ class ARMMane{ } } - getPreset() { - // Return the promise for the fetch operation - return fetch(`${this.serverURL}/config`, { - method: "GET", - headers: { - "Content-Type": "application/json" - } - }) - .then((response) => { - if (response.status === 200) { - return response.json(); - } else { - this.consoleLog("Train request sent failed", "ERROR"); - throw new Error("Request failed with status: " + response.status); - } - }) - .then((data) => { - if (data.config && data.config.instructions) { - const instructions = data.config.instructions; - const presetNames = Object.keys(instructions); - const presetsWithSteps = presetNames.map(presetName => { - const steps = instructions[presetName].step; - return { - presetName, - steps - }; - }); - console.log("Presets with Steps:", presetsWithSteps); - return presetsWithSteps; - } else { - console.error("Data format is invalid. Missing 'config' or 'instructions'."); - throw new Error("Data format is invalid."); - } - }) - .catch((error) => { - console.error("Error:", error); - throw error; - }); - } - - // Add the translateInstruction function to your class - translateInstruction(instruction) { - const type = instruction[0]; - - if (type === 'S') { - const id = parseInt(instruction[2]); - const degree = parseInt(instruction.substring(4)); - return `setServo(${id},${degree});`; - } else if (type === 'C') { - const id = parseInt(instruction[1]); - const mode = parseInt(instruction[3]); - const speed = parseInt(instruction.substring(5)); - return `setConV(${id},${mode},${speed});`; - } else { - // Handle unsupported instruction type - return `Unsupported instruction type: ${type}`; - } - } - - createPresetList(presetsWithSteps) { - const spawnArea = this.elements["ui"]["preset_box"][0].querySelector("div"); - - presetsWithSteps.forEach(preset => { - const newPresetElement = this.createPresetElement(preset.presetName); - newPresetElement.addEventListener("click", () => { - this.handlePresetElementClick(preset, newPresetElement); - }); - - spawnArea.appendChild(newPresetElement); - }); - } - - createPresetElement(presetName) { - const newPresetElement = this.elements["template"]["ins_preset"][0].cloneNode(true); - const uniqueId = `preset_${presetName}`; - newPresetElement.id = uniqueId; - - newPresetElement.classList.add("ins-preset", presetName); - newPresetElement.querySelector(".tp-ins-preset > div > h4").textContent = presetName; - newPresetElement.style.display = "flex"; - newPresetElement.setAttribute("data-preset-name", presetName); - - return newPresetElement; - } - - handlePresetElementClick(preset, newPresetElement) { - const swimLane = this.elements["ui"]["command_area"][0]; - swimLane.innerHTML = ""; - - preset.steps.forEach(step => { - const newDiv = this.cloneCodeBlockElement(newPresetElement); // Pass newPresetElement as an argument - this.attachCodeBlockEventListeners(newDiv, newPresetElement); // Pass newPresetElement as well - newDiv.querySelector(".cmd-text > div > h2").textContent = this.translateInstruction(step); - swimLane.appendChild(newDiv); - }); - } - - initialize() { - // Fetch the presets and steps - this.getPreset() - .then(presetsWithSteps => { - // Create the draggable list of elements - this.createDraggableList(); - - // Create the preset list in the preset_box - this.createPresetList(presetsWithSteps); - - // You can add other initialization code here. - }) - .catch(error => { - console.error("Error:", error); - }); - } - - //This will change the property of the element after click save button openConfigBox() { if (this.appStatus["currentEditCodeBlock"] == null) { From d233fda3e5ce4b5045250f7fc637a17640bf5aee Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Thu, 12 Oct 2023 15:56:42 +0700 Subject: [PATCH 55/76] Fix getPreset() --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index 2430774..967be1b 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1168,7 +1168,7 @@ class ARMMane{ getPreset() { // Return the promise for the fetch operation - return fetch(`${this.serverURL}/config`, { + return fetch(`${this.appStatus["server"]["fullURL"]}/config`, { method: "GET", headers: { "Content-Type": "application/json" From d8c2e65196ccc58d2b08f2a2a29f22a2f1f24b3d Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Thu, 12 Oct 2023 16:04:37 +0700 Subject: [PATCH 56/76] Add preset _box --- main-dev.js | 1 + 1 file changed, 1 insertion(+) diff --git a/main-dev.js b/main-dev.js index 967be1b..20ee44b 100644 --- a/main-dev.js +++ b/main-dev.js @@ -79,6 +79,7 @@ class ARMMane{ "status_conv01_backward" : this.querySel(".status-conv01-bw"), "command_area" : document.querySelectorAll(".ins-command-area"), "function_box" : document.querySelectorAll(".ins-func-box"), + "preset_box" : document.querySelectorAll(".ins-preset-box"), "livepreview" : this.querySel(".livepreview"), "settingbox1" : this.querySel(".settingbox-1"), "settingbox2" : this.querySel(".settingbox-2"), From ab1f95523f1e98ac02b77446dfcc224cccc33a65 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Thu, 12 Oct 2023 16:07:58 +0700 Subject: [PATCH 57/76] Add ins_preset --- main-dev.js | 1 + 1 file changed, 1 insertion(+) diff --git a/main-dev.js b/main-dev.js index 20ee44b..cebca89 100644 --- a/main-dev.js +++ b/main-dev.js @@ -117,6 +117,7 @@ class ARMMane{ "log_alert" : this.querySel(".tp-log-alert"), "ins_function" : document.querySelectorAll(".tp-ins-func"), "code_block" : this.querySel(".tp-ins-code-block"), + "ins_preset" : this.querySel(".tp-ins-preset"), }, "text" : { "connect_url" : this.querySel(".connecting-url").querySelector("div > h2"), From 7b23d6dc8c8c34151d08d6c316830bff3642604a Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Thu, 12 Oct 2023 16:21:56 +0700 Subject: [PATCH 58/76] try to fix error --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index cebca89..7f076eb 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1241,7 +1241,7 @@ class ARMMane{ } createPresetElement(presetName) { - const newPresetElement = this.elements["template"]["ins_preset"][0].cloneNode(true); + const newPresetElement = this.elements["template"]["ins_preset"].cloneNode(true); const uniqueId = `preset_${presetName}`; newPresetElement.id = uniqueId; From bfe330ae59cfdcec6aabd1ce10c0d80128a94ed3 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Thu, 12 Oct 2023 16:42:40 +0700 Subject: [PATCH 59/76] add attribute to createPresetElement() --- main-dev.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/main-dev.js b/main-dev.js index 7f076eb..7e4ba8f 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1249,6 +1249,18 @@ class ARMMane{ newPresetElement.querySelector(".tp-ins-preset > div > h4").textContent = presetName; newPresetElement.style.display = "flex"; newPresetElement.setAttribute("data-preset-name", presetName); + + // Call translateInstruction to get the data + const translatedData = this.translateInstruction(instruction); + + // Set attributes based on the translated data + newPresetElement.setAttribute("data-type", translatedData.type); + newPresetElement.setAttribute("data-device", translatedData.device); + newPresetElement.setAttribute("data-value", translatedData.value); + newPresetElement.setAttribute("data-speed", translatedData.speed); + newPresetElement.setAttribute("data-min", translatedData.min); + newPresetElement.setAttribute("data-max", translatedData.max); + newPresetElement.setAttribute("data-num", translatedData.num); return newPresetElement; } From 3055c8a6575d532d5a31782cea07800f32c18811 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Thu, 12 Oct 2023 16:45:39 +0700 Subject: [PATCH 60/76] Forgot to pass instruction --- main-dev.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main-dev.js b/main-dev.js index 7e4ba8f..a18998f 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1240,19 +1240,21 @@ class ARMMane{ }); } - createPresetElement(presetName) { + createPresetElement(presetName, instruction) { + // Clone the preset template const newPresetElement = this.elements["template"]["ins_preset"].cloneNode(true); const uniqueId = `preset_${presetName}`; newPresetElement.id = uniqueId; + // Add preset class and set the preset name newPresetElement.classList.add("ins-preset", presetName); newPresetElement.querySelector(".tp-ins-preset > div > h4").textContent = presetName; newPresetElement.style.display = "flex"; newPresetElement.setAttribute("data-preset-name", presetName); - + // Call translateInstruction to get the data const translatedData = this.translateInstruction(instruction); - + // Set attributes based on the translated data newPresetElement.setAttribute("data-type", translatedData.type); newPresetElement.setAttribute("data-device", translatedData.device); @@ -1263,7 +1265,7 @@ class ARMMane{ newPresetElement.setAttribute("data-num", translatedData.num); return newPresetElement; - } + } handlePresetElementClick(preset, newPresetElement) { const swimLane = this.elements["ui"]["command_area"][0]; From 6d37aea77f1b0b6b66d24ade0279f02f9a3a61df Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Thu, 12 Oct 2023 16:48:41 +0700 Subject: [PATCH 61/76] Tr to fix translateInstruction() --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index a18998f..e242ec9 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1210,7 +1210,7 @@ class ARMMane{ // Add the translateInstruction function to your class translateInstruction(instruction) { - const type = instruction[0]; + const type = instruction; if (type === 'S') { const id = parseInt(instruction[2]); From 650d20728188f5e3230b1d45dcb88ddd5a17b56a Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:01:37 +0700 Subject: [PATCH 62/76] comment out some line --- main-dev.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/main-dev.js b/main-dev.js index e242ec9..33be582 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1256,13 +1256,13 @@ class ARMMane{ const translatedData = this.translateInstruction(instruction); // Set attributes based on the translated data - newPresetElement.setAttribute("data-type", translatedData.type); - newPresetElement.setAttribute("data-device", translatedData.device); - newPresetElement.setAttribute("data-value", translatedData.value); - newPresetElement.setAttribute("data-speed", translatedData.speed); - newPresetElement.setAttribute("data-min", translatedData.min); - newPresetElement.setAttribute("data-max", translatedData.max); - newPresetElement.setAttribute("data-num", translatedData.num); + // newPresetElement.setAttribute("data-type", translatedData.type); + // newPresetElement.setAttribute("data-device", translatedData.device); + // newPresetElement.setAttribute("data-value", translatedData.value); + // newPresetElement.setAttribute("data-speed", translatedData.speed); + // newPresetElement.setAttribute("data-min", translatedData.min); + // newPresetElement.setAttribute("data-max", translatedData.max); + // newPresetElement.setAttribute("data-num", translatedData.num); return newPresetElement; } From 86408245a19e05981495fad17e85e0b81b6e11ca Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:04:05 +0700 Subject: [PATCH 63/76] comment out more --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index 33be582..3412e78 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1253,7 +1253,7 @@ class ARMMane{ newPresetElement.setAttribute("data-preset-name", presetName); // Call translateInstruction to get the data - const translatedData = this.translateInstruction(instruction); + //const translatedData = this.translateInstruction(instruction); // Set attributes based on the translated data // newPresetElement.setAttribute("data-type", translatedData.type); From f2a59ab9a418000af34a3acaaa2e2f2a11c8bc29 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:26:00 +0700 Subject: [PATCH 64/76] Try to fix translate --- main-dev.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/main-dev.js b/main-dev.js index 3412e78..db11796 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1210,8 +1210,8 @@ class ARMMane{ // Add the translateInstruction function to your class translateInstruction(instruction) { - const type = instruction; - + const type = instruction[0]; + if (type === 'S') { const id = parseInt(instruction[2]); const degree = parseInt(instruction.substring(4)); @@ -1225,7 +1225,7 @@ class ARMMane{ // Handle unsupported instruction type return `Unsupported instruction type: ${type}`; } - } + } createPresetList(presetsWithSteps) { const spawnArea = this.elements["ui"]["preset_box"][0].querySelector("div"); @@ -1253,16 +1253,16 @@ class ARMMane{ newPresetElement.setAttribute("data-preset-name", presetName); // Call translateInstruction to get the data - //const translatedData = this.translateInstruction(instruction); + const translatedData = this.translateInstruction(instruction); // Set attributes based on the translated data - // newPresetElement.setAttribute("data-type", translatedData.type); - // newPresetElement.setAttribute("data-device", translatedData.device); - // newPresetElement.setAttribute("data-value", translatedData.value); - // newPresetElement.setAttribute("data-speed", translatedData.speed); - // newPresetElement.setAttribute("data-min", translatedData.min); - // newPresetElement.setAttribute("data-max", translatedData.max); - // newPresetElement.setAttribute("data-num", translatedData.num); + newPresetElement.setAttribute("data-type", translatedData.type); + newPresetElement.setAttribute("data-device", translatedData.device); + newPresetElement.setAttribute("data-value", translatedData.value); + newPresetElement.setAttribute("data-speed", translatedData.speed); + newPresetElement.setAttribute("data-min", translatedData.min); + newPresetElement.setAttribute("data-max", translatedData.max); + newPresetElement.setAttribute("data-num", translatedData.num); return newPresetElement; } From f0bc8ce37f757839d21117a83e9a2b14bf081565 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:28:35 +0700 Subject: [PATCH 65/76] Add parseInt --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index db11796..f13ea57 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1210,7 +1210,7 @@ class ARMMane{ // Add the translateInstruction function to your class translateInstruction(instruction) { - const type = instruction[0]; + const type = parseInt(instruction[0]); if (type === 'S') { const id = parseInt(instruction[2]); From 5d00ee5e3281fad80d90517572a91f7ebcac7411 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:32:09 +0700 Subject: [PATCH 66/76] God help me --- main-dev.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main-dev.js b/main-dev.js index f13ea57..84c6e0c 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1210,7 +1210,7 @@ class ARMMane{ // Add the translateInstruction function to your class translateInstruction(instruction) { - const type = parseInt(instruction[0]); + const type = instruction[0]; if (type === 'S') { const id = parseInt(instruction[2]); @@ -1242,7 +1242,7 @@ class ARMMane{ createPresetElement(presetName, instruction) { // Clone the preset template - const newPresetElement = this.elements["template"]["ins_preset"].cloneNode(true); + const newPresetElement = this.elements["template"]["ins_preset"][0].cloneNode(true); const uniqueId = `preset_${presetName}`; newPresetElement.id = uniqueId; From 4e47fe5409a10580e22943b3aa052209c90b1711 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:38:53 +0700 Subject: [PATCH 67/76] Change ins_preset to querySelectorAll --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index 84c6e0c..559efc6 100644 --- a/main-dev.js +++ b/main-dev.js @@ -117,7 +117,7 @@ class ARMMane{ "log_alert" : this.querySel(".tp-log-alert"), "ins_function" : document.querySelectorAll(".tp-ins-func"), "code_block" : this.querySel(".tp-ins-code-block"), - "ins_preset" : this.querySel(".tp-ins-preset"), + "ins_preset" : document.querySelectorAll(".tp-ins-preset"), }, "text" : { "connect_url" : this.querySel(".connecting-url").querySelector("div > h2"), From a55ec42a43a4bae84edaf92c88ec8dbdb90d3fc5 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:50:55 +0700 Subject: [PATCH 68/76] Try to roll back --- main-dev.js | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/main-dev.js b/main-dev.js index 559efc6..778c366 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1211,7 +1211,6 @@ class ARMMane{ // Add the translateInstruction function to your class translateInstruction(instruction) { const type = instruction[0]; - if (type === 'S') { const id = parseInt(instruction[2]); const degree = parseInt(instruction.substring(4)); @@ -1225,8 +1224,7 @@ class ARMMane{ // Handle unsupported instruction type return `Unsupported instruction type: ${type}`; } - } - + } createPresetList(presetsWithSteps) { const spawnArea = this.elements["ui"]["preset_box"][0].querySelector("div"); @@ -1239,33 +1237,19 @@ class ARMMane{ spawnArea.appendChild(newPresetElement); }); } - - createPresetElement(presetName, instruction) { - // Clone the preset template + + createPresetElement(presetName) { const newPresetElement = this.elements["template"]["ins_preset"][0].cloneNode(true); const uniqueId = `preset_${presetName}`; newPresetElement.id = uniqueId; - - // Add preset class and set the preset name + newPresetElement.classList.add("ins-preset", presetName); newPresetElement.querySelector(".tp-ins-preset > div > h4").textContent = presetName; newPresetElement.style.display = "flex"; newPresetElement.setAttribute("data-preset-name", presetName); - // Call translateInstruction to get the data - const translatedData = this.translateInstruction(instruction); - - // Set attributes based on the translated data - newPresetElement.setAttribute("data-type", translatedData.type); - newPresetElement.setAttribute("data-device", translatedData.device); - newPresetElement.setAttribute("data-value", translatedData.value); - newPresetElement.setAttribute("data-speed", translatedData.speed); - newPresetElement.setAttribute("data-min", translatedData.min); - newPresetElement.setAttribute("data-max", translatedData.max); - newPresetElement.setAttribute("data-num", translatedData.num); - return newPresetElement; - } + } handlePresetElementClick(preset, newPresetElement) { const swimLane = this.elements["ui"]["command_area"][0]; @@ -1278,7 +1262,6 @@ class ARMMane{ swimLane.appendChild(newDiv); }); } - initializePreset() { // Fetch the presets and steps this.getPreset() From b0f58bb30d3b04750e3b905a3e6eb6af3e572285 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Mon, 16 Oct 2023 13:01:38 +0700 Subject: [PATCH 69/76] Add data --- main-dev.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index 778c366..c0bcec0 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1238,7 +1238,7 @@ class ARMMane{ }); } - createPresetElement(presetName) { + createPresetElement(presetName, instruction) { const newPresetElement = this.elements["template"]["ins_preset"][0].cloneNode(true); const uniqueId = `preset_${presetName}`; newPresetElement.id = uniqueId; @@ -1247,6 +1247,12 @@ class ARMMane{ newPresetElement.querySelector(".tp-ins-preset > div > h4").textContent = presetName; newPresetElement.style.display = "flex"; newPresetElement.setAttribute("data-preset-name", presetName); + + const data = this.translateInstruction(instruction); + newPresetElement.setAttribute("data-type", data.type); + newPresetElement.setAttribute("data-device", data.id); + newPresetElement.setAttribute("data-value", data.degree); + newPresetElement.setAttribute("data-speed", data.speed); return newPresetElement; } From 258e42e5d6539f74a8083b0981efa666b561b85d Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Mon, 16 Oct 2023 13:08:32 +0700 Subject: [PATCH 70/76] Add console,log --- main-dev.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index c0bcec0..23179de 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1210,6 +1210,7 @@ class ARMMane{ // Add the translateInstruction function to your class translateInstruction(instruction) { + console.log("Instruction:", instruction); const type = instruction[0]; if (type === 'S') { const id = parseInt(instruction[2]); @@ -1248,7 +1249,7 @@ class ARMMane{ newPresetElement.style.display = "flex"; newPresetElement.setAttribute("data-preset-name", presetName); - const data = this.translateInstruction(instruction); + new data = this.translateInstruction(instruction); newPresetElement.setAttribute("data-type", data.type); newPresetElement.setAttribute("data-device", data.id); newPresetElement.setAttribute("data-value", data.degree); From 6b24a6fe70b53db47ccd477f34086afa6ee146bc Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Mon, 16 Oct 2023 13:11:01 +0700 Subject: [PATCH 71/76] const --- main-dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-dev.js b/main-dev.js index 23179de..392e22f 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1249,7 +1249,7 @@ class ARMMane{ newPresetElement.style.display = "flex"; newPresetElement.setAttribute("data-preset-name", presetName); - new data = this.translateInstruction(instruction); + const data = this.translateInstruction(instruction); newPresetElement.setAttribute("data-type", data.type); newPresetElement.setAttribute("data-device", data.id); newPresetElement.setAttribute("data-value", data.degree); From c69b0cfa157b6cfbcbbbd949c4fe23d3fbb5d252 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Mon, 16 Oct 2023 13:16:11 +0700 Subject: [PATCH 72/76] Try adding translate() --- main-dev.js | 1 + 1 file changed, 1 insertion(+) diff --git a/main-dev.js b/main-dev.js index 392e22f..bfa45f5 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1196,6 +1196,7 @@ class ARMMane{ }; }); console.log("Presets with Steps:", presetsWithSteps); + this.translateInstruction(presetNames, presetsWithSteps); // Call the translateInstruction function return presetsWithSteps; } else { console.error("Data format is invalid. Missing 'config' or 'instructions'."); From 4aa388949eaa2a6584ad1b50a5e6f3a20817ff0c Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Mon, 16 Oct 2023 13:24:05 +0700 Subject: [PATCH 73/76] IDk --- main-dev.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main-dev.js b/main-dev.js index bfa45f5..d285e14 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1196,7 +1196,6 @@ class ARMMane{ }; }); console.log("Presets with Steps:", presetsWithSteps); - this.translateInstruction(presetNames, presetsWithSteps); // Call the translateInstruction function return presetsWithSteps; } else { console.error("Data format is invalid. Missing 'config' or 'instructions'."); @@ -1240,7 +1239,7 @@ class ARMMane{ }); } - createPresetElement(presetName, instruction) { + createPresetElement(presetName, instructions) { const newPresetElement = this.elements["template"]["ins_preset"][0].cloneNode(true); const uniqueId = `preset_${presetName}`; newPresetElement.id = uniqueId; @@ -1250,7 +1249,7 @@ class ARMMane{ newPresetElement.style.display = "flex"; newPresetElement.setAttribute("data-preset-name", presetName); - const data = this.translateInstruction(instruction); + const data = this.translateInstruction(instructions); newPresetElement.setAttribute("data-type", data.type); newPresetElement.setAttribute("data-device", data.id); newPresetElement.setAttribute("data-value", data.degree); From aacf84da3029b44d81fa775e874c4db3f8f3eaf8 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Mon, 16 Oct 2023 13:35:04 +0700 Subject: [PATCH 74/76] add steps --- main-dev.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main-dev.js b/main-dev.js index d285e14..1c5de1b 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1239,7 +1239,7 @@ class ARMMane{ }); } - createPresetElement(presetName, instructions) { + createPresetElement(presetName, steps) { const newPresetElement = this.elements["template"]["ins_preset"][0].cloneNode(true); const uniqueId = `preset_${presetName}`; newPresetElement.id = uniqueId; @@ -1249,7 +1249,7 @@ class ARMMane{ newPresetElement.style.display = "flex"; newPresetElement.setAttribute("data-preset-name", presetName); - const data = this.translateInstruction(instructions); + const data = this.translateInstruction(steps); newPresetElement.setAttribute("data-type", data.type); newPresetElement.setAttribute("data-device", data.id); newPresetElement.setAttribute("data-value", data.degree); From fbb607474bbd2584d8b0e8a7d7422b549845dbcf Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Mon, 16 Oct 2023 13:47:21 +0700 Subject: [PATCH 75/76] Revert "try to fix error" This reverts commit 7b23d6dc8c8c34151d08d6c316830bff3642604a. --- main-dev.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/main-dev.js b/main-dev.js index 1c5de1b..6a28239 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1238,8 +1238,8 @@ class ARMMane{ spawnArea.appendChild(newPresetElement); }); } - - createPresetElement(presetName, steps) { + + createPresetElement(presetName) { const newPresetElement = this.elements["template"]["ins_preset"][0].cloneNode(true); const uniqueId = `preset_${presetName}`; newPresetElement.id = uniqueId; @@ -1249,12 +1249,6 @@ class ARMMane{ newPresetElement.style.display = "flex"; newPresetElement.setAttribute("data-preset-name", presetName); - const data = this.translateInstruction(steps); - newPresetElement.setAttribute("data-type", data.type); - newPresetElement.setAttribute("data-device", data.id); - newPresetElement.setAttribute("data-value", data.degree); - newPresetElement.setAttribute("data-speed", data.speed); - return newPresetElement; } From 96bfa2b5d190469c6e4765dc7fb0631c37182e04 Mon Sep 17 00:00:00 2001 From: GenZerg <108889885+GenZerg@users.noreply.github.com> Date: Tue, 17 Oct 2023 11:56:13 +0700 Subject: [PATCH 76/76] Still trying to add data --- main-dev.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main-dev.js b/main-dev.js index 6a28239..e38f7f3 100644 --- a/main-dev.js +++ b/main-dev.js @@ -1258,8 +1258,13 @@ class ARMMane{ preset.steps.forEach(step => { const newDiv = this.cloneCodeBlockElement(newPresetElement); // Pass newPresetElement as an argument + const data = this.translateInstruction(step); this.attachCodeBlockEventListeners(newDiv, newPresetElement); // Pass newPresetElement as well newDiv.querySelector(".cmd-text > div > h2").textContent = this.translateInstruction(step); + newDiv.setAttribute("data-type", data.type); + newDiv.setAttribute("data-device", data.id); + newDiv.setAttribute("data-value", data.degree); + newDiv.setAttribute("data-speed", data.speed); swimLane.appendChild(newDiv); }); }