Skip to content

Commit

Permalink
feat: disable and better error instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
xtruan committed Jun 3, 2024
1 parent 4b47286 commit 1a299d5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
4 changes: 2 additions & 2 deletions flipenigma.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ FlipEnigma* flipenigma_app_alloc() {
TEXT_BUFFER_SIZE,
// clear default text
true);
text_input_set_header_text(app->message_input, "Input Message");
text_input_set_header_text(app->message_input, "Input message");
view_dispatcher_add_view(
app->view_dispatcher,
FlipEnigmaViewIdMessageInput,
Expand All @@ -113,7 +113,7 @@ FlipEnigma* flipenigma_app_alloc() {
TEXT_BUFFER_SIZE,
// clear default text
true);
text_input_set_header_text(app->plugboard_input, "Input Plugboard");
text_input_set_header_text(app->plugboard_input, "Input plugboard or X to disable");
view_dispatcher_add_view(
app->view_dispatcher,
FlipEnigmaViewIdPlugboardInput,
Expand Down
52 changes: 37 additions & 15 deletions helpers/flipenigma_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@
#define ENIGMA_IMPLEMENTATION
#include "../enigma/enigma.h"

#define PLUGBOARD_ERROR_TEXT "Error parsing plugboard\n-> Must be evenly paired\n-> Must be unique"
#define TEXT_PLUGBOARD_DISABLED "Plugboard disabled"
#define TEXT_PLUGBOARD_ERROR \
"Error parsing plugboard!\n" \
"The plugboard text must be\n" \
"an even number of unique \n" \
"letters. These are interpret-\n" \
"ed as connected pairs.\n" \
"There is a maximum of 10\n" \
"connections (20 letters).\n" \
"To disable the plugboard,\n" \
"input the letter 'X'."

void text_string_to_uppercase(char* input) {
int i;
Expand Down Expand Up @@ -149,24 +159,36 @@ void text_input_callback(void* context) {
if(strlen(app->input_plugboard_text) > 0) {
// Convert the text to uppercase
text_string_to_uppercase(app->input_plugboard_text);
// Do the actual work of parsing the plugboard
app->plugboard_size = text_validate_and_convert_plugboard(
app->input_plugboard_text, app->plugboard_switches);
if(app->plugboard_size == 0) {
flipenigma_play_bad_bump(app);
// Populate text box with error text
text_box_set_text(app->text_box, PLUGBOARD_ERROR_TEXT);
// Set show_text_box boolean
show_text_box = true;
} else {

// Check for disable case
if(strcmp(app->input_plugboard_text, "X") == 0) {
app->plugboard_size = 0;
flipenigma_play_happy_bump(app);
text_normalize_spacing(app->input_plugboard_text, app->plain_text, 2);
// Populate text box with plugboard text
text_box_set_text(app->text_box, app->plain_text);
// Populate text box with info text
text_box_set_text(app->text_box, TEXT_PLUGBOARD_DISABLED);
// Set show_text_box boolean
show_text_box = true;
}
// text_input_set_header_text(app->plugboard_input, app->input_plugboard_text);
// Do the actual work of parsing the plugboard
else {
app->plugboard_size = text_validate_and_convert_plugboard(
app->input_plugboard_text, app->plugboard_switches);
if(app->plugboard_size == 0) {
flipenigma_play_bad_bump(app);
// Populate text box with error text
text_box_set_text(app->text_box, TEXT_PLUGBOARD_ERROR);
// Set show_text_box boolean
show_text_box = true;
} else {
flipenigma_play_happy_bump(app);
text_normalize_spacing(app->input_plugboard_text, app->plain_text, 2);
// Populate text box with plugboard text
text_box_set_text(app->text_box, app->plain_text);
// Set show_text_box boolean
show_text_box = true;
}
// text_input_set_header_text(app->plugboard_input, app->input_plugboard_text);
}
}
}

Expand Down

0 comments on commit 1a299d5

Please sign in to comment.