]> git.f4mnq.fr Git - cells.git/commitdiff
Ajout du nom de l'automate aux fichiers de sauvegarde
authorAmélia Coutard-Sander <git@f4mnq.fr>
Wed, 7 Jan 2026 13:38:53 +0000 (14:38 +0100)
committerAmélia Coutard-Sander <git@f4mnq.fr>
Wed, 7 Jan 2026 13:53:54 +0000 (14:53 +0100)
bin/modes.ml

index 9684937de96e9fb637f40bdd24ec45026248fc86..6bdd1dd6539e359c380f0cbbd30bacbd344f9155 100644 (file)
@@ -148,14 +148,27 @@ module rec Command : (Mode with type initer = string) = struct
                             Printf.fprintf stderr "Automate inconnu: `%s' !\n%!" auto;
                             (estate, Either.right (ModeAux.ModeAndState ((module Normal), Normal.initial ()))))
             | ["write"; f] ->
-                    (try Out_channel.with_open_text f (Automata.serialise (module M) st.board)
+                    (try
+                       Out_channel.with_open_text f (fun f ->
+                           Printf.fprintf f "%s\n" M.name;
+                           Automata.serialise (module M) st.board f)
                      with Sys_error _ -> Printf.fprintf stderr "Failed to write file `%s' !\n%!" f);
                     (EditorState (m, st), Either.right (ModeAux.ModeAndState ((module Normal), Normal.initial ())))
             | ["read"; f] -> (
                     try
-                      ( EditorState
-                          (m, { st with board = In_channel.with_open_text f (Automata.deserialise (module M)) }),
-                        Either.right (ModeAux.ModeAndState ((module Normal), Normal.initial ())) )
+                      In_channel.with_open_text f (fun f ->
+                          let name = Option.get (In_channel.input_line f) in
+                          let auto = List.find (fun m -> get_name m = name) Automata.automata in
+                          let module M = (val auto) in
+                          ( EditorState
+                              ( (module M),
+                                {
+                                  board = Automata.deserialise (module M) f;
+                                  pos = st.pos;
+                                  current = M.default;
+                                  size = st.size;
+                                } ),
+                            Either.right (ModeAux.ModeAndState ((module Normal), Normal.initial ())) ))
                     with Sys_error _ ->
                       Printf.fprintf stderr "Failed to write file `%s' !\n%!" f;
                       (estate, Either.right (ModeAux.ModeAndState ((module Normal), Normal.initial ()))))