From: Holger Schemel Date: Sun, 30 May 2021 21:40:29 +0000 (+0200) Subject: added command line function to write element collecting image to directory X-Git-Tag: 4.3.0.0~143 X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=commitdiff_plain;h=367e1c8fd001e62da9db2af6ba9e523cc9165a83 added command line function to write element collecting image to directory --- diff --git a/src/files.c b/src/files.c index 40d7fb73..83efc958 100644 --- a/src/files.c +++ b/src/files.c @@ -13131,6 +13131,104 @@ void CreateLevelSketchImages(void) } +// ---------------------------------------------------------------------------- +// create and save images for element collecting animations (raw BMP format) +// ---------------------------------------------------------------------------- + +static boolean createCollectImage(int element) +{ + return (IS_COLLECTIBLE(element) && !IS_SP_ELEMENT(element)); +} + +void CreateCollectElementImages(void) +{ + int i, j; + int num_steps = 8; + int anim_frames = num_steps - 1; + int tile_size = TILESIZE; + int anim_width = tile_size * anim_frames; + int anim_height = tile_size; + int num_collect_images = 0; + int pos_collect_images = 0; + + for (i = 0; i < MAX_NUM_ELEMENTS; i++) + if (createCollectImage(i)) + num_collect_images++; + + Info("Creating %d element collecting animation images ...", + num_collect_images); + + int dst_width = anim_width * 2; + int dst_height = anim_height * num_collect_images / 2; + Bitmap *dst_bitmap = CreateBitmap(dst_width, dst_height, DEFAULT_DEPTH); + char *basename = "RocksCollect.bmp"; + char *filename = getPath2(global.create_collect_images_dir, basename); + + for (i = 0; i < MAX_NUM_ELEMENTS; i++) + { + if (!createCollectImage(i)) + continue; + + int dst_x = (pos_collect_images / (num_collect_images / 2)) * anim_width; + int dst_y = (pos_collect_images % (num_collect_images / 2)) * anim_height; + int graphic = el2img(i); + char *token_name = element_info[i].token_name; + Bitmap *tmp_bitmap = CreateBitmap(tile_size, tile_size, DEFAULT_DEPTH); + Bitmap *src_bitmap; + int src_x, src_y; + + Info("- creating collecting image for '%s' ...", token_name); + + getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y); + + BlitBitmap(src_bitmap, tmp_bitmap, src_x, src_y, + tile_size, tile_size, 0, 0); + + tmp_bitmap->surface_masked = tmp_bitmap->surface; + + for (j = 0; j < anim_frames; j++) + { + int frame_size_final = tile_size * (anim_frames - j) / num_steps; + int frame_size = frame_size_final * num_steps; + int offset = (tile_size - frame_size_final) / 2; + Bitmap *frame_bitmap = ZoomBitmap(tmp_bitmap, frame_size, frame_size); + + while (frame_size > frame_size_final) + { + frame_size /= 2; + + Bitmap *half_bitmap = ZoomBitmap(frame_bitmap, frame_size, frame_size); + + FreeBitmap(frame_bitmap); + + frame_bitmap = half_bitmap; + } + + BlitBitmap(frame_bitmap, dst_bitmap, 0, 0, + frame_size_final, frame_size_final, + dst_x + j * tile_size + offset, dst_y + offset); + + FreeBitmap(frame_bitmap); + } + + tmp_bitmap->surface_masked = NULL; + + FreeBitmap(tmp_bitmap); + + pos_collect_images++; + } + + if (SDL_SaveBMP(dst_bitmap->surface, filename) != 0) + Fail("cannot save element collecting image file '%s'", filename); + + FreeBitmap(dst_bitmap); + + Info("Done."); + + CloseAllAndExit(0); +} + + // ---------------------------------------------------------------------------- // create and save images for custom and group elements (raw BMP format) // ---------------------------------------------------------------------------- diff --git a/src/files.h b/src/files.h index 194e1c22..c788bfcb 100644 --- a/src/files.h +++ b/src/files.h @@ -98,6 +98,7 @@ void LoadHelpTextInfo(void); void ConvertLevels(void); void CreateLevelSketchImages(void); +void CreateCollectElementImages(void); void CreateCustomElementImages(char *); void FreeGlobalAnimEventInfo(void); diff --git a/src/init.c b/src/init.c index 528404b7..d266989d 100644 --- a/src/init.c +++ b/src/init.c @@ -4906,6 +4906,7 @@ static void InitGlobal(void) global.dumplevel_leveldir = NULL; global.dumptape_leveldir = NULL; global.create_sketch_images_dir = NULL; + global.create_collect_images_dir = NULL; global.frames_per_second = 0; global.show_frames_per_second = FALSE; @@ -5197,6 +5198,14 @@ static void Execute_Command(char *command) Fail("image target directory '%s' not found or not writable", global.create_sketch_images_dir); } + else if (strPrefix(command, "create collect image ")) + { + global.create_collect_images_dir = getStringCopy(&command[21]); + + if (access(global.create_collect_images_dir, W_OK) != 0) + Fail("image target directory '%s' not found or not writable", + global.create_collect_images_dir); + } else if (strPrefix(command, "create CE image ")) { CreateCustomElementImages(&command[16]); @@ -6299,6 +6308,11 @@ void OpenAll(void) CreateLevelSketchImages(); return; } + else if (global.create_collect_images_dir) + { + CreateCollectElementImages(); + return; + } InitNetworkServer(); diff --git a/src/libgame/system.c b/src/libgame/system.c index 9f8e3075..28d8ebae 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -1193,7 +1193,7 @@ void ReloadCustomImage(Bitmap *bitmap, char *basename) free(new_bitmap); } -static Bitmap *ZoomBitmap(Bitmap *src_bitmap, int zoom_width, int zoom_height) +Bitmap *ZoomBitmap(Bitmap *src_bitmap, int zoom_width, int zoom_height) { return SDLZoomBitmap(src_bitmap, zoom_width, zoom_height); } diff --git a/src/libgame/system.h b/src/libgame/system.h index a02459d8..e59edf83 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -1952,6 +1952,7 @@ Bitmap *LoadImage(char *); Bitmap *LoadCustomImage(char *); void ReloadCustomImage(Bitmap *, char *); +Bitmap *ZoomBitmap(Bitmap *, int, int); void ReCreateGameTileSizeBitmap(Bitmap **); void CreateBitmapWithSmallBitmaps(Bitmap **, int, int); void CreateBitmapTextures(Bitmap **); diff --git a/src/main.c b/src/main.c index dbc5ff1a..8dd3712b 100644 --- a/src/main.c +++ b/src/main.c @@ -7642,6 +7642,7 @@ static void print_usage(void) " \"patch tapes MODE LEVELDIR [NR]\" patch level tapes for LEVELDIR\n" " \"convert LEVELDIR [NR]\" convert levels in LEVELDIR\n" " \"create sketch images DIRECTORY\" write BMP images to DIRECTORY\n" + " \"create collect image DIRECTORY\" write BMP image to DIRECTORY\n" " \"create CE image DIRECTORY\" write BMP image to DIRECTORY\n" "\n", program.command_basename); diff --git a/src/main.h b/src/main.h index a513aaa2..2c2125f4 100644 --- a/src/main.h +++ b/src/main.h @@ -3280,6 +3280,7 @@ struct GlobalInfo int dumptape_level_nr; char *create_sketch_images_dir; + char *create_collect_images_dir; int num_toons;