Beispiel #1
0
        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);
        }
Beispiel #2
0
        /// <summary>
        /// Parses a chooser from a string.
        /// </summary>
        /// <param name="data">Choices to parse. Format: "choice0:weight,choice1:weight,..."</param>
        /// <returns></returns>
        public static 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);
        }
Beispiel #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
     };
 }
Beispiel #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)
     };
 }
Beispiel #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);
        }