Make setting node possible in schema mode
authorLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Sat, 29 Mar 2025 20:50:47 +0000 (21:50 +0100)
committerLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Sat, 29 Mar 2025 20:50:47 +0000 (21:50 +0100)
src/main.c
src/schema_mode.c

index 7ed93d638658d72fe9e86c82ce9973596015dc09..384797d71614e0215da9ec42b44b1239cd2e27fb 100644 (file)
@@ -96,10 +96,10 @@ int parse_terminal(const char *str, t_terminal *term)
 
 int    parse_state(const char *str, t_state *state)
 {
-       if(!ft_strcmp(str, "on"))
-               *state = on;
-       else if (!ft_strcmp(str, "off"))
+       if (!ft_strcmp(str, "off"))
                *state = off;
+       else if (!ft_strcmp(str, "on"))
+               *state = on;
        else if (!ft_strcmp(str, "pd") || !ft_strcmp(str, "pull_down"))
                *state = pull_down;
        else if (!ft_strcmp(str, "pu") || !ft_strcmp(str, "pull_up"))
index 644b25ce4747d7b466de94893f77598e5f4c1d7a..fb66c2db5b28f9b8e9777db6a220fcc5f2a2fb8e 100644 (file)
@@ -321,6 +321,23 @@ void       schema_user_draw_node(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets,
        return ;
 }
 
+void schema_switch_mode(WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets, t_position pos)
+{
+       t_node  *chosen_node;
+
+       chosen_node = find_node_at_pos(nodes, pos);
+       if (!chosen_node)
+               return ;
+       if (chosen_node->set_state == unknown)
+               chosen_node->set_state = off;
+       else
+               ++chosen_node->set_state;
+       update_nodes(nodes, mosfets);
+       refresh_schema_win(schematics_win, nodes, mosfets);
+       wmove(schematics_win, pos.y, pos.x);
+       return ;
+}
+
 int    handle_key_press(int ch, WINDOW *schematics_win, t_vec *nodes, t_vec *mosfets)
 {
        t_position      pos;
@@ -338,6 +355,8 @@ int handle_key_press(int ch, WINDOW *schematics_win, t_vec *nodes, t_vec *mosfet
                schema_add_mosfet(schematics_win, nodes, mosfets, pos);
        else if (ch == 'c')
                schema_user_draw_node(schematics_win, nodes, mosfets, pos);
+       else if (ch == 's')
+               schema_switch_mode(schematics_win, nodes, mosfets, pos);
        return (0);
 }