@@ -28,11 +28,20 @@ let settings: Settings
28
28
let automaton : AutomatonBase
29
29
30
30
window . onload = ( ) => {
31
+ const getInitialAlgo = ( ) => {
32
+ const path = window . location . pathname . slice ( 1 ) ; // Remove leading slash
33
+ const validAlgos = [
34
+ "cca-1D" , "cca-2D" , "cca-3D" , "conway" ,
35
+ "immigration" , "quadlife" , "langton" , "entropy"
36
+ ] ;
37
+ return validAlgos . includes ( path ) ? path : "cca-2D" ;
38
+ } ;
39
+
31
40
pane = new Pane ( {
32
41
title : "Parameters" ,
33
42
expanded : true ,
34
43
} )
35
- const algoSelector = pane . addBinding ( { algo : "cca-2D" } , "algo" , {
44
+ const algoSelector = pane . addBinding ( { algo : getInitialAlgo ( ) } , "algo" , {
36
45
index : 1 ,
37
46
label : "Algorithm" ,
38
47
options : {
@@ -225,6 +234,10 @@ window.onload = () => {
225
234
reset ( )
226
235
227
236
algoSelector . on ( "change" , ( event ) => {
237
+ // Update URL when algorithm changes
238
+ const newUrl = `/${ event . value } ` ;
239
+ window . history . pushState ( { } , '' , newUrl ) ;
240
+
228
241
switch ( event . value ) {
229
242
case "cca-1D" :
230
243
setCca1dBlades ( )
@@ -254,6 +267,14 @@ window.onload = () => {
254
267
reset ( )
255
268
} )
256
269
270
+ // Handle browser back/forward navigation
271
+ window . addEventListener ( 'popstate' , ( ) => {
272
+ const newAlgo = getInitialAlgo ( ) ;
273
+ if ( newAlgo !== settings . algo ) {
274
+ algoSelector . value = newAlgo ;
275
+ }
276
+ } ) ;
277
+
257
278
addBlinkerBtn . on ( "click" , ( ) => {
258
279
automaton . placePatternRandomly ( blinkerPattern ( ) )
259
280
} )
0 commit comments