added command line option to dump level set info
authorHolger Schemel <info@artsoft.org>
Tue, 30 Apr 2024 22:46:20 +0000 (00:46 +0200)
committerHolger Schemel <info@artsoft.org>
Tue, 30 Apr 2024 22:46:26 +0000 (00:46 +0200)
src/files.c
src/files.h
src/game_bd/export_bd.h
src/game_bd/main_bd.c
src/init.c
src/main.c
src/main.h

index 278938ab66865429c951624723dd8a9988613e32..c3f5cf7477eb9bff10eadd1cb693fbd543816b62 100644 (file)
@@ -9041,6 +9041,46 @@ void DumpLevels(void)
   CloseAllAndExit(0);
 }
 
+void DumpLevelsetFromFilename_BD(char *filename)
+{
+  if (leveldir_current == NULL)        // no levelsets loaded yet
+    bd_open_all();
+
+  if (!LoadNativeLevel_BD(filename, 0, FALSE))
+    CloseAllAndExit(0);                // function has already printed warning
+
+  PrintLine("-", 79);
+  Print("Levelset '%s'\n", filename);
+  PrintLine("-", 79);
+
+  DumpLevelset_BD();
+
+  PrintLine("-", 79);
+
+  CloseAllAndExit(0);
+}
+
+void DumpLevelset(void)
+{
+  static LevelDirTree *dumplevelset_leveldir = NULL;
+
+  dumplevelset_leveldir = getTreeInfoFromIdentifier(leveldir_first,
+                                                    global.dumplevelset_leveldir);
+  if (dumplevelset_leveldir == NULL)
+    Fail("no such level identifier: '%s'", global.dumplevelset_leveldir);
+
+  PrintLine("-", 79);
+  Print("Levelset '%s'\n", dumplevelset_leveldir->identifier);
+  PrintLine("-", 79);
+
+  Print("Number of levels:   %d\n", dumplevelset_leveldir->levels);
+  Print("First level number: %d\n", dumplevelset_leveldir->first_level);
+
+  PrintLine("-", 79);
+
+  CloseAllAndExit(0);
+}
+
 
 // ============================================================================
 // tape file functions
index aab1da88a7509763d5db02188150263ad487caae..c122716b60fb8dc672db78903bad35f43f8961a0 100644 (file)
@@ -46,6 +46,8 @@ void SaveLevelTemplate(void);
 void SaveNativeLevel(struct LevelInfo *);
 void DumpLevel(struct LevelInfo *);
 void DumpLevels(void);
+void DumpLevelsetFromFilename_BD(char *);
+void DumpLevelset(void);
 boolean SaveLevelChecked(int);
 
 void CopyNativeLevel_RND_to_Native(struct LevelInfo *);
index 60e70c2046316f57531c87d916e773697e0cf47d..a060e2e4be7f5f07990d10aa2560747968cf74ba 100644 (file)
@@ -103,6 +103,7 @@ void setLevelInfoToDefaults_BD_Ext(int, int);
 void setLevelInfoToDefaults_BD(void);
 boolean LoadNativeLevel_BD(char *, int, boolean);
 boolean SaveNativeLevel_BD(char *);
+void DumpLevelset_BD(void);
 
 void PreparePreviewTileBitmap_BD(Bitmap *, int);
 void SetPreviewTileBitmapReference_BD(Bitmap *);
index a3078e9987f9ab5e1110da1868e24fcdcf6ac0eb..25eb06310409d4a7146e442677c798a2a0887445 100644 (file)
@@ -181,6 +181,12 @@ boolean SaveNativeLevel_BD(char *filename)
   return gd_caveset_save_to_file(filename);
 }
 
+void DumpLevelset_BD(void)
+{
+  Print("Number of levels:   %d\n", 5 * gd_caveset_count());
+  Print("First level number: %d\n", 1);
+}
+
 
 // ============================================================================
 // game engine functions
index 2529a8baba97aa4f9b16bab81a2a764ae82ff1d9..807a9a14e5d238bc94504f08e80c5b1956a937ae 100644 (file)
@@ -5196,6 +5196,7 @@ static void InitGlobal(void)
   global.autoplay_leveldir = NULL;
   global.patchtapes_leveldir = NULL;
   global.convert_leveldir = NULL;
+  global.dumplevelset_leveldir = NULL;
   global.dumplevel_leveldir = NULL;
   global.dumptape_leveldir = NULL;
   global.create_sketch_images_dir = NULL;
@@ -5307,6 +5308,23 @@ static void Execute_Command(char *command)
 
     exit(0);
   }
+  else if (strPrefix(command, "dump levelset "))
+  {
+    char *filename = &command[14];
+
+    if (fileExists(filename) && isLevelsetFilename_BD(filename))
+    {
+      DumpLevelsetFromFilename_BD(filename);
+
+      exit(0);
+    }
+
+    char *leveldir = getStringCopy(filename);  // read command parameters
+
+    global.dumplevelset_leveldir = leveldir;
+
+    program.headless = TRUE;
+  }
   else if (strPrefix(command, "dump level "))
   {
     char *filename = &command[11];
@@ -6691,6 +6709,11 @@ void OpenAll(void)
     ConvertLevels();
     return;
   }
+  else if (global.dumplevelset_leveldir)
+  {
+    DumpLevelset();
+    return;
+  }
   else if (global.dumplevel_leveldir)
   {
     DumpLevels();
index a0b872613a9fab0268355a92e2398bedbe51e0e8..8ab7313dba3a77667264417e627d886e78cd1035 100644 (file)
@@ -9078,6 +9078,7 @@ static void print_usage(void)
        "  \"print editorsetup.conf\"         print default editor config\n"
        "  \"print helpanim.conf\"            print default helpanim config\n"
        "  \"print helptext.conf\"            print default helptext config\n"
+       "  \"dump levelset FILE|LEVELDIR\"    dump levelset info for LEVELDIR\n"
        "  \"dump level FILE\"                dump level data from FILE\n"
        "  \"dump tape FILE\"                 dump tape data from FILE\n"
        "  \"autoplay LEVELDIR [NR ...]\"     play level tapes for LEVELDIR\n"
index 1f679aa03b9387d288ea5b4c0d4f6c53768c63de..9d02a4fb1e0ae849d6c119ebdfe0cc46b2f291c9 100644 (file)
@@ -3884,6 +3884,8 @@ struct GlobalInfo
   char *convert_leveldir;
   int convert_level_nr;
 
+  char *dumplevelset_leveldir;
+
   char *dumplevel_leveldir;
   int dumplevel_level_nr;