From: Holger Schemel Date: Tue, 11 May 2021 17:43:49 +0000 (+0200) Subject: added dumping levels and tapes by level set and number X-Git-Tag: 4.3.0.0~156 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=734eaa90125329a1ce5865b443ce9a31264f9218;p=rocksndiamonds.git added dumping levels and tapes by level set and number --- diff --git a/src/files.c b/src/files.c index d67bb48e..8f04a366 100644 --- a/src/files.c +++ b/src/files.c @@ -7661,6 +7661,28 @@ void DumpLevel(struct LevelInfo *level) PrintLine("-", 79); } +void DumpLevels(void) +{ + static LevelDirTree *dumplevel_leveldir = NULL; + + dumplevel_leveldir = getTreeInfoFromIdentifier(leveldir_first, + global.dumplevel_leveldir); + + if (dumplevel_leveldir == NULL) + Fail("no such level identifier: '%s'", global.dumplevel_leveldir); + + if (global.dumplevel_level_nr < dumplevel_leveldir->first_level || + global.dumplevel_level_nr > dumplevel_leveldir->last_level) + Fail("no such level number: %d", global.dumplevel_level_nr); + + leveldir_current = dumplevel_leveldir; + + LoadLevel(global.dumplevel_level_nr); + DumpLevel(&level); + + CloseAllAndExit(0); +} + // ============================================================================ // tape file functions @@ -8420,6 +8442,32 @@ void DumpTape(struct TapeInfo *tape) PrintLine("-", 79); } +void DumpTapes(void) +{ + static LevelDirTree *dumptape_leveldir = NULL; + + dumptape_leveldir = getTreeInfoFromIdentifier(leveldir_first, + global.dumptape_leveldir); + + if (dumptape_leveldir == NULL) + Fail("no such level identifier: '%s'", global.dumptape_leveldir); + + if (global.dumptape_level_nr < dumptape_leveldir->first_level || + global.dumptape_level_nr > dumptape_leveldir->last_level) + Fail("no such level number: %d", global.dumptape_level_nr); + + leveldir_current = dumptape_leveldir; + + if (options.mytapes) + LoadTape(global.dumptape_level_nr); + else + LoadSolutionTape(global.dumptape_level_nr); + + DumpTape(&tape); + + CloseAllAndExit(0); +} + // ============================================================================ // score file functions diff --git a/src/files.h b/src/files.h index 157fcd44..194e1c22 100644 --- a/src/files.h +++ b/src/files.h @@ -44,6 +44,7 @@ void SaveLevel(int); void SaveLevelTemplate(void); void SaveNativeLevel(struct LevelInfo *); void DumpLevel(struct LevelInfo *); +void DumpLevels(void); boolean SaveLevelChecked(int); void CopyNativeLevel_RND_to_Native(struct LevelInfo *); @@ -56,6 +57,7 @@ void SaveTapeToFilename(char *); void SaveTape(int); void SaveScoreTape(int); void DumpTape(struct TapeInfo *); +void DumpTapes(void); boolean SaveTapeChecked(int); boolean SaveTapeChecked_LevelSolved(int); diff --git a/src/init.c b/src/init.c index 210594fc..fbd103da 100644 --- a/src/init.c +++ b/src/init.c @@ -4903,6 +4903,8 @@ static void InitGlobal(void) global.autoplay_leveldir = NULL; global.patchtapes_leveldir = NULL; global.convert_leveldir = NULL; + global.dumplevel_leveldir = NULL; + global.dumptape_leveldir = NULL; global.create_images_dir = NULL; global.frames_per_second = 0; @@ -5015,25 +5017,51 @@ static void Execute_Command(char *command) { char *filename = &command[11]; - if (!fileExists(filename)) + if (fileExists(filename)) + { + LoadLevelFromFilename(&level, filename); + DumpLevel(&level); + + exit(0); + } + + char *leveldir = getStringCopy(filename); // read command parameters + char *level_nr = strchr(leveldir, ' '); + + if (level_nr == NULL) Fail("cannot open file '%s'", filename); - LoadLevelFromFilename(&level, filename); - DumpLevel(&level); + *level_nr++ = '\0'; - exit(0); + global.dumplevel_leveldir = leveldir; + global.dumplevel_level_nr = atoi(level_nr); + + program.headless = TRUE; } else if (strPrefix(command, "dump tape ")) { char *filename = &command[10]; - if (!fileExists(filename)) + if (fileExists(filename)) + { + LoadTapeFromFilename(filename); + DumpTape(&tape); + + exit(0); + } + + char *leveldir = getStringCopy(filename); // read command parameters + char *level_nr = strchr(leveldir, ' '); + + if (level_nr == NULL) Fail("cannot open file '%s'", filename); - LoadTapeFromFilename(filename); - DumpTape(&tape); + *level_nr++ = '\0'; - exit(0); + global.dumptape_leveldir = leveldir; + global.dumptape_level_nr = atoi(level_nr); + + program.headless = TRUE; } else if (strPrefix(command, "autoplay ") || strPrefix(command, "autoffwd ") || @@ -6258,6 +6286,16 @@ void OpenAll(void) ConvertLevels(); return; } + else if (global.dumplevel_leveldir) + { + DumpLevels(); + return; + } + else if (global.dumptape_leveldir) + { + DumpTapes(); + return; + } else if (global.create_images_dir) { CreateLevelSketchImages(); diff --git a/src/main.h b/src/main.h index 1b9e7cb6..e9844b22 100644 --- a/src/main.h +++ b/src/main.h @@ -3272,6 +3272,12 @@ struct GlobalInfo char *convert_leveldir; int convert_level_nr; + char *dumplevel_leveldir; + int dumplevel_level_nr; + + char *dumptape_leveldir; + int dumptape_level_nr; + char *create_images_dir; int num_toons;