Skip to content

Commit

Permalink
chore: fix lists compile (#136)
Browse files Browse the repository at this point in the history
* chore: fix lists not compiling

* chore: update version

* chore: fix updating name on actual list

* chore: actually fix all instances of list.name
  • Loading branch information
koen1711 authored Oct 31, 2024
1 parent a6fdcab commit c48b89a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"dist",
"media"
],
"version": "3.2.3",
"version": "3.2.4",
"description": "Leaphy custom Blockly blocks and arduino code generator",
"name": "@leaphy-robotics/leaphy-blocks"
}
21 changes: 14 additions & 7 deletions src/generators/arduino/lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@ function getCodeGenerators(arduino: Arduino) {
const value =
arduino.valueToCode(block, "VALUE", arduino.ORDER_ATOMIC) || "0";

return `${list.name}.add(${value});\n`;
const name = list.name.replace(" ", "_");
return `${name}.add(${value});\n`;
};

arduino.forBlock["lists_delete"] = function (block) {
const list = listManager.getList(block.getFieldValue("LIST")) as List;
const index =
arduino.valueToCode(block, "INDEX", arduino.ORDER_ATOMIC) || "0";

return `${list.name}.remove(${index});\n`;
const name = list.name.replace(" ", "_");
return `${name}.remove(${index});\n`;
};

arduino.forBlock["lists_clear"] = function (block) {
const list = listManager.getList(block.getFieldValue("LIST")) as List;

return `${list.name}.clear();\n`;
const name = list.name.replace(" ", "_");
return `${name}.clear();\n`;
};

arduino.forBlock["lists_insert"] = function (block) {
Expand All @@ -31,15 +34,17 @@ function getCodeGenerators(arduino: Arduino) {
const index =
arduino.valueToCode(block, "INDEX", arduino.ORDER_ATOMIC) || "0";

return `${list.name}.addAtIndex(${index}, ${value});\n`;
const name = list.name.replace(" ", "_");
return `${name}.addAtIndex(${index}, ${value});\n`;
};

arduino.forBlock["lists_get"] = function (block) {
const list = listManager.getList(block.getFieldValue("LIST")) as List;
const index =
arduino.valueToCode(block, "INDEX", arduino.ORDER_ATOMIC) || "0";

return [`${list.name}.get(${index})`, arduino.ORDER_ATOMIC];
const name = list.name.replace(" ", "_");
return [`${name}.get(${index})`, arduino.ORDER_ATOMIC];
};

arduino.forBlock["lists_replace"] = function (block) {
Expand All @@ -49,13 +54,15 @@ function getCodeGenerators(arduino: Arduino) {
const index =
arduino.valueToCode(block, "INDEX", arduino.ORDER_ATOMIC) || "0";

return `${list.name}.remove(${index});\n${list.name}.addAtIndex(${index}, ${value});\n`;
const name = list.name.replace(" ", "_");
return `${name}.remove(${index});\n${list.name}.addAtIndex(${index}, ${value});\n`;
};

arduino.forBlock["lists_length"] = function (block) {
const list = listManager.getList(block.getFieldValue("LIST")) as List;

return [`${list.name}.getSize()`, arduino.ORDER_ATOMIC];
const name = list.name.replace(" ", "_");
return [`${name}.getSize()`, arduino.ORDER_ATOMIC];
};
}

Expand Down

0 comments on commit c48b89a

Please sign in to comment.