@@ -2,59 +2,47 @@ import { writable } from 'svelte/store';
22
33// Walls
44const createWallsStore = ( ) => {
5- const { subscribe, update, set } = writable ( new Set < string > ( ) ) ;
6- return {
7- subscribe,
8- addWall : ( key : string ) =>
9- update ( ( current ) => {
10- current . add ( key ) ;
11- return current ;
12- } ) ,
13- removeWall : ( key : string ) =>
14- update ( ( current ) => {
15- current . delete ( key ) ;
16- return current ;
17- } ) ,
18- reset : ( ) => set ( new Set ( ) )
19- } ;
5+ const { subscribe, update, set } = writable ( new Set < string > ( ) ) ;
6+ return {
7+ subscribe,
8+ addWall : ( key : string ) =>
9+ update ( ( current ) => {
10+ current . add ( key ) ;
11+ return current ;
12+ } ) ,
13+ removeWall : ( key : string ) =>
14+ update ( ( current ) => {
15+ current . delete ( key ) ;
16+ return current ;
17+ } ) ,
18+ reset : ( ) => set ( new Set ( ) )
19+ } ;
2020} ;
2121
2222const createWeightStore = ( ) => {
23- const { subscribe, update, set } = writable ( new Map < string , number > ( ) ) ;
24- return {
25- subscribe,
26- addWeight : ( key : string ) => {
27- update ( ( current ) => {
28- const weightedNode = current . get ( key ) ;
29- if ( weightedNode ) {
30- current . set ( key , Math . min ( 9 , weightedNode + 1 ) ) ;
31- } else {
32- current . set ( key , 1 ) ;
33- }
34-
35- return current ;
36- } ) ;
37- } ,
38- removeWeight : ( key : string ) => {
39- update ( ( current ) => {
40- const weightedNode = current . get ( key ) ;
41-
42- if ( ! weightedNode ) {
43- return current ;
44- }
45-
46- const nextWeight = weightedNode - 1 ;
47-
48- if ( nextWeight <= 0 ) {
49- current . delete ( key ) ;
50- } else {
51- current . set ( key , nextWeight ) ;
52- }
53- return current ;
54- } ) ;
55- } ,
56- reset : ( ) => set ( new Map ( ) )
57- } ;
23+ const { subscribe, update, set } = writable ( new Map < string , number > ( ) ) ;
24+ return {
25+ subscribe,
26+ addWeight : ( key : string ) => {
27+ update ( ( current ) => {
28+ const weightedNode = current . get ( key ) ;
29+ if ( weightedNode ) {
30+ current . set ( key , Math . min ( 9 , weightedNode + 1 ) ) ;
31+ } else {
32+ current . set ( key , 1 ) ;
33+ }
34+
35+ return current ;
36+ } ) ;
37+ } ,
38+ removeWeight : ( key : string ) => {
39+ update ( ( current ) => {
40+ current . delete ( key ) ;
41+ return current
42+ } )
43+ } ,
44+ reset : ( ) => set ( new Map ( ) )
45+ } ;
5846} ;
5947
6048// Start Node
@@ -70,6 +58,6 @@ export const walls = createWallsStore();
7058export const weight = createWeightStore ( ) ;
7159
7260export const resetNodes = ( ) => {
73- walls . reset ( ) ;
74- weight . reset ( ) ;
61+ walls . reset ( ) ;
62+ weight . reset ( ) ;
7563} ;
0 commit comments