added option to not trigger further animations if CE change event consumed
[rocksndiamonds.git] / src / files.c
index 42208ce6ec4b99dd9e9499d8cbb64a9923ca29e0..d9addaf1fc074a8ef0f8bde81ead0dfd780f579d 100644 (file)
@@ -11527,8 +11527,9 @@ static boolean string_has_parameter(char *s, char *s_contained)
     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);
+    if (next_char == ',' || next_char == '\0' ||
+       next_char == ' ' || next_char == '\t')
+      return TRUE;
   }
 
   // check if string contains another parameter string after a comma
@@ -11549,9 +11550,10 @@ static boolean string_has_parameter(char *s, char *s_contained)
 static int get_anim_parameter_value_ce(char *s)
 {
   char *s_ptr = s;
-  char *pattern = "ce_change:custom_";
-  int pattern_len = strlen(pattern);
-  char *matching_char = strstr(s_ptr, pattern);
+  char *pattern_1 = "ce_change:custom_";
+  char *pattern_2 = ".page_";
+  int pattern_1_len = strlen(pattern_1);
+  char *matching_char = strstr(s_ptr, pattern_1);
   int result = ANIM_EVENT_NONE;
 
   if (matching_char == NULL)
@@ -11559,9 +11561,9 @@ static int get_anim_parameter_value_ce(char *s)
 
   result = ANIM_EVENT_CE_CHANGE;
 
-  s_ptr = matching_char + pattern_len;
+  s_ptr = matching_char + pattern_1_len;
 
-  // check for custom element number ("custom_X" or "custom_XX" or "custom_XXX")
+  // check for custom element number ("custom_X", "custom_XX" or "custom_XXX")
   if (*s_ptr >= '0' && *s_ptr <= '9')
   {
     int gic_ce_nr = (*s_ptr++ - '0');
@@ -11577,7 +11579,7 @@ static int get_anim_parameter_value_ce(char *s)
     if (gic_ce_nr < 1 || gic_ce_nr > NUM_CUSTOM_ELEMENTS)
       return ANIM_EVENT_NONE;
 
-    // store internal CE number (0 to 255, not "custom_1" to "custom_256")
+    // custom element stored as 0 to 255
     gic_ce_nr--;
 
     result |= gic_ce_nr << ANIM_EVENT_CE_BIT;
@@ -11589,6 +11591,33 @@ static int get_anim_parameter_value_ce(char *s)
     return ANIM_EVENT_NONE;
   }
 
+  // check for change page number ("page_X" or "page_XX") (optional)
+  if (strPrefix(s_ptr, pattern_2))
+  {
+    s_ptr += strlen(pattern_2);
+
+    if (*s_ptr >= '0' && *s_ptr <= '9')
+    {
+      int gic_page_nr = (*s_ptr++ - '0');
+
+      if (*s_ptr >= '0' && *s_ptr <= '9')
+       gic_page_nr = 10 * gic_page_nr + (*s_ptr++ - '0');
+
+      if (gic_page_nr < 1 || gic_page_nr > MAX_CHANGE_PAGES)
+       return ANIM_EVENT_NONE;
+
+      // change page stored as 1 to 32 (0 means "all change pages")
+
+      result |= gic_page_nr << ANIM_EVENT_PAGE_BIT;
+    }
+    else
+    {
+      // invalid animation part number specified
+
+      return ANIM_EVENT_NONE;
+    }
+  }
+
   // discard result if next character is neither delimiter nor whitespace
   if (!(*s_ptr == ',' || *s_ptr == '\0' ||
        *s_ptr == ' ' || *s_ptr == '\t'))
@@ -11713,13 +11742,8 @@ static int get_anim_parameter_values(char *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, ',');
-  }
-
   while (s != NULL)
   {
     // add optional "click:anim_X" or "click:anim_X.part_X" parameter
@@ -11801,6 +11825,7 @@ int get_parameter_value(char *value_raw, char *suffix, int type)
              strEqual(value, "lower")  ? POS_LOWER :
              strEqual(value, "bottom") ? POS_BOTTOM :
              strEqual(value, "any")    ? POS_ANY :
+             strEqual(value, "ce")     ? POS_CE :
              strEqual(value, "last")   ? POS_LAST : POS_UNDEFINED);
   }
   else if (strEqual(suffix, ".align"))
@@ -11890,6 +11915,9 @@ int get_parameter_value(char *value_raw, char *suffix, int type)
 
     if (string_has_parameter(value, "multiple_actions"))
       result |= STYLE_MULTIPLE_ACTIONS;
+
+    if (string_has_parameter(value, "consume_ce_event"))
+      result |= STYLE_CONSUME_CE_EVENT;
   }
   else if (strEqual(suffix, ".fade_mode"))
   {