X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Ffiles.c;h=9f20487fb0e4f5aebb8bd2108b2f7e19040db114;hp=4ac4563fee7dfd0fb9c3ab6494da719c95f56cca;hb=897c46a2720672a49ce6d0803b08eed23fd2dd90;hpb=34dc736661e297f75d604335a7d85ea34d14c55d diff --git a/src/files.c b/src/files.c index 4ac4563f..9f20487f 100644 --- a/src/files.c +++ b/src/files.c @@ -9941,6 +9941,90 @@ static int getElementFromToken(char *token) return EL_UNDEFINED; } +void FreeGlobalAnimEventInfo(void) +{ + struct GlobalAnimEventInfo *gaei = &global_anim_event_info; + + if (gaei->event_list == NULL) + return; + + int i; + + for (i = 0; i < gaei->num_event_lists; i++) + { + checked_free(gaei->event_list[i]->event_value); + checked_free(gaei->event_list[i]); + } + + checked_free(gaei->event_list); + + gaei->event_list = NULL; + gaei->num_event_lists = 0; +} + +static int AddGlobalAnimEventList(void) +{ + struct GlobalAnimEventInfo *gaei = &global_anim_event_info; + int list_pos = gaei->num_event_lists++; + + gaei->event_list = checked_realloc(gaei->event_list, gaei->num_event_lists * + sizeof(struct GlobalAnimEventListInfo *)); + + gaei->event_list[list_pos] = + checked_calloc(sizeof(struct GlobalAnimEventListInfo)); + + struct GlobalAnimEventListInfo *gaeli = gaei->event_list[list_pos]; + + gaeli->event_value = NULL; + gaeli->num_event_values = 0; + + return list_pos; +} + +static int AddGlobalAnimEventValue(int list_pos, int event_value) +{ + // do not add empty global animation events + if (event_value == ANIM_EVENT_NONE) + return list_pos; + + // if list position is undefined, create new list + if (list_pos == ANIM_EVENT_UNDEFINED) + list_pos = AddGlobalAnimEventList(); + + struct GlobalAnimEventInfo *gaei = &global_anim_event_info; + struct GlobalAnimEventListInfo *gaeli = gaei->event_list[list_pos]; + int value_pos = gaeli->num_event_values++; + + gaeli->event_value = checked_realloc(gaeli->event_value, + gaeli->num_event_values * sizeof(int *)); + + gaeli->event_value[value_pos] = event_value; + + return list_pos; +} + +int GetGlobalAnimEventValue(int list_pos, int value_pos) +{ + if (list_pos == ANIM_EVENT_UNDEFINED) + return ANIM_EVENT_NONE; + + struct GlobalAnimEventInfo *gaei = &global_anim_event_info; + struct GlobalAnimEventListInfo *gaeli = gaei->event_list[list_pos]; + + return gaeli->event_value[value_pos]; +} + +int GetGlobalAnimEventValueCount(int list_pos) +{ + if (list_pos == ANIM_EVENT_UNDEFINED) + return 0; + + struct GlobalAnimEventInfo *gaei = &global_anim_event_info; + struct GlobalAnimEventListInfo *gaeli = gaei->event_list[list_pos]; + + return gaeli->num_event_values; +} + // This function checks if a string of the format "string1, string2, ..." // exactly contains a string . @@ -9980,17 +10064,35 @@ static boolean string_has_parameter(char *s, char *s_contained) static int get_anim_parameter_value(char *s) { - char *pattern_1 = "click:anim_"; + int event_value[] = + { + ANIM_EVENT_CLICK + }; + char *pattern_1[] = + { + "click:anim_" + }; char *pattern_2 = ".part_"; char *matching_char = NULL; char *s_ptr = s; + int pattern_1_len = 0; int result = ANIM_EVENT_NONE; + int i; + + for (i = 0; i < ARRAY_SIZE(event_value); i++) + { + matching_char = strstr(s_ptr, pattern_1[i]); + pattern_1_len = strlen(pattern_1[i]); + result = event_value[i]; + + if (matching_char != NULL) + break; + } - matching_char = strstr(s_ptr, pattern_1); if (matching_char == NULL) return ANIM_EVENT_NONE; - s_ptr = matching_char + strlen(pattern_1); + s_ptr = matching_char + pattern_1_len; // check for main animation number ("anim_X" or "anim_XX") if (*s_ptr >= '0' && *s_ptr <= '9') @@ -10045,6 +10147,39 @@ static int get_anim_parameter_value(char *s) return result; } +static int get_anim_parameter_values(char *s) +{ + int list_pos = ANIM_EVENT_UNDEFINED; + int event_value = ANIM_EVENT_DEFAULT; + + if (string_has_parameter(s, "any")) + event_value |= ANIM_EVENT_ANY; + + if (string_has_parameter(s, "click:self") || + string_has_parameter(s, "click") || + string_has_parameter(s, "self")) + event_value |= ANIM_EVENT_SELF; + + // if animation event found, add it to global animation event list + if (event_value != ANIM_EVENT_NONE) + list_pos = AddGlobalAnimEventValue(list_pos, event_value); + + while (s != NULL) + { + // add optional "click:anim_X" or "click:anim_X.part_X" parameter + event_value = get_anim_parameter_value(s); + + // if animation event found, add it to global animation event list + if (event_value != ANIM_EVENT_NONE) + list_pos = AddGlobalAnimEventValue(list_pos, event_value); + + // continue with next part of the string, starting with next comma + s = strchr(s + 1, ','); + } + + return list_pos; +} + static int get_anim_action_parameter_value(char *token) { int result = getImageIDFromToken(token); @@ -10142,16 +10277,7 @@ int get_parameter_value(char *value_raw, char *suffix, int type) else if (strEqual(suffix, ".init_event") || strEqual(suffix, ".anim_event")) { - result = ANIM_EVENT_DEFAULT; - - if (string_has_parameter(value, "any")) - result |= ANIM_EVENT_ANY; - - if (string_has_parameter(value, "click")) - result |= ANIM_EVENT_SELF; - - // add optional "click:anim_X" or "click:anim_X.part_X" parameter - result |= get_anim_parameter_value(value); + result = get_anim_parameter_values(value); } else if (strEqual(suffix, ".init_event_action") || strEqual(suffix, ".anim_event_action"))