Skip to content

Commit

Permalink
rope color
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisShank committed Nov 24, 2024
1 parent 43c086e commit 2561ff8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/arrows/event-propagator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ export class EventPropagator extends FolkRope {
return this.#expression;
}
set expression(expression) {
this.stroke = 'black';
this.#expression = expression;
try {
this.#function = new Function('$source', '$target', '$event', expression);
} catch (error) {
console.warn('Failed to parse expression:', error);
// Use no-op function when parsing fails
this.stroke = 'red';
this.#function = () => {};
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/arrows/fc-rope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ export class FolkRope extends AbstractArrow {
#gravity = { x: 0, y: 3000 };
#points: RopePoint[] = [];

#stroke = this.getAttribute('stroke') || 'black';
get stroke() {
return this.#stroke;
}
set stroke(stroke) {
this.#stroke = stroke;
// TODO: redraw rope?
}

constructor() {
super();

Expand Down Expand Up @@ -148,7 +157,7 @@ export class FolkRope extends AbstractArrow {
this.#context.moveTo(prev.pos.x, prev.pos.y);
this.#context.lineTo(p.pos.x, p.pos.y);
this.#context.lineWidth = 2;
this.#context.strokeStyle = 'black';
this.#context.strokeStyle = this.#stroke;
this.#context.stroke();
}
}
Expand Down

0 comments on commit 2561ff8

Please sign in to comment.