Add command "next" to schema
authorLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Sat, 29 Mar 2025 21:06:34 +0000 (22:06 +0100)
committerLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Sat, 29 Mar 2025 21:06:34 +0000 (22:06 +0100)
src/c_next.c
src/schema_mode.c
src/sim_main.c

index 2bf6a81441da3ca3106f253fdb83c9ab59e1055c..ef86bb64713ba3bf89f97cba4f6bead5514f88f0 100644 (file)
@@ -7,15 +7,14 @@ int   c_next(t_input input, t_vec *nodes, t_vec *mosfets)
 
        if (input.argc == 0)
        {
-               if (!sim_step(nodes, mosfets))
-                       return (0);
+               return (!sim_step(nodes, mosfets));
        }
        else if (input.argc == 1 && input.argv[0].type == num)
        {
                i = 0;
                while (i < input.argv[0].val.num)
                {
-                       if (!sim_step(nodes, mosfets))
+                       if (sim_step(nodes, mosfets))
                                return (0);
                        ++i;
                }
index fb66c2db5b28f9b8e9777db6a220fcc5f2a2fb8e..7e4d7382e08171bfd3dc185efe616660cd7286ca 100644 (file)
@@ -338,6 +338,15 @@ void schema_switch_mode(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets, t_
        return ;
 }
 
+int    schema_next(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos)
+{
+       if (sim_step(nodes, mosfets))
+               return (1);
+       refresh_schema_win(schematics_win, nodes, mosfets);
+       wmove(schematics_win, pos.y, pos.x);
+       return (0);
+}
+
 int    handle_key_press(int ch, WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets)
 {
        t_position      pos;
@@ -357,6 +366,8 @@ int handle_key_press(int ch, WINDOW *schematics_win, t_vec *nodes, t_vec *mosfet
                schema_user_draw_node(schematics_win, nodes, mosfets, pos);
        else if (ch == 's')
                schema_switch_mode(schematics_win, nodes, mosfets, pos);
+       else if (ch == 'n')
+               schema_next(schematics_win, nodes, mosfets, pos);
        return (0);
 }
 
index cb52bf1d2bdcec7d3ae5eb996a31fc73a53c879c..a624dcfbf45eda4eb993c07aefd75497fb2da7f9 100644 (file)
@@ -29,5 +29,5 @@ int   sim_step(t_vec *nodes, t_vec *mosfets)
 {
        update_mosfets(nodes, mosfets);
        update_nodes(nodes, mosfets);
-       return (1);
+       return (0);
 }