From 98eaf73f8c9ca8ba16acca2073f42117d483bced Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Fri, 13 Jul 2018 18:38:38 +0200 Subject: [PATCH] utils: add PunchNumber utility --- src/utils.c | 17 +++++++++++++++++ src/utils.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/utils.c b/src/utils.c index 61ba1de..3cd3e73 100644 --- a/src/utils.c +++ b/src/utils.c @@ -508,3 +508,20 @@ SYMBOL_EXPORT void DisableCompositor(struct Game* game) { game->handlers.compositor = NULL; ResizeGamestates(game); } + +SYMBOL_EXPORT char* PunchNumber(struct Game* game, char* text, char ch, int number) { + char* txt = strdup(text); + char* tmp = txt; + while (*tmp) { + tmp++; + } + int num = 1; + while (tmp != txt) { + tmp--; + if (*tmp == ch) { + *tmp = '0' + (int)floor(number / (float)num) % 10; + num *= 10; + } + }; + return AddGarbage(game, txt); +} diff --git a/src/utils.h b/src/utils.h index 8426d2c..f083b18 100644 --- a/src/utils.h +++ b/src/utils.h @@ -90,4 +90,6 @@ ALLEGRO_BITMAP* CreateNotPreservedBitmap(int width, int height); void EnableCompositor(struct Game* game, void compositor(struct Game* game, struct Gamestate* gamestates)); void DisableCompositor(struct Game* game); +char* PunchNumber(struct Game* game, char* text, char ch, int number); + #endif