Esempio n. 1
0
        public static void Combind(AnimationHolder inherited, ref AnimationHolder @override)
        {
            var temp = new Dictionary <string, Animation>();

            foreach (string key in inherited._animations.Keys)
            {
                temp.Add(key, (Animation)inherited._animations[key].Clone());
            }

            foreach (string key in @override._animations.Keys)
            {
                if (temp.ContainsKey(key))
                {
                    Animation inherited_animation = temp[key];
                    Animation override_animation  = @override._animations[key];

                    Animation.Combind(inherited_animation, ref override_animation);

                    temp.Remove(key);
                    temp.Add(key, override_animation);
                }
                else
                {
                    temp.Add(key, @override._animations[key]);
                }
            }

            @override._animations = temp;
        }
Esempio n. 2
0
        private List <AnimationModule> SetupChildren(AnimationHolder animations)
        {
            var temp = new List <AnimationModule>();

            foreach (string key in animations.Animations.Keys) //To follow this, let's assume this is the "walking left" animation
            {
                Animation ani = animations.Animations[key];

                temp.AddRange(Setup(ref ani));
            }

            return(temp); //Return the new sprites created
        }
Esempio n. 3
0
        private List <AnimationModule> Setup(ref Animation ani, List <Animation> inheritStack = null)
        {
            var temp = new List <AnimationModule>();

            if (ani.setup_ran)
            {
                return(temp);
            }

            if (inheritStack == null)
            {
                inheritStack = new List <Animation>();
            }

            Assembly assembly = Assembly.GetEntryAssembly();

            ani.ModuleOwner = this;

            if (ani.Animations == null)
            {
                return(temp);
            }

            if (ani.InheritedAnimations != null)
            {
                if (inheritStack.Count > 0 && inheritStack.Contains(ani.InheritedAnimationOwner))
                {
                    throw new InvalidOperationException("Loop inheritance detected!");
                }
                if (!ani.InheritedAnimationOwner.setup_ran) //If the inherited animation hasn't been setup yet
                {
                    Animation inheritOwner = ani.InheritedAnimationOwner;
                    inheritStack.Add(ani);                 //Add ourself to the stack
                    Setup(ref inheritOwner, inheritStack); //Setup the inherited animation
                    inheritStack.Remove(ani);              //Remove ourself from the stack
                }
                AnimationHolder t = ani.Animations;
                AnimationHolder.Combind(ani.InheritedAnimations, ref t);
            }

            foreach (string ckey in ani.Animations.Animations.Keys) //To follow this, let's assume this is the "hat" animation for "walking left" animation
            {
                //ckey = "hat"
                Animation child_animation = ani.Animations[ckey]; //Same as ani.Animations.Animations[ckey];
                //Get the animation object for "hat"

                child_animation.ParentAnimation = ani;                  //Set the parent of this child animation to this

                if (ani.InheritedAnimations == null)                    //Only inherit values if this animation didn't inherit animations from another animation
                {
                    Animation.Combind(ani, ref child_animation, false); //Inherit values from parent animation to this animation (exclude animations)
                }

                if (!child_animation.IsEmpty)
                {
                    ModuleSprite    sprite;
                    AnimationModule spriteModule;
                    Type            st = assembly.GetType(child_animation.SpriteFullName); //Get the type for the FullSpriteName
                    if (st == null)
                    {
                        //Assume it's a file path if no type was found
                        try
                        {
                            sprite       = new BasicAnimatedSprite(child_animation.SpriteFullName);
                            spriteModule = new AnimationModule("basic_sprite");
                            sprite.AttachModule(spriteModule);
                        }
                        catch
                        {
                            //If there was an error making this sprite
                            //Just ignore it..
                            ani.setup_ran = true;

                            return(temp);
                        }
                    }
                    else
                    {
                        sprite = (ModuleSprite)Activator.CreateInstance(st); //Create a new instance of the child sprite

                        if (sprite.ModuleExists <AnimationModule>())
                        {
                            spriteModule = sprite.GetModules <AnimationModule>()[0]; //There can only ever bee one animation module
                        }
                        else
                        {
                            spriteModule = new AnimationModule(sprite.ToString());
                            sprite.AttachModule(spriteModule);
                        }
                    }

                    child_animation.ModuleOwner = spriteModule;               //Set the owner of the "hat" animation to the newly created sprite
                    spriteModule.Animations     = child_animation.Animations; //Set the animations for the hat sprite to the children animations of the "hat" animation.
                    Owner.Attach(sprite);
                    sprite.IsVisible = false;                                 //Make sure this sprite isn't visible by default
                    temp.Add(spriteModule);                                   //Add the "hat" sprite as a children of this sprite

                    spriteModule.SetupChildren(spriteModule.Animations);      //Setup the children of "hat" animation, and put all of it's children in a list

                    //Nevermind, don't do that
                    //temp.AddRange(temp2); //Add all of children of the "hat" sprite as our children as well.
                }
                else
                {
                    temp.Add(Empty); //This is an empty animation, fill it with a unused module
                }
            }

            ani.setup_ran = true;

            return(temp);
        }