Exemple #1
0
 /// <summary>Read Effect from string array, as in ini files, 
 /// optionally starting from specified index
 /// <remarks>Does not check if correct format</remarks></summary>
 /// <param name="str">Array of strings, one for each line</param>
 /// <param name="i">Optional, Array index to start reading from
 /// by default is zero</param>
 public int ReadFromArray(String[] str, int i = 0)
 {
     // Check here if there are comments
     PARSE_COMMENTS_STATE commentsState = PARSE_COMMENTS_STATE.NotCommentLine;
     while (i < str.Length
         && (commentsState = IniCommon.ParseLineComments(str[i], commentsState)) >= 0)
     {
         // Store comments
         if (!String.IsNullOrEmpty(Comments))
             Comments += "\r\n" + str[i];
         else
             Comments = str[i];
         i++;
     }
     // Read AniTitle and Amount
     AniTitle = str[i].Substring(1, str[0].Length - 2);
     i++;
     Amount = UInt16.Parse(str[i].Split('=')[1]);
     i++;
     if (Amount > 0x0FFF)
         throw new ArgumentOutOfRangeException("Amount", "cannot fit in a signed short, while should be 16 or lower");
     // Check if remaining lines are enough for the amount of parts
     if (str.Length - i < Amount * 4 + 7)
         throw new ArgumentOutOfRangeException("str", "there are too few lines to read Effect, expected at least " + (4 * Amount + 7).ToString() + ", while remaining " + (str.Length - i).ToString());
     Part = new List<EffectPart>(Amount);
     // Read every Part
     for (int j = 0; j < Amount; j++)
     {
         EffectPart ep = new EffectPart();
         i += ep.ReadFromArray(str, i);
         Part.Add(ep);
     }
     // Read the rest of data
     Delay = UInt32.Parse(str[i].Substring(1, str[0].Length - 2));
     i++;
     LoopTime = UInt32.Parse(str[i].Substring(1, str[0].Length - 2));
     i++;
     FrameInterval = UInt32.Parse(str[i].Substring(1, str[0].Length - 2));
     i++;
     LoopInterval = UInt32.Parse(str[i].Substring(1, str[0].Length - 2));
     i++;
     OffsetX = float.Parse(str[i].Substring(1, str[0].Length - 2));
     i++;
     OffsetY = float.Parse(str[i].Substring(1, str[0].Length - 2));
     i++;
     OffsetZ = float.Parse(str[i].Substring(1, str[0].Length - 2));
     i++;
     if (i < str.Length && str[i].StartsWith("Billboard"))
     {
         Billboard = (Byte.Parse(str[i].Split('=')[1]) != 0);
         i++;
     }
     if (i < str.Length && str[i].StartsWith("ColorEnable"))
     {
         ColorEnable = (COLOR_ENABLE)Byte.Parse(str[i].Split('=')[1]);
         i++;
     }
     if (i < str.Length && str[i].StartsWith("Lev"))
     {
         Level = Byte.Parse(str[i].Split('=')[1]);
         i++;
     }
     if (i < str.Length
         && !String.IsNullOrWhiteSpace(str[i])
         && str[i].Contains("="))
     {
         Unknown = Byte.Parse(str[i].Split('=')[1]);
         i++;
     }
     return i;
 }