Skip to content

Commit

Permalink
handle undo
Browse files Browse the repository at this point in the history
  • Loading branch information
deveshidwivedi committed Jun 20, 2024
1 parent e47f20e commit d101cc4
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion modules/room/helpers/Canvas.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,40 @@ export const drawFromSocket = (
tempCtx.beginPath();
socketMoves.forEach(([x,y])=>{
tempCtx.lineTo(x,y);
tempCtx.stroke();
});
tempCtx.stroke();
tempCtx.closePath();
afterDraw();
}
};

export const drawOnUndo = (
ctx: CanvasRenderingContext2D,
savedMoves: [number, number][][],
users: {[key:string]: [number, number][][]}
) => {
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);

Object.values(users).forEach((user)=>{
user.forEach((userMove)=>{
ctx.beginPath();
userMove.forEach(([x,y])=>{
ctx.lineTo(x,y);
});
ctx.stroke();
ctx.closePath();
});
});

savedMoves.forEach((movesArr)=> {
ctx.beginPath();
movesArr.forEach(([x,y])=>{
ctx.lineTo(x,y);
});
ctx.stroke();
ctx.closePath();
});


};

0 comments on commit d101cc4

Please sign in to comment.