re-added some removed (deactivated) code (to be evaluated again)
[rocksndiamonds.git] / src / libgame / setup.c
index 2eca885ac16b27fb5ced808c25871f15239dd250..4d1a8fd02c6d017b4f2d5f36838e8690d03ef551 100644 (file)
@@ -3860,88 +3860,80 @@ void LoadLevelArtworkInfo(void)
   print_timestamp_done("LoadLevelArtworkInfo");
 }
 
-static boolean AddUserLevelSetToLevelInfoExt(char *level_subdir_new)
+static boolean AddUserTreeSetToTreeInfoExt(char *tree_subdir_new, int type)
 {
-  // get level info tree node of first (original) user level set
-  char *level_subdir_old = getLoginName();
-  LevelDirTree *leveldir_old = getTreeInfoFromIdentifier(leveldir_first,
-                                                        level_subdir_old);
-  if (leveldir_old == NULL)            // should not happen
-    return FALSE;
-
-  int draw_deactivation_mask = GetDrawDeactivationMask();
-
-  // override draw deactivation mask (temporarily disable drawing)
-  SetDrawDeactivationMask(REDRAW_ALL);
-
-  // load new level set config and add it next to first user level set
-  LoadLevelInfoFromLevelConf(&leveldir_old->next, NULL,
-                            leveldir_old->basepath, level_subdir_new);
+  TreeInfo **tree_node_first, *tree_node_old, *tree_node_new;
+  char *tree_user_dir = TREE_USERDIR(type);
 
-  // set draw deactivation mask to previous value
-  SetDrawDeactivationMask(draw_deactivation_mask);
-
-  // get level info tree node of newly added user level set
-  LevelDirTree *leveldir_new = getTreeInfoFromIdentifier(leveldir_first,
-                                                        level_subdir_new);
-  if (leveldir_new == NULL)            // should not happen
+  if (tree_user_dir == NULL)           // should not happen
     return FALSE;
 
-  // correct top link and parent node link of newly created tree node
-  leveldir_new->node_top    = leveldir_old->node_top;
-  leveldir_new->node_parent = leveldir_old->node_parent;
+  // get first node of level or artwork tree
+  tree_node_first = TREE_FIRST_NODE_PTR(type);
 
-  // sort level info tree to adjust position of newly added level set
-  sortTreeInfo(&leveldir_first);
-
-  return TRUE;
-}
+  if (tree_node_first == NULL)         // should not happen
+    return FALSE;
 
-void AddUserLevelSetToLevelInfo(char *level_subdir_new)
-{
-  if (!AddUserLevelSetToLevelInfoExt(level_subdir_new))
-    Error(ERR_EXIT, "internal level set structure corrupted -- aborting");
-}
+  if (type == TREE_TYPE_LEVEL_DIR)
+  {
+    // get level info tree node of personal user level set
+    tree_node_old = getTreeInfoFromIdentifier(*tree_node_first, getLoginName());
+  }
+  else
+  {
+    // get artwork info tree node of first artwork set
+    tree_node_old = *tree_node_first;
+  }
 
-static boolean AddUserArtworkSetToArtworkInfoExt(char *artwork_subdir_new,
-                                                int type)
-{
-  // get artwork info tree node of first artwork set
-  TreeInfo *artwork_first_node = ARTWORK_FIRST_NODE(artwork, type);
-  char *artwork_user_dir = USER_ARTWORK_DIRECTORY(type);
+  if (tree_node_old == NULL)           // should not happen
+    return FALSE;
 
   int draw_deactivation_mask = GetDrawDeactivationMask();
 
   // override draw deactivation mask (temporarily disable drawing)
   SetDrawDeactivationMask(REDRAW_ALL);
 
-  // load new artwork set config and add it next to first artwork set
-  LoadArtworkInfoFromArtworkConf(&artwork_first_node->next, NULL,
-                                artwork_user_dir, artwork_subdir_new, type);
+  if (type == TREE_TYPE_LEVEL_DIR)
+  {
+    // load new level set config and add it next to first user level set
+    LoadLevelInfoFromLevelConf(&tree_node_old->next, NULL,
+                              tree_user_dir, tree_subdir_new);
+  }
+  else
+  {
+    // load new artwork set config and add it next to first artwork set
+    LoadArtworkInfoFromArtworkConf(&tree_node_old->next, NULL,
+                                  tree_user_dir, tree_subdir_new, type);
+  }
 
   // set draw deactivation mask to previous value
   SetDrawDeactivationMask(draw_deactivation_mask);
 
-  // get artwork info tree node of newly added artwork set
-  LevelDirTree *artwork_new = getTreeInfoFromIdentifier(artwork_first_node,
-                                                       artwork_subdir_new);
-  if (artwork_new == NULL)             // should not happen
+  // get tree info tree node of newly added tree set
+  tree_node_new = getTreeInfoFromIdentifier(*tree_node_first, tree_subdir_new);
+
+  if (tree_node_new == NULL)           // should not happen
     return FALSE;
 
   // correct top link and parent node link of newly created tree node
-  artwork_new->node_top    = artwork_first_node->node_top;
-  artwork_new->node_parent = artwork_first_node->node_parent;
+  tree_node_new->node_top    = tree_node_old->node_top;
+  tree_node_new->node_parent = tree_node_old->node_parent;
 
-  // sort artwork info tree to adjust position of newly added artwork set
-  sortTreeInfo(&artwork_first_node);
+  // sort tree info tree to adjust position of newly added tree set
+  sortTreeInfo(tree_node_first);
 
   return TRUE;
 }
 
-void AddUserArtworkSetToArtworkInfo(char *artwork_subdir_new, int type)
+void AddUserTreeSetToTreeInfo(char *tree_subdir_new, int type)
 {
-  if (!AddUserArtworkSetToArtworkInfoExt(artwork_subdir_new, type))
-    Error(ERR_EXIT, "internal artwork set structure corrupted -- aborting");
+  if (!AddUserTreeSetToTreeInfoExt(tree_subdir_new, type))
+    Error(ERR_EXIT, "internal tree set structure corrupted -- aborting");
+}
+
+void AddUserLevelSetToLevelInfo(char *level_subdir_new)
+{
+  AddUserTreeSetToTreeInfo(level_subdir_new, TREE_TYPE_LEVEL_DIR);
 }
 
 char *getArtworkIdentifierForUserLevelSet(int type)
@@ -4340,6 +4332,9 @@ static void checkSeriesInfo(void)
 {
   static char *level_directory = NULL;
   Directory *dir;
+#if 0
+  DirectoryEntry *dir_entry;
+#endif
 
   // check for more levels besides the 'levels' field of 'levelinfo.conf'
 
@@ -4355,6 +4350,35 @@ static void checkSeriesInfo(void)
     return;
   }
 
+#if 0
+  while ((dir_entry = readDirectory(dir)) != NULL)     // loop all entries
+  {
+    if (strlen(dir_entry->basename) > 4 &&
+       dir_entry->basename[3] == '.' &&
+       strEqual(&dir_entry->basename[4], LEVELFILE_EXTENSION))
+    {
+      char levelnum_str[4];
+      int levelnum_value;
+
+      strncpy(levelnum_str, dir_entry->basename, 3);
+      levelnum_str[3] = '\0';
+
+      levelnum_value = atoi(levelnum_str);
+
+      if (levelnum_value < leveldir_current->first_level)
+      {
+       Error(ERR_WARN, "additional level %d found", levelnum_value);
+       leveldir_current->first_level = levelnum_value;
+      }
+      else if (levelnum_value > leveldir_current->last_level)
+      {
+       Error(ERR_WARN, "additional level %d found", levelnum_value);
+       leveldir_current->last_level = levelnum_value;
+      }
+    }
+  }
+#endif
+
   closeDirectory(dir);
 }