utils: add PunchNumber utility

This commit is contained in:
Sebastian Krzyszkowiak 2018-07-13 18:38:38 +02:00
parent 6061b8d1bb
commit 98eaf73f8c
2 changed files with 19 additions and 0 deletions

View file

@ -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);
}

View file

@ -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