Ejemplo n.º 1
0
        /// <summary>
        /// Load the animations (read them from XML file)
        /// </summary>
        /// <param name="animations">Animation class where the animations should be saved</param>
        public void loadAnimations(Animations animations)
        {
            // for each animation
            foreach (AnimationNode node in AnimationXML.Animations.Animation)
            {
                TAnimation ani = animations.AddAnimation(node.Id, node.Id.ToString());
                ani.Border  = node.Border != null;
                ani.Gravity = node.Gravity != null;

                ani.Name = node.Name;
                switch (ani.Name)
                {
                case "fall": animations.AnimationFall = node.Id; break;

                case "drag": animations.AnimationDrag = node.Id; break;

                case "kill": animations.AnimationKill = node.Id; break;

                case "sync": animations.AnimationSync = node.Id; break;
                }

                ani.Start.X        = getXMLCompute(node.Start.X);
                ani.Start.Y        = getXMLCompute(node.Start.Y);
                ani.Start.Interval = getXMLCompute(node.Start.Interval);
                ani.Start.OffsetY  = node.Start.OffsetY;
                ani.Start.Opacity  = node.Start.Opacity;

                ani.End.X        = getXMLCompute(node.End.X);
                ani.End.Y        = getXMLCompute(node.End.Y);
                ani.End.Interval = getXMLCompute(node.End.Interval);
                ani.End.OffsetY  = node.End.OffsetY;
                ani.End.Opacity  = node.End.Opacity;

                ani.Sequence.RepeatFrom = node.Sequence.RepeatFromFrame;
                ani.Sequence.Action     = node.Sequence.Action;
                ani.Sequence.Repeat     = getXMLCompute(node.Sequence.RepeatCount);
                foreach (int frameid in node.Sequence.Frame)
                {
                    ani.Sequence.Frames.Add(frameid);
                }
                if (ani.Sequence.RepeatFrom > 0)
                {
                    ani.Sequence.TotalSteps = ani.Sequence.Frames.Count + (ani.Sequence.Frames.Count - ani.Sequence.RepeatFrom - 1) * ani.Sequence.Repeat.Value;
                }
                else
                {
                    ani.Sequence.TotalSteps = ani.Sequence.Frames.Count + ani.Sequence.Frames.Count * ani.Sequence.Repeat.Value;
                }
                if (node.Sequence.Next != null)
                {
                    foreach (NextNode nextNode in node.Sequence.Next)
                    {
                        TNextAnimation.TOnly where;
                        switch (nextNode.OnlyFlag)
                        {
                        case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break;

                        case "window": where = TNextAnimation.TOnly.WINDOW; break;

                        case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break;

                        case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break;

                        case "vertical": where = TNextAnimation.TOnly.VERTICAL; break;

                        default: where = TNextAnimation.TOnly.NONE; break;
                        }

                        ani.EndAnimation.Add(
                            new TNextAnimation(
                                nextNode.Value,
                                nextNode.Probability,
                                where
                                )
                            );
                    }
                }

                if (ani.Border)
                {
                    foreach (NextNode nextNode in node.Border.Next)
                    {
                        TNextAnimation.TOnly where;
                        switch (nextNode.OnlyFlag)
                        {
                        case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break;

                        case "window": where = TNextAnimation.TOnly.WINDOW; break;

                        case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break;

                        case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break;

                        case "vertical": where = TNextAnimation.TOnly.VERTICAL; break;

                        default: where = TNextAnimation.TOnly.NONE; break;
                        }
                        ani.Border = true;
                        ani.EndBorder.Add(
                            new TNextAnimation(
                                nextNode.Value,
                                nextNode.Probability,
                                where
                                )
                            );
                    }
                }

                if (ani.Gravity)
                {
                    foreach (NextNode nextNode in node.Gravity.Next)
                    {
                        TNextAnimation.TOnly where;
                        switch (nextNode.OnlyFlag)
                        {
                        case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break;

                        case "window": where = TNextAnimation.TOnly.WINDOW; break;

                        case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break;

                        case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break;

                        case "vertical": where = TNextAnimation.TOnly.VERTICAL; break;

                        default: where = TNextAnimation.TOnly.NONE; break;
                        }
                        ani.Gravity = true;
                        ani.EndGravity.Add(
                            new TNextAnimation(
                                nextNode.Value,
                                nextNode.Probability,
                                where
                                )
                            );
                    }
                }

                /* OLD XML parsing:
                 *
                 *  foreach (XmlNode node3 in node2.SelectNodes(".//pet:next", xmlNS))
                 *  {
                 *      TNextAnimation.TOnly where = TNextAnimation.TOnly.NONE;
                 *      if (node3.Attributes["only"] != null)
                 *      {
                 *          switch (node3.Attributes["only"].InnerText)
                 *          {
                 *              case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break;
                 *              case "window": where = TNextAnimation.TOnly.WINDOW; break;
                 *              case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break;
                 *              case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break;
                 *              case "vertical": where = TNextAnimation.TOnly.VERTICAL; break;
                 *          }
                 *      }
                 *      ani.Gravity = true;
                 *      ani.EndGravity.Add(
                 *          new TNextAnimation(
                 *              int.Parse(node3.InnerText, CultureInfo.InvariantCulture),
                 *              int.Parse(node3.Attributes["probability"].InnerText, CultureInfo.InvariantCulture),
                 *              where
                 *          )
                 *      );
                 *  }
                 *  break;
                 */
                animations.SaveAnimation(ani, node.Id);
            }

            // for each spawn
            if (AnimationXML.Spawns.Spawn != null)
            {
                foreach (SpawnNode node in AnimationXML.Spawns.Spawn)
                {
                    TSpawn ani = animations.AddSpawn(
                        node.Id,
                        node.Probability);

                    ani.Start.X = getXMLCompute(node.X);
                    ani.Start.Y = getXMLCompute(node.Y);
                    ani.Next    = node.Next.Value;

                    animations.SaveSpawn(ani, node.Id);
                }
            }

            // for each child
            if (AnimationXML.Childs.Child != null)
            {
                foreach (ChildNode node in AnimationXML.Childs.Child)
                {
                    TChild aniChild = animations.AddChild(node.Id);
                    aniChild.AnimationID = node.Id;

                    aniChild.Position.X = getXMLCompute(node.X);
                    aniChild.Position.Y = getXMLCompute(node.Y);
                    aniChild.Next       = node.Next;

                    animations.SaveChild(aniChild, node.Id);
                }
            }
        }