From 6d3651ffe8672c768d26ae4ba55cc65145bda7e0 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 7 Aug 2023 22:57:02 -0700 Subject: modules/rkt: make NEWSCENE state a simple function This doesn't need to be a distinct state since it's basically just a banner for the start of the newscene process which never recurs, it's not an interactive prompt or dialog of any kind... --- src/modules/rkt/rkt_scener.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'src/modules') diff --git a/src/modules/rkt/rkt_scener.c b/src/modules/rkt/rkt_scener.c index dfe22b1..3e4126c 100644 --- a/src/modules/rkt/rkt_scener.c +++ b/src/modules/rkt/rkt_scener.c @@ -44,7 +44,6 @@ typedef enum rkt_scener_fsm_t { RKT_SCENER_FSM_RECV_SCENES, /* waiting/reading at main scenes prompt */ RKT_SCENER_FSM_SEND_SCENE, /* send per-scene dialog for scene @ scener->scene -> prompt */ RKT_SCENER_FSM_RECV_SCENE, /* waiting/reading at the per-scene prompt */ - RKT_SCENER_FSM_SEND_NEWSCENE, /* send create new scene dialog -> prompt */ RKT_SCENER_FSM_RECV_NEWSCENE, /* waiting/reading at the new scene prompt, creating/setting up new scene on input */ RKT_SCENER_FSM_SEND_NEWSCENE_SETUP, /* send whatever's necessary for next step of new_scene.settings setup */ RKT_SCENER_FSM_SEND_NEWSCENE_SETUP_PROMPT, @@ -255,6 +254,23 @@ static int rkt_scener_send_goodbye(rkt_scener_t *scener, rkt_scener_fsm_t next_s } +static int rkt_scener_new_scene(rkt_context_t *ctxt) +{ + rkt_scener_t *scener; + til_str_t *output; + + assert(ctxt); + scener = ctxt->scener; + assert(scener); + + output = til_str_new("Input new scene \"module[,settings...]\" :\n"); + if (!output) + return rkt_scener_err_close(scener, ENOMEM); + + return rkt_scener_send(scener, output, RKT_SCENER_FSM_RECV_NEWSCENE); +} + + /* handle input from the main scenes prompt */ static int rkt_scener_handle_input_scenes(rkt_context_t *ctxt) { @@ -301,8 +317,7 @@ static int rkt_scener_handle_input_scenes(rkt_context_t *ctxt) case 'N': /* Add new scene */ case 'n': - scener->state = RKT_SCENER_FSM_SEND_NEWSCENE; - break; + return rkt_scener_new_scene(ctxt); case 'S': /* Serialize current settings for the entire rkt scenes state */ case 's': @@ -688,8 +703,7 @@ static int rkt_scener_handle_input_scene(rkt_context_t *ctxt) case 'N': case 'n': - scener->state = RKT_SCENER_FSM_SEND_NEWSCENE; - break; + return rkt_scener_new_scene(ctxt); case '!': /* toggle pin_scene */ scener->pin_scene = !scener->pin_scene; @@ -974,16 +988,6 @@ int rkt_scener_update(rkt_context_t *ctxt) return rkt_scener_handle_input_scenes(ctxt); - case RKT_SCENER_FSM_SEND_NEWSCENE: { - til_str_t *output; - - output = til_str_new("Input new scene \"module[,settings...]\" :\n"); - if (!output) - return rkt_scener_err_close(scener, ENOMEM); - - return rkt_scener_send(scener, output, RKT_SCENER_FSM_RECV_NEWSCENE); - } - case RKT_SCENER_FSM_RECV_NEWSCENE: if (!scener->input) return rkt_scener_recv(scener, scener->state); -- cgit v1.2.3