return NULL;
if (node->node_parent == NULL) /* top level group */
- return leveldir_first;
+ return *node->node_top;
else /* sub level group */
return node->node_parent->node_group;
}
return NULL;
}
-TreeInfo *getTreeInfoFromFilename(char *filename)
+TreeInfo *getTreeInfoFromFilename(TreeInfo *ti, char *filename)
{
- return getTreeInfoFromFilenameExt(leveldir_first, filename);
+ return getTreeInfoFromFilenameExt(ti, filename);
}
void dumpTreeInfo(TreeInfo *node, int depth)
{
int i;
+ printf("Dumping TreeInfo:\n");
+
while (node)
{
- for (i=0; i<depth * 3; i++)
+ for (i=0; i<(depth + 1) * 3; i++)
printf(" ");
printf("filename == '%s' [%s]\n", node->filename, node->name);
{ TYPE_BOOLEAN, &ldi.readonly, "readonly" }
};
-static void setTreeInfoToDefaults(TreeInfo *ldi)
+static void setTreeInfoToDefaults(TreeInfo *ldi, int type)
{
+ ldi->type = type;
+
+ ldi->node_top = (ldi->type == TREE_TYPE_LEVEL_DIR ? &leveldir_first :
+ ldi->type == TREE_TYPE_GRAPHICS_DIR ? &artwork.gfx_first :
+ ldi->type == TREE_TYPE_SOUNDS_DIR ? &artwork.snd_first :
+ ldi->type == TREE_TYPE_MUSIC_DIR ? &artwork.mus_first :
+ NULL);
+
ldi->node_parent = NULL;
ldi->node_group = NULL;
ldi->next = NULL;
ldi->cl_first = -1;
ldi->cl_cursor = -1;
- ldi->type = TREE_TYPE_GENERIC;
-
ldi->filename = NULL;
ldi->fullpath = NULL;
ldi->basepath = NULL;
ldi->name_short = NULL;
ldi->name_sorting = NULL;
ldi->author = getStringCopy(ANONYMOUS_NAME);
- ldi->imported_from = NULL;
- ldi->levels = 0;
- ldi->first_level = 0;
- ldi->last_level = 0;
+
ldi->sort_priority = LEVELCLASS_UNDEFINED; /* default: least priority */
- ldi->level_group = FALSE;
ldi->parent_link = FALSE;
ldi->user_defined = FALSE;
- ldi->readonly = TRUE;
ldi->color = 0;
ldi->class_desc = NULL;
- ldi->handicap_level = 0;
+
+ if (ldi->type == TREE_TYPE_LEVEL_DIR)
+ {
+ ldi->imported_from = NULL;
+ ldi->levels = 0;
+ ldi->first_level = 0;
+ ldi->last_level = 0;
+ ldi->level_group = FALSE;
+ ldi->handicap_level = 0;
+ ldi->readonly = TRUE;
+ }
}
-static void setTreeInfoToDefaultsFromParent(TreeInfo *ldi,
- TreeInfo *parent)
+static void setTreeInfoToDefaultsFromParent(TreeInfo *ldi, TreeInfo *parent)
{
if (parent == NULL)
{
- setTreeInfoToDefaults(ldi);
+ Error(ERR_WARN, "setTreeInfoToDefaultsFromParent(): parent == NULL");
+
+ setTreeInfoToDefaults(ldi, TREE_TYPE_GENERIC);
return;
}
ldi->level_group = FALSE;
ldi->parent_link = FALSE;
+ ldi->node_top = parent->node_top;
ldi->node_parent = parent;
ldi->node_group = NULL;
ldi->next = NULL;
static void createParentTreeInfoNode(TreeInfo *node_parent)
{
- TreeInfo *leveldir_new = newTreeInfo();
+ TreeInfo *ti_new;
- setTreeInfoToDefaults(leveldir_new);
+ if (node_parent == NULL)
+ return;
- leveldir_new->node_parent = node_parent;
- leveldir_new->parent_link = TRUE;
+ ti_new = newTreeInfo();
+ setTreeInfoToDefaults(ti_new, node_parent->type);
- leveldir_new->name = ".. (parent directory)";
- leveldir_new->name_short = getStringCopy(leveldir_new->name);
- leveldir_new->name_sorting = getStringCopy(leveldir_new->name);
+ ti_new->node_parent = node_parent;
+ ti_new->parent_link = TRUE;
- leveldir_new->filename = "..";
- leveldir_new->fullpath = getStringCopy(node_parent->fullpath);
+ ti_new->name = ".. (parent directory)";
+ ti_new->name_short = getStringCopy(ti_new->name);
+ ti_new->name_sorting = getStringCopy(ti_new->name);
- leveldir_new->sort_priority = node_parent->sort_priority;
- leveldir_new->class_desc = getLevelClassDescription(leveldir_new);
+ ti_new->filename = "..";
+ ti_new->fullpath = getStringCopy(node_parent->fullpath);
+
+ ti_new->sort_priority = node_parent->sort_priority;
+ ti_new->class_desc = getLevelClassDescription(ti_new);
- pushTreeInfo(&node_parent->node_group, leveldir_new);
+ pushTreeInfo(&node_parent->node_group, ti_new);
}
/* forward declaration for recursive call by "LoadLevelInfoFromLevelDir()" */
leveldir_new = newTreeInfo();
+ if (node_parent)
+ setTreeInfoToDefaultsFromParent(leveldir_new, node_parent);
+ else
+ setTreeInfoToDefaults(leveldir_new, TREE_TYPE_LEVEL_DIR);
+
checkSetupFileListIdentifier(setup_file_list, getCookie("LEVELINFO"));
- setTreeInfoToDefaultsFromParent(leveldir_new, node_parent);
/* set all structure fields according to the token/value pairs */
ldi = *leveldir_new;
#endif
}
-/* declaration for recursive call by "LoadArtworkInfoFromArtworkConf()" */
-static void LoadArtworkInfoFromArtworkDir(TreeInfo **, TreeInfo *, char *,int);
-
static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first,
TreeInfo *node_parent,
char *base_directory,
}
artwork_new = newTreeInfo();
- setTreeInfoToDefaultsFromParent(artwork_new, node_parent);
+
+ if (node_parent)
+ setTreeInfoToDefaultsFromParent(artwork_new, node_parent);
+ else
+ setTreeInfoToDefaults(artwork_new, type);
artwork_new->filename = getStringCopy(directory_name);
- if (setup_file_list)
+ if (setup_file_list) /* (before defining ".color" and ".class_desc") */
{
#if 0
checkSetupFileListIdentifier(setup_file_list, getCookie("..."));
if (artwork_new->name_sorting == NULL)
artwork_new->name_sorting = getStringCopy(artwork_new->name);
}
- else
- {
- if (artwork_new->name != NULL)
- free(artwork_new->name);
-
- if (strcmp(artwork_new->filename, ".") == 0)
- artwork_new->name = getStringCopy("default");
- else
- artwork_new->name = getStringCopy(artwork_new->filename);
-
- artwork_new->name_short = getStringCopy(artwork_new->name);
- artwork_new->name_sorting = getStringCopy(artwork_new->name);
- }
if (node_parent == NULL) /* top level group */
{
artwork_new->user_defined =
(artwork_new->basepath == check_dir ? FALSE : TRUE);
-#if 0
+ /* (may use ".sort_priority" from "setup_file_list" above) */
artwork_new->color = LEVELCOLOR(artwork_new);
artwork_new->class_desc = getLevelClassDescription(artwork_new);
-#endif
+
+ if (setup_file_list == NULL) /* (after determining ".user_defined") */
+ {
+ if (artwork_new->name != NULL)
+ free(artwork_new->name);
+
+ if (strcmp(artwork_new->filename, ".") == 0)
+ {
+ if (artwork_new->user_defined)
+ artwork_new->name = getStringCopy("private");
+ else
+ artwork_new->name = getStringCopy("default");
+ }
+ else
+ artwork_new->name = getStringCopy(artwork_new->filename);
+
+ artwork_new->name_short = getStringCopy(artwork_new->name);
+ artwork_new->name_sorting = getStringCopy(artwork_new->name);
+ }
pushTreeInfo(node_first, artwork_new);
free(directory_path);
+ /* check if this directory contains artwork with or without config file */
valid_entry_found |= LoadArtworkInfoFromArtworkConf(node_first,node_parent,
base_directory,
directory_name, type);
closedir(dir);
- if (!valid_entry_found)
- {
- /* check if this directory directly contains an artwork config file */
- valid_entry_found |= LoadArtworkInfoFromArtworkConf(node_first,node_parent,
- base_directory, ".",
- type);
- }
-
+ /* check if this directory directly contains artwork itself */
+ valid_entry_found |= LoadArtworkInfoFromArtworkConf(node_first,node_parent,
+ base_directory, ".",
+ type);
if (!valid_entry_found)
Error(ERR_WARN, "cannot find any valid artwork in directory '%s'",
base_directory);
getUserMusicDir(NULL),
TREE_TYPE_MUSIC_DIR);
+ /* before sorting, the first entries will be from the user directory */
artwork.gfx_current = artwork.gfx_first;
artwork.snd_current = artwork.snd_first;
artwork.mus_current = artwork.mus_first;
sortTreeInfo(&artwork.snd_first, compareTreeInfoEntries);
sortTreeInfo(&artwork.mus_first, compareTreeInfoEntries);
-#if 0
+#if 1
dumpTreeInfo(artwork.gfx_first, 0);
dumpTreeInfo(artwork.snd_first, 0);
dumpTreeInfo(artwork.mus_first, 0);
}
/* always start with reliable default values */
- setTreeInfoToDefaults(&ldi);
+ setTreeInfoToDefaults(&ldi, TREE_TYPE_LEVEL_DIR);
ldi.name = getLoginName();
ldi.author = getRealName();
char *last_level_series =
getTokenValue(level_setup_list, TOKEN_STR_LAST_LEVEL_SERIES);
- leveldir_current = getTreeInfoFromFilename(last_level_series);
+ leveldir_current = getTreeInfoFromFilename(leveldir_first,
+ last_level_series);
if (leveldir_current == NULL)
leveldir_current = leveldir_first;