public ParticleType(ParticleType copyFrom)
        {
            Source             = copyFrom.Source;
            SourceChooser      = copyFrom.SourceChooser;
            Color              = copyFrom.Color;
            Color2             = copyFrom.Color2;
            ColorMode          = copyFrom.ColorMode;
            FadeMode           = copyFrom.FadeMode;
            SpeedMin           = copyFrom.SpeedMin;
            SpeedMax           = copyFrom.SpeedMax;
            SpeedMultiplier    = copyFrom.SpeedMultiplier;
            Acceleration       = copyFrom.Acceleration;
            Friction           = copyFrom.Friction;
            Direction          = copyFrom.Direction;
            DirectionRange     = copyFrom.DirectionRange;
            LifeMin            = copyFrom.LifeMin;
            LifeMax            = copyFrom.LifeMax;
            Size               = copyFrom.Size;
            SizeRange          = copyFrom.SizeRange;
            RotationMode       = copyFrom.RotationMode;
            SpinMin            = copyFrom.SpinMin;
            SpinMax            = copyFrom.SpinMax;
            SpinFlippedChance  = copyFrom.SpinFlippedChance;
            ScaleOut           = copyFrom.ScaleOut;
            UseActualDeltaTime = copyFrom.UseActualDeltaTime;

            AllTypes.Add(this);
        }
Exemple #2
0
        /// <summary>
        /// Parses a chooser from a string.
        /// </summary>
        /// <param name="data">Choices to parse. Format: "choice0:weight,choice1:weight,..."</param>
        /// <returns></returns>
        static public Chooser <TT> FromString <TT>(string data) where TT : IConvertible
        {
            var chooser = new Chooser <TT>();

            string[] choices = data.Split(',');

            //If it's just a single choice with no weight, add it and return
            if (choices.Length == 1 && choices[0].IndexOf(':') == -1)
            {
                chooser.Add((TT)Convert.ChangeType(choices[0], typeof(TT)), 1f);
                return(chooser);
            }

            //Parse the individual choices
            foreach (var choice in choices)
            {
                if (choice.IndexOf(':') == -1)
                {
                    //No weight, default to weight of 1
                    chooser.Add((TT)Convert.ChangeType(choice, typeof(TT)), 1f);
                }
                else
                {
                    //Has weight, handle that correctly
                    var parts  = choice.Split(':');
                    var key    = parts[0].Trim();
                    var weight = parts[1].Trim();

                    chooser.Add((TT)Convert.ChangeType(key, typeof(TT)), Convert.ToSingle(weight));
                }
            }

            return(chooser);
        }
Exemple #3
0
 public void Add(string id, string path, float delay, Chooser <string> into, params int[] frames)
 {
     animations[id] = new Animation()
     {
         Delay  = delay,
         Frames = GetFrames(path, frames),
         Goto   = into
     };
 }
Exemple #4
0
 public void Add(string id, string path, float delay, string into)
 {
     animations[id] = new Animation()
     {
         Delay  = delay,
         Frames = GetFrames(path),
         Goto   = Chooser <string> .FromString <string>(into)
     };
 }
Exemple #5
0
        public void Add(XmlElement xml, string overridePath = null)
        {
            var source = new SpriteDataSource();

            source.XML          = xml;
            source.Path         = source.XML.Attr("path");
            source.OverridePath = overridePath;

            //Error Checking
            {
                var prefix = "Sprite '" + source.XML.Name + "': ";

                //Path
                if (!source.XML.HasAttr("path") && string.IsNullOrEmpty(overridePath))
                {
                    throw new Exception(prefix + "'path' is missing!");
                }

                //Anims
                var ids = new HashSet <string>();
                foreach (XmlElement anim in source.XML.GetElementsByTagName("Anim"))
                {
                    CheckAnimXML(anim, prefix, ids);
                }
                foreach (XmlElement loop in source.XML.GetElementsByTagName("Loop"))
                {
                    CheckAnimXML(loop, prefix, ids);
                }

                //Start
                if (source.XML.HasAttr("start") && !ids.Contains(source.XML.Attr("start")))
                {
                    throw new Exception(prefix + "starting animation '" + source.XML.Attr("start") + "' is missing!");
                }

                //Origin
                if (source.XML.HasChild("Justify") && source.XML.HasChild("Origin"))
                {
                    throw new Exception(prefix + "has both Origin and Justify tags!");
                }
            }

            //Create the Sprite
            {
                var normalPath  = source.XML.Attr("path", "");
                var masterDelay = source.XML.AttrFloat("delay", 0);

                //Build Animations
                foreach (XmlElement anim in source.XML.GetElementsByTagName("Anim"))
                {
                    Chooser <string> into;
                    if (anim.HasAttr("goto"))
                    {
                        into = Chooser <string> .FromString <string>(anim.Attr("goto"));
                    }
                    else
                    {
                        into = null;
                    }

                    var id     = anim.Attr("id");
                    var path   = anim.Attr("path", "");
                    var frames = Calc.ReadCSVIntWithTricks(anim.Attr("frames", ""));

                    if (!string.IsNullOrEmpty(overridePath) && HasFrames(Atlas, overridePath + path, frames))
                    {
                        path = overridePath + path;
                    }
                    else
                    {
                        path = normalPath + path;
                    }

                    Sprite.Add(id, path, anim.AttrFloat("delay", masterDelay), into, frames);
                }

                //Build Loops
                foreach (XmlElement loop in source.XML.GetElementsByTagName("Loop"))
                {
                    var id     = loop.Attr("id");
                    var path   = loop.Attr("path", "");
                    var frames = Calc.ReadCSVIntWithTricks(loop.Attr("frames", ""));

                    if (!string.IsNullOrEmpty(overridePath) && HasFrames(Atlas, overridePath + path, frames))
                    {
                        path = overridePath + path;
                    }
                    else
                    {
                        path = normalPath + path;
                    }

                    Sprite.AddLoop(id, path, loop.AttrFloat("delay", masterDelay), frames);
                }

                //Origin
                if (source.XML.HasChild("Center"))
                {
                    Sprite.CenterOrigin();
                    Sprite.Justify = new Vector2(.5f, .5f);
                }
                else if (source.XML.HasChild("Justify"))
                {
                    Sprite.JustifyOrigin(source.XML.ChildPosition("Justify"));
                    Sprite.Justify = source.XML.ChildPosition("Justify");
                }
                else if (source.XML.HasChild("Origin"))
                {
                    Sprite.Origin = source.XML.ChildPosition("Origin");
                }

                //Position
                if (source.XML.HasChild("Position"))
                {
                    Sprite.Position = source.XML.ChildPosition("Position");
                }

                //Start Animation
                if (source.XML.HasAttr("start"))
                {
                    Sprite.Play(source.XML.Attr("start"));
                }
            }

            Sources.Add(source);
        }
Exemple #6
0
        private void ApplyToSprite(Sprite sprite, XmlElement xml)
        {
            float masterDelay = xml.AttrFloat("delay", 0);

            //Build Animations
            foreach (XmlElement anim in xml.GetElementsByTagName("Anim"))
            {
                Chooser <string> into;
                if (anim.HasAttr("goto"))
                {
                    into = Chooser <string> .FromString <string>(anim.Attr("goto"));
                }
                else
                {
                    into = null;
                }

                if (anim.HasAttr("frames"))
                {
                    sprite.Add(anim.Attr("id"), anim.Attr("path", ""), anim.AttrFloat("delay", masterDelay), into, Calc.ReadCSVIntWithTricks(anim.Attr("frames")));
                }
                else
                {
                    sprite.Add(anim.Attr("id"), anim.Attr("path", ""), anim.AttrFloat("delay", masterDelay), into);
                }
            }

            //Build Loops
            foreach (XmlElement loop in xml.GetElementsByTagName("Loop"))
            {
                if (loop.HasAttr("frames"))
                {
                    sprite.AddLoop(loop.Attr("id"), loop.Attr("path", ""), loop.AttrFloat("delay", masterDelay), Calc.ReadCSVIntWithTricks(loop.Attr("frames")));
                }
                else
                {
                    sprite.AddLoop(loop.Attr("id"), loop.Attr("path", ""), loop.AttrFloat("delay", masterDelay));
                }
            }

            //Origin
            if (xml.HasChild("Center"))
            {
                sprite.CenterOrigin();
                sprite.Justify = new Vector2(.5f, .5f);
            }
            else if (xml.HasChild("Justify"))
            {
                sprite.JustifyOrigin(xml.ChildPosition("Justify"));
                sprite.Justify = xml.ChildPosition("Justify");
            }
            else if (xml.HasChild("Origin"))
            {
                sprite.Origin = xml.ChildPosition("Origin");
            }

            //Position
            if (xml.HasChild("Position"))
            {
                sprite.Position = xml.ChildPosition("Position");
            }

            //Start Animation
            if (xml.HasAttr("start"))
            {
                sprite.Play(xml.Attr("start"));
            }
        }