Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60a3584e86 | ||
|
|
fa0e653236 | ||
|
|
16de3d9243 | ||
|
|
c65d6506f7 | ||
|
|
a249f332a2 |
@@ -91,7 +91,7 @@ export class LaserPathManager {
|
||||
private collaboratorsState: Map<string, CollabolatorState> = new Map();
|
||||
|
||||
private rafId: number | undefined;
|
||||
private lastUpdate = 0;
|
||||
private isDrawing = false;
|
||||
private container: SVGSVGElement | undefined;
|
||||
|
||||
constructor(private app: App) {
|
||||
@@ -100,12 +100,19 @@ export class LaserPathManager {
|
||||
|
||||
destroy() {
|
||||
this.stop();
|
||||
this.lastUpdate = 0;
|
||||
this.isDrawing = false;
|
||||
this.ownState = instantiateCollabolatorState();
|
||||
this.collaboratorsState = new Map();
|
||||
}
|
||||
|
||||
startPath(x: number, y: number) {
|
||||
if (this.container) {
|
||||
this.container.style.top = "0px";
|
||||
this.container.style.left = "0px";
|
||||
const { x, y } = this.container.getBoundingClientRect();
|
||||
this.container.style.top = `${-y}px`;
|
||||
this.container.style.left = `${-x}px`;
|
||||
}
|
||||
this.ownState.currentPath = instantiatePath();
|
||||
this.ownState.currentPath.addPoint([x, y, performance.now()]);
|
||||
this.updatePath(this.ownState);
|
||||
@@ -127,7 +134,7 @@ export class LaserPathManager {
|
||||
}
|
||||
|
||||
private updatePath(state: CollabolatorState) {
|
||||
this.lastUpdate = performance.now();
|
||||
this.isDrawing = true;
|
||||
|
||||
if (!this.isRunning) {
|
||||
this.start();
|
||||
@@ -160,7 +167,7 @@ export class LaserPathManager {
|
||||
|
||||
this.updateCollabolatorsState();
|
||||
|
||||
if (performance.now() - this.lastUpdate < DECAY_TIME * 2) {
|
||||
if (this.isDrawing) {
|
||||
this.update();
|
||||
} else {
|
||||
this.isRunning = false;
|
||||
@@ -250,6 +257,8 @@ export class LaserPathManager {
|
||||
return;
|
||||
}
|
||||
|
||||
let somePathsExist = false;
|
||||
|
||||
for (const [key, state] of this.collaboratorsState.entries()) {
|
||||
if (!this.app.state.collaborators.has(key)) {
|
||||
state.svg.remove();
|
||||
@@ -269,6 +278,10 @@ export class LaserPathManager {
|
||||
paths += ` ${this.draw(state.currentPath)}`;
|
||||
}
|
||||
|
||||
if (paths.trim()) {
|
||||
somePathsExist = true;
|
||||
}
|
||||
|
||||
state.svg.setAttribute("d", paths);
|
||||
state.svg.setAttribute("fill", getClientColor(key));
|
||||
}
|
||||
@@ -287,7 +300,17 @@ export class LaserPathManager {
|
||||
paths += ` ${this.draw(this.ownState.currentPath)}`;
|
||||
}
|
||||
|
||||
paths = paths.trim();
|
||||
|
||||
if (paths) {
|
||||
somePathsExist = true;
|
||||
}
|
||||
|
||||
this.ownState.svg.setAttribute("d", paths);
|
||||
this.ownState.svg.setAttribute("fill", "red");
|
||||
|
||||
if (!somePathsExist) {
|
||||
this.isDrawing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
|
||||
z-index: 2;
|
||||
|
||||
.LaserToolOverlayCanvas {
|
||||
|
||||
Reference in New Issue
Block a user