From 0eccd8eea8c2caba4f9c52b7aaa3991eb6813505 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Luk=C3=A1=C5=A1=20Ji=C5=99i=C5=A1t=C4=9B?= Date: Mon, 11 Mar 2024 14:27:17 +0100 Subject: [PATCH] Implement j, k for up and down movement in -l mode This led to the necessity to rename kill to defeat. The option -k has thus been renamed -d and in the loop mode "d" key is used for what "k" used to do. --- inc/palboss.h | 6 +++--- src/loop.c | 12 ++++++------ src/main.c | 26 +++++++++++++------------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/inc/palboss.h b/inc/palboss.h index 62b75be..d22db27 100644 --- a/inc/palboss.h +++ b/inc/palboss.h @@ -9,14 +9,14 @@ typedef struct s_database_entry { int level; - time_t kill_time; + time_t defeat_time; char *name; char *biome; } t_entry; typedef enum e_basic_command { - basic_kill, + basic_defeat, basic_add, basic_list, basic_loop, @@ -42,6 +42,6 @@ typedef struct s_term } t_term; void loop(t_vec *database); -void kill_entry(t_vec *database, size_t ind); +void defeat_entry(t_vec *database, size_t ind); void print_entry(t_entry *entry); #endif //PALBOSS_H diff --git a/src/loop.c b/src/loop.c index aa30e73..4f2f3f2 100644 --- a/src/loop.c +++ b/src/loop.c @@ -90,28 +90,28 @@ void print_noncanon(t_vec *database, t_term *term) int handle_buffer(const char *buffer, t_vec *database, t_term *term) { - if (!ft_strcmp(buffer, "\033[A")) + if (!ft_strcmp(buffer, "\033[A") || !ft_strcmp(buffer, "k")) { if (term->y > 1) { --term->y; - ft_putstr_fd(buffer, STDOUT_FILENO); + ft_putstr_fd("\033[A", STDOUT_FILENO); } else if (term->top_row > 0) --term->top_row; } - else if (!ft_strcmp(buffer, "\033[B")) + else if (!ft_strcmp(buffer, "\033[B") || !ft_strcmp(buffer, "j")) { if (term->y < term->height && term->y < database->size - term->top_row) { ++term->y; - ft_putstr_fd(buffer, STDOUT_FILENO); + ft_putstr_fd("\033[B", STDOUT_FILENO); } else if (database->size - term->top_row > term->height) ++term->top_row; } - else if (!ft_strcmp(buffer, "k") && term->top_row + term->y - 1 < database->size) - kill_entry(database, term->top_row + term->y - 1); + else if (!ft_strcmp(buffer, "d") && term->top_row + term->y - 1 < database->size) + defeat_entry(database, term->top_row + term->y - 1); else if (!ft_strcmp(buffer, "q") || !ft_strcmp(buffer, "\033")) return (1); return (0); diff --git a/src/main.c b/src/main.c index 91d783b..9afea1f 100644 --- a/src/main.c +++ b/src/main.c @@ -17,7 +17,7 @@ int write_entry(int fd, t_entry *entry) entry->name, entry->level, entry->biome, - entry->kill_time); + entry->defeat_time); return (0); } @@ -64,7 +64,7 @@ void print_entry(t_entry *entry) char *color; static const char *reset_color = "\033[0m"; - countdown = 3600 - (get_time_sec() - entry->kill_time); + countdown = 3600 - (get_time_sec() - entry->defeat_time); countdown = ft_max(0, countdown); if (countdown == 0) color = "\033[42m"; @@ -122,7 +122,7 @@ int parse_line(char *line, t_vec *database) new_entry.biome = line; if (advance_line(&line)) return (1); - new_entry.kill_time = ft_atoi(line); + new_entry.defeat_time = ft_atoi(line); if (advance_line(&line)) return (1); if (*line != '\0') @@ -180,7 +180,7 @@ int construct_new_entry(t_entry *entry, char **argv) entry->name = datastr; entry->level = ft_atoi(argv[3]); entry->biome = datastr + namelen + 1; - entry->kill_time = 0; + entry->defeat_time = 0; return (0); } @@ -207,11 +207,11 @@ int parse_input(t_command *command, int argc, char **argv) } else if (argc == 3) { - if (ft_strcmp(argv[1], "-k") && ft_strcmp(argv[1], "-r")) + if (ft_strcmp(argv[1], "-d") && ft_strcmp(argv[1], "-r")) return (1); command->entry.name = argv[2]; - if (argv[1][1] == 'k') - command->basic = basic_kill; + if (argv[1][1] == 'd') + command->basic = basic_defeat; else if (argv[1][1] == 'r') command->basic = basic_remove; return (0); @@ -224,12 +224,12 @@ int parse_input(t_command *command, int argc, char **argv) return (1); } -void kill_entry(t_vec *database, size_t ind) +void defeat_entry(t_vec *database, size_t ind) { t_entry entry; entry = *(t_entry *)ft_vec_access(database, ind); - entry.kill_time = get_time_sec(); + entry.defeat_time = get_time_sec(); ft_vec_forget(database, ind); ft_vec_append(database, &entry); return ; @@ -267,8 +267,8 @@ void print_help(void) "\t\tPrint this help.\n" "\t-l\n" "\t\tPrint the list in a loop. End by using Q key.\n" - "\t-k boss\n" - "\t\tMark the boss as killed, setting the counter to 60 minutes.\n" + "\t-d boss\n" + "\t\tMark the boss as defeated, setting the counter to 60 minutes.\n" "\t-a boss level location\n" "\t\tAdd a boss to the database. Long strings may break formatting.\n" "\t-r boss\n" @@ -287,8 +287,8 @@ void carry_out_command(t_command *com, t_vec *database) ft_printf("Problem with the name!\n"); return ; } - if (com->basic == basic_kill) - kill_entry(database, ind); + if (com->basic == basic_defeat) + defeat_entry(database, ind); else if (com->basic == basic_remove) ft_vec_erase(database, ind, free_entry); else if (com->basic == basic_add) -- 2.30.2