Commit 857d13d0 authored by Chris's avatar Chris
Browse files

various refactors and cleanups

parent 74ff9208
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -7,4 +7,5 @@ add_executable(yahtc yaht.c graphics.c
        dicelogic.h
        dicelogic.c
        utils.h
        utils.c)
        utils.c
        menu.c)
+2 −1
Original line number Diff line number Diff line
// dicelogic.c

#include <stdio.h>
#include "dicelogic.h"
#include "graphics.h"
#include "utils.h"
@@ -13,7 +14,7 @@ void roll_and_print(game_context *ctx, unsigned int *out_dice_values, int animat
        generate_dice_roll(ctx, temporary_next_roll, 0);
        print_multiple_dice(temporary_next_roll, NUM_DICE);
        sleep_ms(50);
        clear_dice();
        cursor_to_dice_start(0);
    }
    // the last roll will be the one that is saved in game state
    generate_dice_roll(ctx, out_dice_values, 1);
+0 −1
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@

#ifndef DICELOGIC_H
#define DICELOGIC_H
#include <stdio.h>

extern const int NUM_DICE;

+6 −4
Original line number Diff line number Diff line
@@ -22,14 +22,16 @@ void print_multiple_dice(const unsigned int *die_value, const int n) {
	}
}

// to only be called after print_multiple_dice()
// todo this is a misnomer for this function: it doesn't clear anything, it just moves the cursor
//		(or make it actually clear, conditionally/otherwise)
void clear_dice() {
// to only be called after print_multiple_dice() as this will return the terminal cursor to its original positon
//		useful for erasing or positioning for redraw of dice area
void cursor_to_dice_start(const int erase_lines) {
	// move cursor up
	// for (int i = 0; i < DIE_VERTICAL_LENGTH + 1; i++) {
	for (int i = 0; i < DIE_VERTICAL_LENGTH; i++) {
		printf("\033[A"); // move cursor up one line
		if (i < erase_lines) {
			printf("\033[2K"); // clear entire line
		}
	}
	// move cursor all the way to the left
	printf("\r");
+2 −2
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ static const char *DICE[7][6] = {
};

void print_single_die(unsigned int die_value);
void print_multiple_dice(const unsigned int *die_value, const int n);
void clear_dice();
void print_multiple_dice(const unsigned int *die_value, int n);
void cursor_to_dice_start(int erase_lines);

#endif //GRAPHICS_H_
Loading