Truncate Scores (#269)

* Fixed score truncation erasure, and centering for chips, mult, score and "temp score

* Added centering for money

* Added tests for truncate_uint_to_suffixed_str()

* Fixed u32 bug with get_digits

* Fixed score flames for large numbers

* Small change to update documentation

* Added 1 pixel on to score rect on the left to make room for full character tile + reset_top_left_panel_bottom_row() refactor

* Replaced directional defines with enums

* Updated ante_lut comment

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
MeirGavish
2025-12-02 08:28:36 +02:00
committed by GitHub
co-authored by Copilot
parent 07cab81ba1
commit 43d837571e
14 changed files with 411 additions and 148 deletions
+40
View File
@@ -1,5 +1,7 @@
#include "util.h"
#include <limits.h>
#include <stdio.h>
#include <stdbool.h>
int int_arr_max(int int_arr[], int size)
{
@@ -15,6 +17,44 @@ int int_arr_max(int int_arr[], int size)
return max;
}
void truncate_uint_to_suffixed_str(uint32_t num, int num_req_chars, char out_str_buff[UINT_MAX_DIGITS + 1])
{
bool inevitable_overflow = num_req_chars < SUFFIXED_NUM_MIN_REQ_CHARS;
if (inevitable_overflow)
{
num_req_chars = SUFFIXED_NUM_MIN_REQ_CHARS;
}
int num_digits = u32_get_digits(num);
int overflow_size = num_digits - num_req_chars;
char* suffix = "";
/* If there is overflow, divide by the next suffixed power of 10
* to truncate the number back within num_req_chars.
* UINT32_MAX is in the billions so no need to check larger numbers
* or perform complex mathematical operations.
*/
if (overflow_size >= ONE_M_ZEROS)
{
num /= ONE_B;
suffix = "B";
}
else if (overflow_size >= ONE_K_ZEROS)
{
num /= ONE_M;
suffix = "M";
}
else if (overflow_size > 0
|| (inevitable_overflow && num_digits == SUFFIXED_NUM_MIN_REQ_CHARS))
// Special case - alleviate inevitable overflow for 1000s and truncate them to "1K"s
{
num /= ONE_K;
suffix = "K";
}
snprintf(out_str_buff, UINT_MAX_DIGITS + 1, "%lu%s", num, suffix);
}
// Avoid uint overflow when add/multiplying score
uint32_t u32_protected_add(uint32_t a, uint32_t b)