Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where parse_time was parsing CLI flags on F5 #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <time.h>

Expand Down Expand Up @@ -240,19 +241,21 @@ int main(int argc, char **argv)
{
Mode mode = MODE_ASCENDING;
float displayed_time = 0.0f;
int paused = 0;
int exit_after_countdown = 0;
float start_time = 0.0f;
bool paused = false;
bool exit_after_countdown = false;

for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-p") == 0) {
paused = 1;
paused = true;
} else if (strcmp(argv[i], "-e") == 0) {
exit_after_countdown = 1;
exit_after_countdown = true;
} else if (strcmp(argv[i], "clock") == 0) {
mode = MODE_CLOCK;
} else {
mode = MODE_COUNTDOWN;
displayed_time = parse_time(argv[i]);
start_time = parse_time(argv[i]);
displayed_time = start_time;
}
}

Expand Down Expand Up @@ -286,7 +289,7 @@ int main(int argc, char **argv)
secc(SDL_SetTextureColorMod(digits, MAIN_COLOR_R, MAIN_COLOR_G, MAIN_COLOR_B));
}

int quit = 0;
bool quit = false;
size_t wiggle_index = 0;
float wiggle_cooldown = WIGGLE_DURATION;
float user_scale = 1.0f;
Expand All @@ -299,7 +302,7 @@ int main(int argc, char **argv)
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT: {
quit = 1;
quit = true;
} break;

case SDL_KEYDOWN: {
Expand Down Expand Up @@ -329,20 +332,10 @@ int main(int argc, char **argv)
} break;

case SDLK_F5: {
displayed_time = 0.0f;
paused = 0;
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-p") == 0) {
paused = 1;
} else {
displayed_time = parse_time(argv[i]);
}
}
if (paused) {
secc(SDL_SetTextureColorMod(digits, PAUSE_COLOR_R, PAUSE_COLOR_G, PAUSE_COLOR_B));
} else {
secc(SDL_SetTextureColorMod(digits, MAIN_COLOR_R, MAIN_COLOR_G, MAIN_COLOR_B));
if (mode == MODE_CLOCK) {
break;
}
displayed_time = start_time;
} break;

case SDLK_F11: {
Expand Down