aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuben Beltran del Rio <jj@r.bdr.sh>2025-12-12 15:22:14 +0100
committerRuben Beltran del Rio <jj@r.bdr.sh>2025-12-12 15:24:22 +0100
commitaee5dffd8013f6f6a6b77e5d00edd981bcfcad48 (patch)
tree5139b74aed9b4ba49e57d688039b0eb4fab29392 /src
parent68a999ed21907ef8f14c1aa0bf760d3c9b4b4c8c (diff)
Use component/s instead of vert(ex/ices) and circle as default shape
Diffstat (limited to 'src')
-rw-r--r--src/index.js29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/index.js b/src/index.js
index 653de18..24a2c2e 100644
--- a/src/index.js
+++ b/src/index.js
@@ -10,12 +10,17 @@
*/
/**
+ * Any of the potential shapes in a component.
+ * @typedef {"x"|"square"|"triangle"|"circle"} Shape
+ */
+
+/**
* A component in the map.
* @typedef {Object} Component
* @property {'component'} type - Entity type
* @property {string} label - Component label
* @property {[number, number]} coordinates - X and Y coordinates
- * @property {string|null} shape - Shape type (x, square, triangle, circle) or null
+ * @property {Shape} shape - Shape of the component
*/
/**
@@ -47,21 +52,21 @@
* A group of components.
* @typedef {Object} Group
* @property {'group'} type - Entity type
- * @property {string[]} vertices - Array of component labels in the group
+ * @property {string[]} components - Array of component labels in the group
*/
/**
* Inertia associated with a component.
* @typedef {Object} Inertia
* @property {'inertia'} type - Entity type
- * @property {string} vertex - Component label with inertia
+ * @property {string} component - Component label with inertia
*/
/**
* Evolution associated with a component.
* @typedef {Object} Evolution
* @property {'evolution'} type - Entity type
- * @property {string} vertex - Component label
+ * @property {string} component - Component label
* @property {boolean} isPositive - Whether evolution is positive (+) or negative (-)
* @property {number} value - Evolution value
*/
@@ -199,18 +204,18 @@ function parseKeywordEntity(line, start, length) {
// Group: [Group] label1, label2, ...
if (keyword === "group") {
- const vertices = line
+ const components = line
.substring(i)
.split(",")
.map(v => v.trim())
.filter(v => v);
- return vertices.length > 0 ? { type: "group", vertices } : null;
+ return components.length > 0 ? { type: "group", components } : null;
}
// Inertia: [Inertia] label
if (keyword === "inertia") {
- const vertex = line.substring(i).trim();
- return vertex ? { type: "inertia", vertex } : null;
+ const component = line.substring(i).trim();
+ return component ? { type: "inertia", component } : null;
}
// Evolution: [Evolution] label +/- number
@@ -232,8 +237,8 @@ function parseKeywordEntity(line, start, length) {
if (indexOfSign === -1 || indexOfSign === i) return null;
- const vertex = line.substring(i, indexOfSign).trim();
- if (!vertex) return null;
+ const component = line.substring(i, indexOfSign).trim();
+ if (!component) return null;
// Read number after sign
let indexOfNumber = indexOfSign + 1;
@@ -244,7 +249,7 @@ function parseKeywordEntity(line, start, length) {
return {
type: "evolution",
- vertex,
+ component,
isPositive: signCharacter === "+",
value: parseFloat(line.substring(numStart, indexOfNumber)),
};
@@ -334,7 +339,7 @@ function parseComponent(line, indexOfParenthesis, length) {
i++;
// Optional shape: [shape]
- let shape = null;
+ let shape = "circle";
while (i < length && isWhitespace(line[i])) i++;
if (i < length && line[i] === "[") {
i++;