Skip to content

Commit

Permalink
laser fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelle committed Jan 29, 2024
1 parent b539826 commit 1efde89
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 328 deletions.
317 changes: 0 additions & 317 deletions packages/excalidraw/components/LaserTool/LaserPathManager.ts

This file was deleted.

25 changes: 14 additions & 11 deletions packages/excalidraw/laser-trails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type App from "./components/App";
import { SocketId } from "./types";
import { easeOut } from "./utils";
import { getClientColor } from "./clients";
import { DEFAULT_LASER_COLOR } from "./constants";

export class LaserTrails implements Trail {
public localTrail: AnimatedTrail;
Expand All @@ -20,7 +21,7 @@ export class LaserTrails implements Trail {

this.localTrail = new AnimatedTrail(animationFrameHandler, app, {
...this.getTrailOptions(),
fill: () => "red",
fill: () => DEFAULT_LASER_COLOR,
});
}

Expand Down Expand Up @@ -78,13 +79,15 @@ export class LaserTrails implements Trail {
return;
}

for (const [key, collabolator] of this.app.state.collaborators.entries()) {
for (const [key, collaborator] of this.app.state.collaborators.entries()) {
let trail!: AnimatedTrail;

if (!this.collabTrails.has(key)) {
trail = new AnimatedTrail(this.animationFrameHandler, this.app, {
...this.getTrailOptions(),
fill: () => getClientColor(key),
fill: () =>
collaborator.pointer?.laserColor ||
getClientColor(collaborator.id || key),
});
trail.start(this.container);

Expand All @@ -93,21 +96,21 @@ export class LaserTrails implements Trail {
trail = this.collabTrails.get(key)!;
}

if (collabolator.pointer && collabolator.pointer.tool === "laser") {
if (collabolator.button === "down" && !trail.hasCurrentTrail) {
trail.startPath(collabolator.pointer.x, collabolator.pointer.y);
if (collaborator.pointer && collaborator.pointer.tool === "laser") {
if (collaborator.button === "down" && !trail.hasCurrentTrail) {
trail.startPath(collaborator.pointer.x, collaborator.pointer.y);
}

if (
collabolator.button === "down" &&
collaborator.button === "down" &&
trail.hasCurrentTrail &&
!trail.hasLastPoint(collabolator.pointer.x, collabolator.pointer.y)
!trail.hasLastPoint(collaborator.pointer.x, collaborator.pointer.y)
) {
trail.addPointToPath(collabolator.pointer.x, collabolator.pointer.y);
trail.addPointToPath(collaborator.pointer.x, collaborator.pointer.y);
}

if (collabolator.button === "up" && trail.hasCurrentTrail) {
trail.addPointToPath(collabolator.pointer.x, collabolator.pointer.y);
if (collaborator.button === "up" && trail.hasCurrentTrail) {
trail.addPointToPath(collaborator.pointer.x, collaborator.pointer.y);
trail.endPath();
}
}
Expand Down

0 comments on commit 1efde89

Please sign in to comment.