コード例 #1
0
ファイル: ParticleLoader.cs プロジェクト: vb0067/LGame
        private static void parseValueElement(XMLElement element,
                                              Value value)
        {
            if (element == null)
            {
                return;
            }

            string type = element.GetAttribute("type", "");
            string v    = element.GetAttribute("value", "");

            if (type == null || type.Length == 0)
            {
                if (value is SimpleValue)
                {
                    ((SimpleValue)value).SetValue(Convert.ToSingle(v));
                }
                else if (value is RandomValue)
                {
                    ((RandomValue)value).SetValue(Convert.ToSingle(v));
                }
                else
                {
                    Log.DebugWrite("problems reading element, skipping: "
                                   + element);
                }
            }
            else
            {
                if (type.Equals("simple"))
                {
                    ((SimpleValue)value).SetValue(Convert.ToSingle(v));
                }
                else if (type.Equals("random"))
                {
                    ((RandomValue)value).SetValue(Convert.ToSingle(v));
                }
                else if (type.Equals("linear"))
                {
                    int min = element.GetIntAttribute("min", 0);
                    int max = element.GetIntAttribute("max", 0);

                    bool active = element.GetBoolAttribute("active", false);

                    List <XMLElement> points = element.List("point");

                    List <Vector2f> curve = new List <Vector2f>();
                    for (int i = 0; i < points.Count; i++)
                    {
                        XMLElement point = (XMLElement)points[i];

                        float x = point.GetFloatAttribute("x", 0);
                        float y = point.GetFloatAttribute("y", 0);

                        curve.Add(new Vector2f(x, y));
                    }

                    ((LinearInterpolator)value).SetCurve(curve);
                    ((LinearInterpolator)value).SetMin(min);
                    ((LinearInterpolator)value).SetMax(max);
                    ((LinearInterpolator)value).SetActive(active);
                }
                else
                {
                    Log.DebugWrite("unkown type detected: " + type);
                }
            }
        }