From 843e17e8d3e9fc1dbe9f1360fc16d3ef8ec41179 Mon Sep 17 00:00:00 2001 From: Sverre Nystad Date: Sat, 10 Aug 2024 23:56:25 +0200 Subject: [PATCH] feat: Add function to reset grid to initial state --- frontend/src/services/animationService.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/frontend/src/services/animationService.ts b/frontend/src/services/animationService.ts index 74334c0..bb0d719 100644 --- a/frontend/src/services/animationService.ts +++ b/frontend/src/services/animationService.ts @@ -130,3 +130,18 @@ const animatePath = (path: Node[]) => { timeoutIds.push(timeoutId); // Store timeout ID }); }; + +/** + * Reset the grid to its initial state by clearing any previous animations and resetting the tiles + */ +export const resetGrid = () => { + clearPreviousAnimations(); + tiles.value = tiles.value.map((tile) => { + return { + ...tile, + isExplored: false, + isPath: false, + weight: 0, + }; + }); +};