From 59ab3594e522a4ef553d6ed8eea29aa7728dcf87 Mon Sep 17 00:00:00 2001 From: nesbox Date: Fri, 25 Aug 2023 16:54:02 +0200 Subject: [PATCH] #2268: fixed font() api arguments count --- src/api.h | 16 ++++++++-------- src/api/js.c | 13 ++++--------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/api.h b/src/api.h index 9ce7d5813..d3431176d 100644 --- a/src/api.h +++ b/src/api.h @@ -290,7 +290,7 @@ enum 0, \ void, \ tic_mem*, s32 index, s32 x, s32 y, s32 w, s32 h, \ - u8* trans_colors, u8 trans_count, s32 scale, tic_flip flip, tic_rotate rotate) \ + u8* trans_colors, u8 trans_count, s32 scale, tic_flip flip, tic_rotate rotate) \ \ \ macro(btn, \ @@ -363,7 +363,7 @@ enum "The map can be up to 240 cells wide by 136 deep.\n" \ "This function will draw the desired area of the map to a specified screen position.\n" \ "For example, map(5,5,12,10,0,0) will draw a 12x10 section of the map, " \ - "starting from map coordinates (5,5) to screen position (0,0).\n" \ + "starting from map coordinates (5,5) to screen position (0,0).\n" \ "The map function's last parameter is a powerful callback function " \ "for changing how map cells (sprites) are drawn when map is called.\n" \ "It can be used to rotate, flip and replace sprites while the game is running.\n" \ @@ -379,7 +379,7 @@ enum 1, \ void, \ tic_mem*, s32 x, s32 y, s32 width, s32 height, s32 sx, s32 sy, \ - u8* trans_colors, u8 trans_count, s32 scale, RemapFunc remap, void* data) \ + u8* trans_colors, u8 trans_count, s32 scale, RemapFunc remap, void* data) \ \ \ macro(mget, \ @@ -606,17 +606,17 @@ enum \ \ macro(font, \ - "font(text x y chromakey char_width char_height fixed=false scale=1) -> width", \ + "font(text x y chromakey char_width char_height fixed=false scale=1 alt=false) -> width", \ \ "Print string with font defined in foreground sprites.\n" \ "To simply print to the screen, check out `print()`.\n" \ "To print to the console, check out `trace()`.", \ - 8, \ + 9, \ 6, \ 0, \ s32, \ tic_mem*, const char* text, s32 x, s32 y, \ - u8* trans_colors, u8 trans_count, s32 w, s32 h, bool fixed, s32 scale, bool alt) \ + u8* trans_colors, u8 trans_count, s32 w, s32 h, bool fixed, s32 scale, bool alt) \ \ \ macro(mouse, \ @@ -700,8 +700,8 @@ enum tic_mem*, float x1, float y1, float x2, float y2, float x3, float y3, u8 color) \ \ \ - macro(ttri, \ - "ttri(x1 y1 x2 y2 x3 y3 u1 v1 u2 v2 u3 v3 texsrc=0 chromakey=-1 z1=0 z2=0 z3=0)", \ + macro(ttri, \ + "ttri(x1 y1 x2 y2 x3 y3 u1 v1 u2 v2 u3 v3 texsrc=0 chromakey=-1 z1=0 z2=0 z3=0)", \ \ "It renders a triangle filled with texture from image ram, map ram or vbank.\n" \ "Use in 3D graphics.\n" \ diff --git a/src/api/js.c b/src/api/js.c index 19705ac0d..275311dc9 100644 --- a/src/api/js.c +++ b/src/api/js.c @@ -675,18 +675,13 @@ static JSValue js_font(JSContext *ctx, JSValueConst this_val, s32 argc, JSValueC s32 x = getInteger(ctx, argv[1]); s32 y = getInteger(ctx, argv[2]); u8 chromakey = getInteger(ctx, argv[3]); - s32 width = getInteger2(ctx, argv[4], TIC_SPRITESIZE); - s32 height = getInteger2(ctx, argv[5], TIC_SPRITESIZE); + s32 width = getInteger2(ctx, argv[4], TIC_SPRITESIZE); + s32 height = getInteger2(ctx, argv[5], TIC_SPRITESIZE); bool fixed = JS_ToBool(ctx, argv[6]); - s32 scale = getInteger2(ctx, argv[7], 1); + s32 scale = getInteger2(ctx, argv[7], 1); bool alt = JS_ToBool(ctx, argv[8]); - if(scale == 0) - { - return JS_NewInt32(ctx, 0); - } - - s32 size = tic_api_font(tic, text, x, y, &chromakey, 1, width, height, fixed, scale, alt); + s32 size = scale ? tic_api_font(tic, text, x, y, &chromakey, 1, width, height, fixed, scale, alt) : 0; JS_FreeCString(ctx, text); return JS_NewInt32(ctx, size);