rnd-20070324-1-src
[rocksndiamonds.git] / src / libgame / misc.c
index eb3e7a0f6ba58faa9b0b105fe46edcf9d3edcf1f..c06eac4f097f9e32f7031323b4613ba78aad1bf9 100644 (file)
@@ -156,6 +156,11 @@ int log_2(unsigned int x)
   return e;
 }
 
+boolean getTokenValueFromString(char *string, char **token, char **value)
+{
+  return getTokenValueFromSetupLine(string, token, value);
+}
+
 
 /* ------------------------------------------------------------------------- */
 /* counter functions                                                         */
@@ -579,6 +584,14 @@ boolean strEqual(char *s1, char *s2)
          strcmp(s1, s2) == 0);
 }
 
+boolean strEqualN(char *s1, char *s2, int n)
+{
+  return (s1 == NULL && s2 == NULL ? TRUE  :
+         s1 == NULL && s2 != NULL ? FALSE :
+         s1 != NULL && s2 == NULL ? FALSE :
+         strncmp(s1, s2, n) == 0);
+}
+
 
 /* ------------------------------------------------------------------------- */
 /* command line option handling functions                                    */
@@ -1782,7 +1795,15 @@ int get_parameter_value(char *value_raw, char *suffix, int type)
   {
     result = (strEqual(value, "left")   ? ALIGN_LEFT :
              strEqual(value, "right")  ? ALIGN_RIGHT :
-             strEqual(value, "center") ? ALIGN_CENTER : ALIGN_DEFAULT);
+             strEqual(value, "center") ? ALIGN_CENTER :
+             strEqual(value, "middle") ? ALIGN_CENTER : ALIGN_DEFAULT);
+  }
+  else if (strEqual(suffix, ".valign"))
+  {
+    result = (strEqual(value, "top")    ? VALIGN_TOP :
+             strEqual(value, "bottom") ? VALIGN_BOTTOM :
+             strEqual(value, "middle") ? VALIGN_MIDDLE :
+             strEqual(value, "center") ? VALIGN_MIDDLE : VALIGN_DEFAULT);
   }
   else if (strEqual(suffix, ".anim_mode"))
   {
@@ -1798,8 +1819,6 @@ int get_parameter_value(char *value_raw, char *suffix, int type)
              string_has_parameter(value, "horizontal") ? ANIM_HORIZONTAL :
              string_has_parameter(value, "vertical")   ? ANIM_VERTICAL :
              string_has_parameter(value, "centered")   ? ANIM_CENTERED :
-             string_has_parameter(value, "fade")       ? ANIM_FADE :
-             string_has_parameter(value, "crossfade")  ? ANIM_CROSSFADE :
              ANIM_DEFAULT);
 
     if (string_has_parameter(value, "reverse"))
@@ -1811,6 +1830,18 @@ int get_parameter_value(char *value_raw, char *suffix, int type)
     if (string_has_parameter(value, "static_panel"))
       result |= ANIM_STATIC_PANEL;
   }
+  else if (strEqual(suffix, ".fade_mode"))
+  {
+    result = (string_has_parameter(value, "none")      ? FADE_MODE_NONE :
+             string_has_parameter(value, "fade")       ? FADE_MODE_FADE :
+             string_has_parameter(value, "crossfade")  ? FADE_MODE_CROSSFADE :
+             string_has_parameter(value, "melt")       ? FADE_MODE_MELT :
+             FADE_MODE_DEFAULT);
+  }
+  else if (strEqualN(suffix, ".font", 5))      /* (may also be ".font_xyz") */
+  {
+    result = gfx.get_font_from_token_function(value);
+  }
   else         /* generic parameter of type integer or boolean */
   {
     result = (strEqual(value, ARG_UNDEFINED) ? ARG_UNDEFINED_VALUE :
@@ -1824,7 +1855,7 @@ int get_parameter_value(char *value_raw, char *suffix, int type)
   return result;
 }
 
-int get_auto_parameter_value(char *token, char *value_raw)
+int get_token_parameter_value(char *token, char *value_raw)
 {
   char *suffix;
 
@@ -1835,6 +1866,21 @@ int get_auto_parameter_value(char *token, char *value_raw)
   if (suffix == NULL)
     suffix = token;
 
+#if 0
+  if (strncmp(suffix, ".font", 5) == 0)
+  {
+    int i;
+
+    /* !!! OPTIMIZE THIS BY USING HASH !!! */
+    for (i = 0; i < NUM_FONTS; i++)
+      if (strEqual(value_raw, font_info[i].token_name))
+       return i;
+
+    /* if font not found, use reliable default value */
+    return FONT_INITIAL_1;
+  }
+#endif
+
   return get_parameter_value(value_raw, suffix, TYPE_INTEGER);
 }
 
@@ -2683,7 +2729,7 @@ static void LoadCustomArtwork(struct ArtworkListInfo *artwork_info,
                              struct FileInfo *file_list_entry)
 {
 #if 0
-  printf("GOT CUSTOM ARTWORK FILE '%s'\n", filename);
+  printf("GOT CUSTOM ARTWORK FILE '%s'\n", file_list_entry->filename);
 #endif
 
   if (strEqual(file_list_entry->filename, UNDEFINED_FILENAME))