X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=b6ec4fda6353c2494c1c15f0eeca311ea6733887;hb=5a5342a6ab48037839b783adc4f3304331834a8c;hp=d68316d873777ba91f6c17e8e593d60b81606dc0;hpb=0548cd8fd0353c19608df8a7079fc2c39cc4ce27;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index d68316d8..b6ec4fda 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1512,12 +1512,78 @@ boolean FileIsArtworkType(char *basename, int type) /* functions for loading artwork configuration information */ /* ------------------------------------------------------------------------- */ -int get_parameter_value(int type, char *value) +/* This function checks if a string of the format "string1, string2, ..." + exactly contains a string . */ + +static boolean string_has_parameter(char *s, char *s_contained) { - return (strcmp(value, ARG_UNDEFINED) == 0 ? ARG_UNDEFINED_VALUE : - type == TYPE_INTEGER ? get_integer_from_string(value) : - type == TYPE_BOOLEAN ? get_boolean_from_string(value) : - ARG_UNDEFINED_VALUE); + char *substring; + + if (s == NULL || s_contained == NULL) + return FALSE; + + if (strlen(s_contained) > strlen(s)) + return FALSE; + + if (strncmp(s, s_contained, strlen(s_contained)) == 0) + { + char next_char = s[strlen(s_contained)]; + + /* check if next character is delimiter or whitespace */ + return (next_char == ',' || next_char == '\0' || + next_char == ' ' || next_char == '\t' ? TRUE : FALSE); + } + + /* check if string contains another parameter string after a comma */ + substring = strchr(s, ','); + if (substring == NULL) /* string does not contain a comma */ + return FALSE; + + /* advance string pointer to next character after the comma */ + substring++; + + /* skip potential whitespaces after the comma */ + while (*substring == ' ' || *substring == '\t') + substring++; + + return string_has_parameter(substring, s_contained); +} + +int get_parameter_value(char *token, char *value_raw, int type) +{ + char *value = getStringToLower(value_raw); + int result = 0; /* probably a save default value */ + + if (strcmp(token, ".direction") == 0) + { + result = (strcmp(value, "left") == 0 ? MV_LEFT : + strcmp(value, "right") == 0 ? MV_RIGHT : + strcmp(value, "up") == 0 ? MV_UP : + strcmp(value, "down") == 0 ? MV_DOWN : MV_NO_MOVING); + } + else if (strcmp(token, ".anim_mode") == 0) + { + result = (string_has_parameter(value, "loop") ? ANIM_LOOP : + string_has_parameter(value, "linear") ? ANIM_LINEAR : + string_has_parameter(value, "pingpong") ? ANIM_PINGPONG : + string_has_parameter(value, "pingpong2") ? ANIM_PINGPONG2 : + string_has_parameter(value, "random") ? ANIM_RANDOM : + ANIM_LOOP); + + if (string_has_parameter(value, "reverse")) + result |= ANIM_REVERSE; + } + else /* generic parameter of type integer or boolean */ + { + result = (strcmp(value, ARG_UNDEFINED) == 0 ? ARG_UNDEFINED_VALUE : + type == TYPE_INTEGER ? get_integer_from_string(value) : + type == TYPE_BOOLEAN ? get_boolean_from_string(value) : + ARG_UNDEFINED_VALUE); + } + + free(value); + + return result; } static void FreeCustomArtworkList(struct ArtworkListInfo *,