added "levelinfo.conf" options to rename levels with title "nameless level"
authorHolger Schemel <info@artsoft.org>
Sat, 9 Apr 2022 18:04:36 +0000 (20:04 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 9 Apr 2022 18:05:25 +0000 (20:05 +0200)
src/files.c
src/libgame/setup.c
src/libgame/system.h

index 3564470c443802426c5ca3d943bffdfd5a328a22..3278b0c6313441f19ef4535e6e2bd0ddce34fe9c 100644 (file)
@@ -6566,6 +6566,13 @@ static void LoadLevel_InitSettings(struct LevelInfo *level)
 {
   // adjust level settings for (non-native) Sokoban-style levels
   LoadLevel_InitSettings_SB(level);
+
+  // rename levels with title "nameless level" or if renaming is forced
+  if (leveldir_current->empty_level_name != NULL &&
+      (strEqual(level->name, NAMELESS_LEVEL_NAME) ||
+       leveldir_current->force_level_name))
+    snprintf(level->name, MAX_LEVEL_NAME_LEN + 1,
+            leveldir_current->empty_level_name, level_nr);
 }
 
 static void LoadLevel_InitStandardElements(struct LevelInfo *level)
index 60bb56853b59b6016a0454730a43111b71316fca..3557e949273a30f1c3ffc5f3ddd7b456af62ac2b 100644 (file)
@@ -2636,11 +2636,13 @@ SetupFileHash *loadSetupFileHash(char *filename)
 #define LEVELINFO_TOKEN_FILENAME               24
 #define LEVELINFO_TOKEN_FILETYPE               25
 #define LEVELINFO_TOKEN_SPECIAL_FLAGS          26
-#define LEVELINFO_TOKEN_HANDICAP               27
-#define LEVELINFO_TOKEN_SKIP_LEVELS            28
-#define LEVELINFO_TOKEN_USE_EMC_TILES          29
+#define LEVELINFO_TOKEN_EMPTY_LEVEL_NAME       27
+#define LEVELINFO_TOKEN_FORCE_LEVEL_NAME       28
+#define LEVELINFO_TOKEN_HANDICAP               29
+#define LEVELINFO_TOKEN_SKIP_LEVELS            30
+#define LEVELINFO_TOKEN_USE_EMC_TILES          31
 
-#define NUM_LEVELINFO_TOKENS                   30
+#define NUM_LEVELINFO_TOKENS                   32
 
 static LevelDirTree ldi;
 
@@ -2674,6 +2676,8 @@ static struct TokenInfo levelinfo_tokens[] =
   { TYPE_STRING,       &ldi.level_filename,    "filename"              },
   { TYPE_STRING,       &ldi.level_filetype,    "filetype"              },
   { TYPE_STRING,       &ldi.special_flags,     "special_flags"         },
+  { TYPE_STRING,       &ldi.empty_level_name,  "empty_level_name"      },
+  { TYPE_BOOLEAN,      &ldi.force_level_name,  "force_level_name"      },
   { TYPE_BOOLEAN,      &ldi.handicap,          "handicap"              },
   { TYPE_BOOLEAN,      &ldi.skip_levels,       "skip_levels"           },
   { TYPE_BOOLEAN,      &ldi.use_emc_tiles,     "use_emc_tiles"         }
@@ -2771,6 +2775,9 @@ static void setTreeInfoToDefaults(TreeInfo *ti, int type)
 
     ti->special_flags = NULL;
 
+    ti->empty_level_name = NULL;
+    ti->force_level_name = FALSE;
+
     ti->levels = 0;
     ti->first_level = 0;
     ti->last_level = 0;
@@ -2853,6 +2860,9 @@ static void setTreeInfoToDefaultsFromParent(TreeInfo *ti, TreeInfo *parent)
 
     ti->special_flags = getStringCopy(parent->special_flags);
 
+    ti->empty_level_name = getStringCopy(parent->empty_level_name);
+    ti->force_level_name = parent->force_level_name;
+
     ti->levels = parent->levels;
     ti->first_level = parent->first_level;
     ti->last_level = parent->last_level;
@@ -2915,6 +2925,9 @@ static TreeInfo *getTreeInfoCopy(TreeInfo *ti)
 
   ti_copy->special_flags       = getStringCopy(ti->special_flags);
 
+  ti_copy->empty_level_name    = getStringCopy(ti->empty_level_name);
+  ti_copy->force_level_name    = ti->force_level_name;
+
   ti_copy->levels              = ti->levels;
   ti_copy->first_level         = ti->first_level;
   ti_copy->last_level          = ti->last_level;
index cf2bf1632f66a0289e1c4f1bef5c7724ea2a189b..15391399f06451c7b2a3b75bfeea1d0100b8c161 100644 (file)
@@ -1623,6 +1623,9 @@ struct TreeInfo
 
   char *special_flags; // flags for special actions performed on level file
 
+  char *empty_level_name;   // name pattern if level title is "nameless level"
+  boolean force_level_name; // force also renaming non-nameless level titles
+
   int levels;          // number of levels in level series
   int first_level;     // first level number (to allow start with 0 or 1)
   int last_level;      // last level number (automatically calculated)