From: Holger Schemel Date: Mon, 26 Jan 2015 23:57:45 +0000 (+0100) Subject: added looking for editor element descriptions in level set directory X-Git-Tag: 4.0.0.0-rc1~304 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=1c820b0c374f7b56f01d2c2353cc32f4970640d9;p=rocksndiamonds.git added looking for editor element descriptions in level set directory --- diff --git a/ChangeLog b/ChangeLog index fd54470d..adc9c2bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-01-27 + * added looking for editor element descriptions in level set directory + (for example, in file "/docs/elements/custom_1.txt") + 2015-01-25 * moved "element properties" button in editor from toolbox to palette * added "zoom level tile size" button in editor to toolbox (currently diff --git a/src/editor.c b/src/editor.c index 5b1b7560..a9d575a5 100644 --- a/src/editor.c +++ b/src/editor.c @@ -4787,27 +4787,47 @@ static char *getElementInfoText(int element) return info_text; } -char *getElementDescriptionFilename(int element) +static char *getElementDescriptionFilenameExt(char *basename) { - char *docs_dir = options.docs_directory; char *elements_subdir = "elements"; + static char *elements_subdir2 = NULL; static char *filename = NULL; - char basename[MAX_FILENAME_LEN]; + + if (elements_subdir2 == NULL) + elements_subdir2 = getPath2(DOCS_DIRECTORY, elements_subdir); checked_free(filename); - /* 1st try: look for element description file for exactly this element */ - sprintf(basename, "%s.txt", element_info[element].token_name); - filename = getPath3(docs_dir, elements_subdir, basename); + /* 1st try: look for element description in current level set directory */ + filename = getPath3(getCurrentLevelDir(), elements_subdir2, basename); if (fileExists(filename)) return filename; free(filename); + /* 2nd try: look for element description in the game's base directory */ + filename = getPath3(options.docs_directory, elements_subdir, basename); + if (fileExists(filename)) + return filename; + + return NULL; +} + +char *getElementDescriptionFilename(int element) +{ + char basename[MAX_FILENAME_LEN]; + char *filename; + + /* 1st try: look for element description file for exactly this element */ + sprintf(basename, "%s.txt", element_info[element].token_name); + filename = getElementDescriptionFilenameExt(basename); + if (filename != NULL) + return filename; + /* 2nd try: look for element description file for this element's class */ sprintf(basename, "%s.txt", element_info[element].class_name); - filename = getPath3(docs_dir, elements_subdir, basename); - if (fileExists(filename)) + filename = getElementDescriptionFilenameExt(basename); + if (filename != NULL) return filename; return NULL;